Skip to content

Commit c70358f

Browse files
committed
Auto merge of #143643 - matthiaskrgr:rollup-a9j7h8q, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #143402 (Port several linking (linkage?) related attributes the new attribute system ) - #143555 (Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.) - #143593 (Port #[rustc_dummy]) - #143600 (Update intro blurb in `wasm32-wasip1` docs) - #143603 (Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrder::KeepLast`) - #143606 (configure.py: Write last key in each section) - #143620 (fix: Remove newline from multiple crate versions note) - #143622 (Add target maintainer information for mips64-unknown-linux-muslabi64) Failed merges: - #143403 (Port several trait/coherence-related attributes the new attribute system) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f838cbc + cd41710 commit c70358f

File tree

19 files changed

+286
-78
lines changed

19 files changed

+286
-78
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ pub enum AttributeKind {
240240
/// Represents [`#[doc]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
241241
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
242242

243+
/// Represents `#[rustc_dummy]`.
244+
Dummy,
245+
243246
/// Represents [`#[export_name]`](https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute).
244247
ExportName {
245248
/// The name to export this item with.
@@ -248,6 +251,15 @@ pub enum AttributeKind {
248251
span: Span,
249252
},
250253

254+
/// Represents `#[export_stable]`.
255+
ExportStable,
256+
257+
/// Represents `#[ffi_const]`.
258+
FfiConst(Span),
259+
260+
/// Represents `#[ffi_pure]`.
261+
FfiPure(Span),
262+
251263
/// Represents `#[ignore]`
252264
Ignore {
253265
span: Span,
@@ -326,6 +338,9 @@ pub enum AttributeKind {
326338
span: Span,
327339
},
328340

341+
/// Represents `#[rustc_std_internal_symbol]`.
342+
StdInternalSymbol(Span),
343+
329344
/// Represents `#[target_feature(enable = "...")]`
330345
TargetFeature(ThinVec<(Symbol, Span)>, Span),
331346

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ impl AttributeKind {
2525
ConstStabilityIndirect => No,
2626
Deprecation { .. } => Yes,
2727
DocComment { .. } => Yes,
28+
Dummy => No,
2829
ExportName { .. } => Yes,
30+
ExportStable => No,
31+
FfiConst(..) => No,
32+
FfiPure(..) => No,
2933
Ignore { .. } => No,
3034
Inline(..) => No,
3135
LinkName { .. } => Yes,
@@ -48,6 +52,7 @@ impl AttributeKind {
4852
RustcObjectLifetimeDefault => No,
4953
SkipDuringMethodDispatch { .. } => No,
5054
Stability { .. } => Yes,
55+
StdInternalSymbol(..) => No,
5156
TargetFeature(..) => No,
5257
TrackCaller(..) => Yes,
5358
Used { .. } => No,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_feature::{AttributeTemplate, template};
3+
use rustc_span::{Symbol, sym};
4+
5+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
6+
use crate::context::{AcceptContext, Stage};
7+
use crate::parser::ArgParser;
8+
9+
pub(crate) struct DummyParser;
10+
impl<S: Stage> SingleAttributeParser<S> for DummyParser {
11+
const PATH: &[Symbol] = &[sym::rustc_dummy];
12+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
13+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
14+
const TEMPLATE: AttributeTemplate = template!(Word); // Anything, really
15+
16+
fn convert(_: &mut AcceptContext<'_, '_, S>, _: &ArgParser<'_>) -> Option<AttributeKind> {
17+
Some(AttributeKind::Dummy)
18+
}
19+
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use rustc_attr_data_structures::AttributeKind;
22
use rustc_attr_data_structures::AttributeKind::{LinkName, LinkSection};
33
use rustc_feature::{AttributeTemplate, template};
4-
use rustc_span::{Symbol, sym};
4+
use rustc_span::{Span, Symbol, sym};
55

6-
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
6+
use crate::attributes::{
7+
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
8+
};
79
use crate::context::{AcceptContext, Stage};
810
use crate::parser::ArgParser;
911
use crate::session_diagnostics::NullOnLinkSection;
@@ -57,3 +59,31 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
5759
Some(LinkSection { name, span: cx.attr_span })
5860
}
5961
}
62+
63+
pub(crate) struct ExportStableParser;
64+
impl<S: Stage> NoArgsAttributeParser<S> for ExportStableParser {
65+
const PATH: &[Symbol] = &[sym::export_stable];
66+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
67+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ExportStable;
68+
}
69+
70+
pub(crate) struct FfiConstParser;
71+
impl<S: Stage> NoArgsAttributeParser<S> for FfiConstParser {
72+
const PATH: &[Symbol] = &[sym::ffi_const];
73+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
74+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiConst;
75+
}
76+
77+
pub(crate) struct FfiPureParser;
78+
impl<S: Stage> NoArgsAttributeParser<S> for FfiPureParser {
79+
const PATH: &[Symbol] = &[sym::ffi_pure];
80+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
81+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiPure;
82+
}
83+
84+
pub(crate) struct StdInternalSymbolParser;
85+
impl<S: Stage> NoArgsAttributeParser<S> for StdInternalSymbolParser {
86+
const PATH: &[Symbol] = &[sym::rustc_std_internal_symbol];
87+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
88+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::StdInternalSymbol;
89+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) mod cfg;
3030
pub(crate) mod codegen_attrs;
3131
pub(crate) mod confusables;
3232
pub(crate) mod deprecation;
33+
pub(crate) mod dummy;
3334
pub(crate) mod inline;
3435
pub(crate) mod link_attrs;
3536
pub(crate) mod lint_helpers;
@@ -217,7 +218,14 @@ impl<S: Stage> OnDuplicate<S> {
217218
// them will be merged in another PR
218219
#[allow(unused)]
219220
pub(crate) enum AttributeOrder {
220-
/// Duplicates after the first attribute will be an error.
221+
/// Duplicates after the first attribute will be an error. I.e. only keep the lowest attribute.
222+
///
223+
/// Attributes are processed from bottom to top, so this raises an error on all the attributes
224+
/// further above the lowest one:
225+
/// ```
226+
/// #[stable(since="1.0")] //~ WARNING duplicated attribute
227+
/// #[stable(since="2.0")]
228+
/// ```
221229
///
222230
/// This should be used where duplicates would be ignored, but carry extra
223231
/// meaning that could cause confusion. For example, `#[stable(since="1.0")]
@@ -227,6 +235,13 @@ pub(crate) enum AttributeOrder {
227235
/// Duplicates preceding the last instance of the attribute will be a
228236
/// warning, with a note that this will be an error in the future.
229237
///
238+
/// Attributes are processed from bottom to top, so this raises a warning on all the attributes
239+
/// below the higher one:
240+
/// ```
241+
/// #[path="foo.rs"]
242+
/// #[path="bar.rs"] //~ WARNING duplicated attribute
243+
/// ```
244+
///
230245
/// This is the same as `FutureWarnFollowing`, except the last attribute is
231246
/// the one that is "used". Ideally these can eventually migrate to
232247
/// `ErrorPreceding`.

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ use crate::attributes::codegen_attrs::{
2121
};
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
24+
use crate::attributes::dummy::DummyParser;
2425
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
25-
use crate::attributes::link_attrs::{LinkNameParser, LinkSectionParser};
26+
use crate::attributes::link_attrs::{
27+
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkSectionParser,
28+
StdInternalSymbolParser,
29+
};
2630
use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTransparentParser};
2731
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2832
use crate::attributes::must_use::MustUseParser;
@@ -127,6 +131,7 @@ attribute_parsers!(
127131

128132
// tidy-alphabetical-start
129133
Single<DeprecationParser>,
134+
Single<DummyParser>,
130135
Single<ExportNameParser>,
131136
Single<IgnoreParser>,
132137
Single<InlineParser>,
@@ -145,13 +150,17 @@ attribute_parsers!(
145150
Single<WithoutArgs<ColdParser>>,
146151
Single<WithoutArgs<ConstContinueParser>>,
147152
Single<WithoutArgs<ConstStabilityIndirectParser>>,
153+
Single<WithoutArgs<ExportStableParser>>,
154+
Single<WithoutArgs<FfiConstParser>>,
155+
Single<WithoutArgs<FfiPureParser>>,
148156
Single<WithoutArgs<LoopMatchParser>>,
149157
Single<WithoutArgs<MayDangleParser>>,
150158
Single<WithoutArgs<NoImplicitPreludeParser>>,
151159
Single<WithoutArgs<NoMangleParser>>,
152160
Single<WithoutArgs<NonExhaustiveParser>>,
153161
Single<WithoutArgs<PassByValueParser>>,
154162
Single<WithoutArgs<PubTransparentParser>>,
163+
Single<WithoutArgs<StdInternalSymbolParser>>,
155164
Single<WithoutArgs<TrackCallerParser>>,
156165
// tidy-alphabetical-end
157166
];

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
203203
UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER,
204204
UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER,
205205
},
206+
AttributeKind::FfiConst(_) => {
207+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
208+
}
209+
AttributeKind::FfiPure(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
210+
AttributeKind::StdInternalSymbol(_) => {
211+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
212+
}
206213
_ => {}
207214
}
208215
}
@@ -213,17 +220,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
213220

214221
match name {
215222
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
216-
sym::ffi_pure => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
217-
sym::ffi_const => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST,
218223
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
219224
sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
220225
sym::rustc_deallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR,
221226
sym::rustc_allocator_zeroed => {
222227
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
223228
}
224-
sym::rustc_std_internal_symbol => {
225-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
226-
}
227229
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
228230
sym::linkage => {
229231
if let Some(val) = attr.value_str() {

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ pub fn check_builtin_meta_item(
271271
if matches!(
272272
name,
273273
sym::inline
274+
| sym::export_stable
275+
| sym::ffi_const
276+
| sym::ffi_pure
277+
| sym::rustc_std_internal_symbol
274278
| sym::may_dangle
275279
| sym::rustc_as_ptr
276280
| sym::rustc_pub_transparent

compiler/rustc_passes/src/check_attr.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,20 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
204204
AttributeKind::RustcLayoutScalarValidRangeStart(_num, attr_span)
205205
| AttributeKind::RustcLayoutScalarValidRangeEnd(_num, attr_span),
206206
) => self.check_rustc_layout_scalar_valid_range(*attr_span, span, target),
207+
Attribute::Parsed(AttributeKind::ExportStable) => {
208+
// handled in `check_export`
209+
}
210+
&Attribute::Parsed(AttributeKind::FfiConst(attr_span)) => {
211+
self.check_ffi_const(attr_span, target)
212+
}
213+
&Attribute::Parsed(AttributeKind::FfiPure(attr_span)) => {
214+
self.check_ffi_pure(attr_span, attrs, target)
215+
}
207216
Attribute::Parsed(
208217
AttributeKind::BodyStability { .. }
209218
| AttributeKind::ConstStabilityIndirect
210-
| AttributeKind::MacroTransparency(_),
219+
| AttributeKind::MacroTransparency(_)
220+
| AttributeKind::Dummy,
211221
) => { /* do nothing */ }
212222
Attribute::Parsed(AttributeKind::AsPtr(attr_span)) => {
213223
self.check_applied_to_fn_or_method(hir_id, *attr_span, span, target)
@@ -233,6 +243,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
233243
&Attribute::Parsed(AttributeKind::PassByValue(attr_span)) => {
234244
self.check_pass_by_value(attr_span, span, target)
235245
}
246+
&Attribute::Parsed(AttributeKind::StdInternalSymbol(attr_span)) => {
247+
self.check_rustc_std_internal_symbol(attr_span, span, target)
248+
}
236249
Attribute::Unparsed(attr_item) => {
237250
style = Some(attr_item.style);
238251
match attr.path().as_slice() {
@@ -258,9 +271,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
258271
),
259272
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
260273
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
261-
[sym::rustc_std_internal_symbol, ..] => {
262-
self.check_rustc_std_internal_symbol(attr, span, target)
263-
}
264274
[sym::rustc_no_implicit_autorefs, ..] => {
265275
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
266276
}
@@ -300,8 +310,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
300310
[sym::rustc_has_incoherent_inherent_impls, ..] => {
301311
self.check_has_incoherent_inherent_impls(attr, span, target)
302312
}
303-
[sym::ffi_pure, ..] => self.check_ffi_pure(attr.span(), attrs, target),
304-
[sym::ffi_const, ..] => self.check_ffi_const(attr.span(), target),
305313
[sym::link_ordinal, ..] => self.check_link_ordinal(attr, span, target),
306314
[sym::link, ..] => self.check_link(hir_id, attr, span, target),
307315
[sym::macro_use, ..] | [sym::macro_escape, ..] => {
@@ -346,7 +354,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
346354
| sym::cfg_attr
347355
| sym::cfg_trace
348356
| sym::cfg_attr_trace
349-
| sym::export_stable // handled in `check_export`
350357
// need to be fixed
351358
| sym::cfi_encoding // FIXME(cfi_encoding)
352359
| sym::pointee // FIXME(derive_coerce_pointee)
@@ -1507,7 +1514,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15071514
self.dcx().emit_err(errors::FfiPureInvalidTarget { attr_span });
15081515
return;
15091516
}
1510-
if attrs.iter().any(|a| a.has_name(sym::ffi_const)) {
1517+
if find_attr!(attrs, AttributeKind::FfiConst(_)) {
15111518
// `#[ffi_const]` functions cannot be `#[ffi_pure]`
15121519
self.dcx().emit_err(errors::BothFfiConstAndPure { attr_span });
15131520
}
@@ -2214,13 +2221,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22142221
}
22152222
}
22162223

2217-
fn check_rustc_std_internal_symbol(&self, attr: &Attribute, span: Span, target: Target) {
2224+
fn check_rustc_std_internal_symbol(&self, attr_span: Span, span: Span, target: Target) {
22182225
match target {
22192226
Target::Fn | Target::Static | Target::ForeignFn | Target::ForeignStatic => {}
22202227
_ => {
2221-
self.tcx
2222-
.dcx()
2223-
.emit_err(errors::RustcStdInternalSymbol { attr_span: attr.span(), span });
2228+
self.tcx.dcx().emit_err(errors::RustcStdInternalSymbol { attr_span, span });
22242229
}
22252230
}
22262231
}

compiler/rustc_passes/src/check_export.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::iter;
22
use std::ops::ControlFlow;
33

44
use rustc_abi::ExternAbi;
5+
use rustc_attr_data_structures::{AttributeKind, find_attr};
56
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
67
use rustc_hir as hir;
78
use rustc_hir::def::DefKind;
@@ -14,7 +15,7 @@ use rustc_middle::ty::{
1415
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Visibility,
1516
};
1617
use rustc_session::config::CrateType;
17-
use rustc_span::{Span, sym};
18+
use rustc_span::Span;
1819

1920
use crate::errors::UnexportableItem;
2021

@@ -44,7 +45,7 @@ impl<'tcx> ExportableItemCollector<'tcx> {
4445
}
4546

4647
fn item_is_exportable(&self, def_id: LocalDefId) -> bool {
47-
let has_attr = self.tcx.has_attr(def_id, sym::export_stable);
48+
let has_attr = find_attr!(self.tcx.get_all_attrs(def_id), AttributeKind::ExportStable);
4849
if !self.in_exportable_mod && !has_attr {
4950
return false;
5051
}
@@ -80,7 +81,7 @@ impl<'tcx> ExportableItemCollector<'tcx> {
8081
fn walk_item_with_mod(&mut self, item: &'tcx hir::Item<'tcx>) {
8182
let def_id = item.hir_id().owner.def_id;
8283
let old_exportable_mod = self.in_exportable_mod;
83-
if self.tcx.get_attr(def_id, sym::export_stable).is_some() {
84+
if find_attr!(self.tcx.get_all_attrs(def_id), AttributeKind::ExportStable) {
8485
self.in_exportable_mod = true;
8586
}
8687
let old_seen_exportable_in_mod = std::mem::replace(&mut self.seen_exportable_in_mod, false);

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19331933
StringPart::highlighted("multiple different versions".to_string()),
19341934
StringPart::normal(" of crate `".to_string()),
19351935
StringPart::highlighted(format!("{crate_name}")),
1936-
StringPart::normal("` in the dependency graph\n".to_string()),
1936+
StringPart::normal("` in the dependency graph".to_string()),
19371937
],
19381938
);
19391939
if points_at_type {

0 commit comments

Comments
 (0)