From 7a96d86fb76789f5ad35e837d90ce1b7e31c3d55 Mon Sep 17 00:00:00 2001 From: Asuna Date: Thu, 7 May 2026 10:39:44 +0000 Subject: [PATCH 01/19] Fix typos in `intrinsics::size_of_type_id` panic message and doc comment --- library/core/src/intrinsics/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 1aeb1a0eb3972..411483b65cdac 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2939,11 +2939,11 @@ pub const fn type_id_eq(a: crate::any::TypeId, b: crate::any::TypeId) -> bool { /// Gets the size of the type represented by this `TypeId`. /// -/// The stabilized version of this intrinsic is [`core::any::TypeId::size`]. +/// The more user-friendly version of this intrinsic is [`core::any::TypeId::size`]. #[rustc_intrinsic] #[unstable(feature = "core_intrinsics", issue = "none")] pub const fn size_of_type_id(_id: crate::any::TypeId) -> Option { - panic!("`Type::size` can only be called at compile-time") + panic!("`TypeId::size` can only be called at compile-time") } /// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`. From d1ad6292d6f5a9cfb0c1b8552d2ae87468cacb9c Mon Sep 17 00:00:00 2001 From: Asuna Date: Thu, 7 May 2026 11:10:02 +0000 Subject: [PATCH 02/19] Add `TypeId::variants` method to get number of variants for `type_info` --- .../src/const_eval/machine.rs | 6 +++++ .../rustc_hir_analysis/src/check/intrinsic.rs | 2 ++ compiler/rustc_span/src/symbol.rs | 1 + library/core/src/intrinsics/mod.rs | 9 +++++++ library/core/src/mem/type_info.rs | 25 +++++++++++++++++++ library/coretests/tests/mem/type_info.rs | 12 +++++++++ 6 files changed, 55 insertions(+) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index fb456d80e465f..e406523122f03 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -622,6 +622,12 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { ecx.write_discriminant(variant_index, dest)?; } + sym::type_id_variants => { + let ty = ecx.read_type_id(&args[0])?; + let variants_num = ty.ty_adt_def().map(|def| def.variants().len()).unwrap_or(1); + ecx.write_scalar(Scalar::from_target_usize(variants_num as u64, ecx), dest)?; + } + sym::field_offset => { let frt_ty = instance.args.type_at(0); ensure_monomorphic_enough(ecx.tcx.tcx, frt_ty)?; diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 9059070157fac..528ccad1e6183 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -213,6 +213,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi | sym::truncf128 | sym::type_id | sym::type_id_eq + | sym::type_id_variants | sym::type_id_vtable | sym::type_name | sym::type_of @@ -319,6 +320,7 @@ pub(crate) fn check_intrinsic_type( sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)), sym::type_id => (1, 0, vec![], type_id_ty()), sym::type_id_eq => (0, 0, vec![type_id_ty(), type_id_ty()], tcx.types.bool), + sym::type_id_variants => (0, 0, vec![type_id_ty()], tcx.types.usize), sym::type_id_vtable => { let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, span); let dyn_metadata_adt_ref = tcx.adt_def(dyn_metadata); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 72339efd0a132..b71bc9e965616 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2098,6 +2098,7 @@ symbols! { type_changing_struct_update, type_id, type_id_eq, + type_id_variants, type_id_vtable, type_info, type_ir, diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 411483b65cdac..c549fea537414 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2946,6 +2946,15 @@ pub const fn size_of_type_id(_id: crate::any::TypeId) -> Option { panic!("`TypeId::size` can only be called at compile-time") } +/// Gets the number of variants of the type represented by this `TypeId`. +/// +/// The more user-friendly version of this intrinsic is [`core::any::TypeId::variants`]. +#[rustc_intrinsic] +#[unstable(feature = "core_intrinsics", issue = "none")] +pub const fn type_id_variants(_id: crate::any::TypeId) -> usize { + panic!("`TypeId::variants` can only be called at compile-time") +} + /// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`. /// /// This is used to implement functions like `slice::from_raw_parts_mut` and diff --git a/library/core/src/mem/type_info.rs b/library/core/src/mem/type_info.rs index 17c51ccaad858..6718cc4aed5bc 100644 --- a/library/core/src/mem/type_info.rs +++ b/library/core/src/mem/type_info.rs @@ -376,4 +376,29 @@ impl TypeId { pub const fn size(self) -> Option { intrinsics::size_of_type_id(self) } + + /// Returns the number of variants of the type represented by this `TypeId`. + /// + /// For enums, this is the number of variants. For structs and unions, this is always 1. + /// + /// ``` + /// #![feature(type_info)] + /// use std::any::TypeId; + /// + /// assert_eq!(const { TypeId::of::>().variants() }, 2); + /// + /// struct Unit; + /// struct Point { + /// x: u32, + /// y: u32, + /// } + /// assert_eq!(const { TypeId::of::().variants() }, 1); + /// assert_eq!(const { TypeId::of::().variants() }, 1); + /// assert_eq!(const { TypeId::of::<(f32, f32)>().variants() }, 1); + /// ``` + #[unstable(feature = "type_info", issue = "146922")] + #[rustc_const_unstable(feature = "type_info", issue = "146922")] + pub const fn variants(self) -> usize { + intrinsics::type_id_variants(self) + } } diff --git a/library/coretests/tests/mem/type_info.rs b/library/coretests/tests/mem/type_info.rs index e02077b96d35a..986166c5a4880 100644 --- a/library/coretests/tests/mem/type_info.rs +++ b/library/coretests/tests/mem/type_info.rs @@ -95,6 +95,7 @@ fn test_structs() { let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); } const { @@ -156,6 +157,7 @@ fn test_unions() { let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); } const { @@ -212,6 +214,7 @@ fn test_enums() { let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 3); } const { @@ -223,6 +226,7 @@ fn test_enums() { let ty_id = TypeId::of::>(); assert!(ty_id.size() == Some(size_of::>())); + assert!(ty_id.variants() == 2); } } @@ -234,43 +238,51 @@ fn test_primitives() { let Type { kind: Bool(_ty), .. } = (const { Type::of::() }) else { panic!() }; let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Char(_ty), .. } = (const { Type::of::() }) else { panic!() }; let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Int(ty), .. } = (const { Type::of::() }) else { panic!() }; assert!(ty.bits == 32); assert!(ty.signed); let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Int(ty), .. } = (const { Type::of::() }) else { panic!() }; assert!(ty.bits as usize == size_of::() * 8); assert!(ty.signed); let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Int(ty), .. } = (const { Type::of::() }) else { panic!() }; assert!(ty.bits == 32); assert!(!ty.signed); let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Int(ty), .. } = (const { Type::of::() }) else { panic!() }; assert!(ty.bits as usize == size_of::() * 8); assert!(!ty.signed); let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Float(ty), .. } = (const { Type::of::() }) else { panic!() }; assert!(ty.bits == 32); let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); let Type { kind: Str(_ty), .. } = (const { Type::of::() }) else { panic!() }; let ty_id = TypeId::of::(); assert!(ty_id.size() == None); + assert!(ty_id.variants() == 1); } } From b50aae66b8a76e3b57cf8c1282a89e9b92fd6305 Mon Sep 17 00:00:00 2001 From: Asuna Date: Thu, 7 May 2026 12:26:47 +0000 Subject: [PATCH 03/19] Add `TypeId::fields` method to get number of fields for `type_info` --- .../src/const_eval/machine.rs | 27 +++++++- .../rustc_hir_analysis/src/check/intrinsic.rs | 2 + compiler/rustc_span/src/symbol.rs | 1 + library/core/src/intrinsics/mod.rs | 9 +++ library/core/src/mem/type_info.rs | 62 +++++++++++++++++++ library/coretests/tests/mem/type_info.rs | 24 +++++++ .../reflection/variant_index_out_of_bounds.rs | 10 +++ .../variant_index_out_of_bounds.stderr | 22 +++++++ 8 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 tests/ui/reflection/variant_index_out_of_bounds.rs create mode 100644 tests/ui/reflection/variant_index_out_of_bounds.stderr diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index e406523122f03..da34f073795d2 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -2,7 +2,7 @@ use std::borrow::{Borrow, Cow}; use std::hash::Hash; use std::{fmt, mem}; -use rustc_abi::{Align, FIRST_VARIANT, FieldIdx, Size}; +use rustc_abi::{Align, FIRST_VARIANT, FieldIdx, Size, VariantIdx}; use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -622,6 +622,31 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { ecx.write_discriminant(variant_index, dest)?; } + sym::type_id_fields => { + let ty = ecx.read_type_id(&args[0])?; + let variant_idx = ecx.read_target_usize(&args[1])? as usize; + + let variants_num = + ty.ty_adt_def().map(|adt_def| adt_def.variants().len()).unwrap_or(1); + if variant_idx >= variants_num { + throw_ub!(BoundsCheckFailed { + len: variants_num as u64, + index: variant_idx as u64 + }); + } + + let fields_num = match ty.kind() { + ty::Adt(adt_def, _) => { + let variant_def = &adt_def.variants()[VariantIdx::from_usize(variant_idx)]; + variant_def.fields.len() + } + ty::Tuple(fields) => fields.len(), + _ => 0, // Other types have no fields + }; + + ecx.write_scalar(Scalar::from_target_usize(fields_num as u64, ecx), dest)?; + } + sym::type_id_variants => { let ty = ecx.read_type_id(&args[0])?; let variants_num = ty.ty_adt_def().map(|def| def.variants().len()).unwrap_or(1); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 528ccad1e6183..99f1750f9ccc6 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -213,6 +213,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi | sym::truncf128 | sym::type_id | sym::type_id_eq + | sym::type_id_fields | sym::type_id_variants | sym::type_id_vtable | sym::type_name @@ -320,6 +321,7 @@ pub(crate) fn check_intrinsic_type( sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)), sym::type_id => (1, 0, vec![], type_id_ty()), sym::type_id_eq => (0, 0, vec![type_id_ty(), type_id_ty()], tcx.types.bool), + sym::type_id_fields => (0, 0, vec![type_id_ty(), tcx.types.usize], tcx.types.usize), sym::type_id_variants => (0, 0, vec![type_id_ty()], tcx.types.usize), sym::type_id_vtable => { let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, span); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index b71bc9e965616..540d30a215f5d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2098,6 +2098,7 @@ symbols! { type_changing_struct_update, type_id, type_id_eq, + type_id_fields, type_id_variants, type_id_vtable, type_info, diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index c549fea537414..1fe7b839597e6 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2955,6 +2955,15 @@ pub const fn type_id_variants(_id: crate::any::TypeId) -> usize { panic!("`TypeId::variants` can only be called at compile-time") } +/// Gets the number of fields at the given `variant_index` represented by this `TypeId`. +/// +/// The more user-friendly version of this intrinsic is [`core::any::TypeId::fields`]. +#[rustc_intrinsic] +#[unstable(feature = "core_intrinsics", issue = "none")] +pub const fn type_id_fields(_id: crate::any::TypeId, _variant_index: usize) -> usize { + panic!("`TypeId::fields` can only be called at compile-time") +} + /// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`. /// /// This is used to implement functions like `slice::from_raw_parts_mut` and diff --git a/library/core/src/mem/type_info.rs b/library/core/src/mem/type_info.rs index 6718cc4aed5bc..a03d4ad1d6d04 100644 --- a/library/core/src/mem/type_info.rs +++ b/library/core/src/mem/type_info.rs @@ -401,4 +401,66 @@ impl TypeId { pub const fn variants(self) -> usize { intrinsics::type_id_variants(self) } + + /// Returns the number of fields at the given `variant_index` of the type represented by this `TypeId`. + /// + /// ``` + /// #![feature(type_info)] + /// use std::any::TypeId; + /// + /// assert_eq!(const { TypeId::of::().fields(0) }, 0); + /// + /// struct Point { + /// x: u32, + /// y: u32, + /// } + /// assert_eq!(const { TypeId::of::().fields(0) }, 2); + /// + /// enum Enum { + /// Unit, + /// Tuple(u32, u64), + /// Struct { x: u32, y: u32, z: String }, + /// } + /// assert_eq!(const { TypeId::of::().fields(0) }, 0); + /// assert_eq!(const { TypeId::of::().fields(1) }, 2); + /// assert_eq!(const { TypeId::of::().fields(2) }, 3); + /// ``` + /// + /// The variant index refers to the source order index of a variant in a type. + /// + /// For enums, these are always `0..variant_count`, regardless of any custom discriminants that may have been defined. + /// `struct`s, `tuples`, and `unions`s are considered to have a single variant with variant index zero. + /// + /// ``` + /// enum Number { + /// Seven = 7, // variant index == 0 + /// Six = 6, // variant index == 1 + /// } + /// ``` + /// + /// Out-of-bounds indexing will be treated as a compile-time error. + /// + /// ```compile_fail,E0080 + /// # #![feature(type_info)] + /// # use std::any::TypeId; + /// # + /// # struct Point { + /// # x: u32, + /// # y: u32, + /// # } + /// # enum Enum { + /// # Unit, + /// # Tuple(u32, u64), + /// # Struct { x: u32, y: u32, z: String }, + /// # } + /// const { + /// _ = TypeId::of::().fields(10); // error: indexing out of bounds: the len is 2 but the index is 10 + /// _ = TypeId::of::().fields(10); // error: indexing out of bounds: the len is 3 but the index is 10 + /// } + /// ``` + #[unstable(feature = "type_info", issue = "146922")] + #[rustc_const_unstable(feature = "type_info", issue = "146922")] + pub const fn fields(self, variant_index: usize) -> usize { + intrinsics::type_id_fields(self, variant_index) + } } diff --git a/library/coretests/tests/mem/type_info.rs b/library/coretests/tests/mem/type_info.rs index 986166c5a4880..ab5b8d8ffe573 100644 --- a/library/coretests/tests/mem/type_info.rs +++ b/library/coretests/tests/mem/type_info.rs @@ -67,6 +67,23 @@ fn test_tuples() { _ => unreachable!(), } } + + const { + let ty_id = TypeId::of::<()>(); + assert!(ty_id.size() == Some(size_of::<()>())); + assert!(ty_id.variants() == 1); + assert!(ty_id.fields(0) == 0); + + let ty_id = TypeId::of::<(u8,)>(); + assert!(ty_id.size() == Some(size_of::<(u8,)>())); + assert!(ty_id.variants() == 1); + assert!(ty_id.fields(0) == 1); + + let ty_id = TypeId::of::<(u8, u8)>(); + assert!(ty_id.size() == Some(size_of::<(u8, u8)>())); + assert!(ty_id.variants() == 1); + assert!(ty_id.fields(0) == 2); + } } #[test] @@ -96,6 +113,7 @@ fn test_structs() { let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); assert!(ty_id.variants() == 1); + assert!(ty_id.fields(0) == 3); } const { @@ -158,6 +176,7 @@ fn test_unions() { let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); assert!(ty_id.variants() == 1); + assert!(ty_id.fields(0) == 2); } const { @@ -215,6 +234,9 @@ fn test_enums() { let ty_id = TypeId::of::(); assert!(ty_id.size() == Some(size_of::())); assert!(ty_id.variants() == 3); + assert!(ty_id.fields(0) == 1); + assert!(ty_id.fields(1) == 0); + assert!(ty_id.fields(2) == 2); } const { @@ -227,6 +249,8 @@ fn test_enums() { let ty_id = TypeId::of::>(); assert!(ty_id.size() == Some(size_of::>())); assert!(ty_id.variants() == 2); + assert!(ty_id.fields(0) == 0); + assert!(ty_id.fields(1) == 1); } } diff --git a/tests/ui/reflection/variant_index_out_of_bounds.rs b/tests/ui/reflection/variant_index_out_of_bounds.rs new file mode 100644 index 0000000000000..3f25e52050845 --- /dev/null +++ b/tests/ui/reflection/variant_index_out_of_bounds.rs @@ -0,0 +1,10 @@ +#![feature(type_info)] + +use std::any::TypeId; + +fn main() {} + +const _: () = const { + TypeId::of::>().fields(2); + //~^ ERROR indexing out of bounds: the len is 2 but the index is 2 +}; diff --git a/tests/ui/reflection/variant_index_out_of_bounds.stderr b/tests/ui/reflection/variant_index_out_of_bounds.stderr new file mode 100644 index 0000000000000..dec9a8d1393fe --- /dev/null +++ b/tests/ui/reflection/variant_index_out_of_bounds.stderr @@ -0,0 +1,22 @@ +error[E0080]: indexing out of bounds: the len is 2 but the index is 2 + --> $DIR/variant_index_out_of_bounds.rs:8:5 + | +LL | TypeId::of::>().fields(2); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_::{constant#0}` failed inside this call + | +note: inside `type_info::::fields` + --> $SRC_DIR/core/src/mem/type_info.rs:LL:COL + +note: erroneous constant encountered + --> $DIR/variant_index_out_of_bounds.rs:7:15 + | +LL | const _: () = const { + | _______________^ +LL | | TypeId::of::>().fields(2); +LL | | +LL | | }; + | |_^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. From 8fec623804f8451729c0504f6d5757bcc922c0c4 Mon Sep 17 00:00:00 2001 From: Aria Givens Date: Thu, 21 May 2026 12:42:31 +0200 Subject: [PATCH 04/19] Inside attributes, suggest adding quotation marks to identifier when literal was expected --- compiler/rustc_attr_parsing/src/parser.rs | 17 +++++++++++++++-- tests/ui/attributes/crate-type-non-crate.stderr | 4 ++-- ...tion-on-associated-items-issue-121537.stderr | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 48790f273adfc..15a9eb91a143d 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -12,7 +12,7 @@ use rustc_ast::{ AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp, }; use rustc_ast_pretty::pprust; -use rustc_errors::{Diag, PResult}; +use rustc_errors::{Applicability, Diag, PResult}; use rustc_hir::{self as hir, AttrPath}; use rustc_parse::exp; use rustc_parse::parser::{ForceCollect, Parser, PathStyle, Recovery, token_descr}; @@ -410,7 +410,20 @@ fn expr_to_lit<'sess>( // - `#[foo = include_str!("nonexistent-file.rs")]`: // results in `ast::ExprKind::Err`. let msg = "attribute value must be a literal"; - let err = psess.dcx().struct_span_err(span, msg); + let mut err = psess.dcx().struct_span_err(span, msg); + + // Suggest adding quotation marks to turn an identifier into a string literal + if let ExprKind::Path(None, ref path) = expr.kind + && let [segment] = path.segments.as_slice() + { + err.span_suggestion( + expr.span, + "try adding quotation marks", + &format!("\"{}\"", segment.ident), + Applicability::MaybeIncorrect, + ); + } + Err(err) } } diff --git a/tests/ui/attributes/crate-type-non-crate.stderr b/tests/ui/attributes/crate-type-non-crate.stderr index 3ad51403db518..d27d81f784254 100644 --- a/tests/ui/attributes/crate-type-non-crate.stderr +++ b/tests/ui/attributes/crate-type-non-crate.stderr @@ -40,7 +40,7 @@ error: attribute value must be a literal --> $DIR/crate-type-non-crate.rs:9:16 | LL | #[crate_type = lib] - | ^^^ + | ^^^ help: try adding quotation marks: `"lib"` error[E0539]: malformed `crate_type` attribute input --> $DIR/crate-type-non-crate.rs:12:1 @@ -72,7 +72,7 @@ error: attribute value must be a literal --> $DIR/crate-type-non-crate.rs:14:16 | LL | #[crate_type = foo] - | ^^^ + | ^^^ help: try adding quotation marks: `"foo"` error[E0539]: malformed `crate_type` attribute input --> $DIR/crate-type-non-crate.rs:17:1 diff --git a/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr b/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr index 9c37bb8231790..750ca2e3aaca2 100644 --- a/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr +++ b/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr @@ -2,7 +2,7 @@ error: attribute value must be a literal --> $DIR/validation-on-associated-items-issue-121537.rs:2:13 | LL | #[doc = MyTrait] - | ^^^^^^^ + | ^^^^^^^ help: try adding quotation marks: `"MyTrait"` error: aborting due to 1 previous error From 28733aa84bda079d2e342404548d913032f623b4 Mon Sep 17 00:00:00 2001 From: Asuna Date: Sun, 10 May 2026 14:23:30 +0000 Subject: [PATCH 05/19] Add `TypeId::field` method to get a field representing type for `type_info` --- .../src/const_eval/machine.rs | 47 ++++++++++ .../rustc_hir_analysis/src/check/intrinsic.rs | 4 + compiler/rustc_span/src/symbol.rs | 1 + library/core/src/any.rs | 2 +- library/core/src/intrinsics/mod.rs | 13 +++ library/core/src/mem/type_info.rs | 91 +++++++++++++++++++ library/coretests/tests/mem/type_info.rs | 23 ++++- .../reflection/variant_index_out_of_bounds.rs | 5 + .../variant_index_out_of_bounds.stderr | 21 ++++- 9 files changed, 203 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index da34f073795d2..f37c57c73de73 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -647,6 +647,53 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { ecx.write_scalar(Scalar::from_target_usize(fields_num as u64, ecx), dest)?; } + sym::type_id_field => { + let ty = ecx.read_type_id(&args[0])?; + let variant_idx = ecx.read_target_usize(&args[1])? as usize; + let field_idx = ecx.read_target_usize(&args[2])? as usize; + + let variants_num = + ty.ty_adt_def().map(|adt_def| adt_def.variants().len()).unwrap_or(1); + if variant_idx >= variants_num { + throw_ub!(BoundsCheckFailed { + len: variants_num as u64, + index: variant_idx as u64 + }); + } + + let field_ty = match ty.kind() { + ty::Adt(adt_def, generics) => { + let variant_def = &adt_def.variants()[VariantIdx::from_usize(variant_idx)]; + let fields_num = variant_def.fields.len(); + if field_idx >= fields_num { + throw_ub!(BoundsCheckFailed { + len: fields_num as u64, + index: field_idx as u64 + }); + } + let field_def = &variant_def.fields[FieldIdx::from_usize(field_idx)]; + field_def.ty(ecx.tcx.tcx, generics).skip_norm_wip() + } + ty::Tuple(fields) => { + let fields_num = fields.len(); + if field_idx >= fields_num { + throw_ub!(BoundsCheckFailed { + len: fields_num as u64, + index: field_idx as u64 + }); + } + fields[field_idx] + } + _ => { + // Other types have no fields, so any field index is out of bounds. + throw_ub!(BoundsCheckFailed { len: 0, index: field_idx as u64 }); + } + }; + + let field_ty = ecx.tcx.erase_and_anonymize_regions(field_ty); + ecx.write_type_id(field_ty, dest)?; + } + sym::type_id_variants => { let ty = ecx.read_type_id(&args[0])?; let variants_num = ty.ty_adt_def().map(|def| def.variants().len()).unwrap_or(1); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 99f1750f9ccc6..b37aa4fac4e98 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -213,6 +213,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi | sym::truncf128 | sym::type_id | sym::type_id_eq + | sym::type_id_field | sym::type_id_fields | sym::type_id_variants | sym::type_id_vtable @@ -321,6 +322,9 @@ pub(crate) fn check_intrinsic_type( sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)), sym::type_id => (1, 0, vec![], type_id_ty()), sym::type_id_eq => (0, 0, vec![type_id_ty(), type_id_ty()], tcx.types.bool), + sym::type_id_field => { + (0, 0, vec![type_id_ty(), tcx.types.usize, tcx.types.usize], type_id_ty()) + } sym::type_id_fields => (0, 0, vec![type_id_ty(), tcx.types.usize], tcx.types.usize), sym::type_id_variants => (0, 0, vec![type_id_ty()], tcx.types.usize), sym::type_id_vtable => { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 540d30a215f5d..5d3b9ad64f103 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2098,6 +2098,7 @@ symbols! { type_changing_struct_update, type_id, type_id_eq, + type_id_field, type_id_fields, type_id_variants, type_id_vtable, diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 62300d8b70a96..92e45c46c8699 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -852,7 +852,7 @@ impl TypeId { } } - fn as_u128(self) -> u128 { + pub(crate) fn as_u128(self) -> u128 { let mut bytes = [0; 16]; // This is a provenance-stripping memcpy. diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 1fe7b839597e6..9b5aa9d6255a4 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2964,6 +2964,19 @@ pub const fn type_id_fields(_id: crate::any::TypeId, _variant_index: usize) -> u panic!("`TypeId::fields` can only be called at compile-time") } +/// Gets the `TypeId` of the field at the given index of the type represented by this `TypeId`. +/// +/// The more user-friendly version of this intrinsic is [`core::any::TypeId::field`]. +#[rustc_intrinsic] +#[unstable(feature = "core_intrinsics", issue = "none")] +pub const fn type_id_field( + _id: crate::any::TypeId, + _variant_index: usize, + _field_index: usize, +) -> crate::any::TypeId { + panic!("`TypeId::field` can only be called at compile-time") +} + /// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`. /// /// This is used to implement functions like `slice::from_raw_parts_mut` and diff --git a/library/core/src/mem/type_info.rs b/library/core/src/mem/type_info.rs index a03d4ad1d6d04..373eb81a201b6 100644 --- a/library/core/src/mem/type_info.rs +++ b/library/core/src/mem/type_info.rs @@ -2,6 +2,7 @@ //! runtime or const-eval processable way. use crate::any::TypeId; +use crate::fmt; use crate::intrinsics::{self, type_id, type_of}; use crate::marker::PointeeSized; use crate::ptr::DynMetadata; @@ -463,4 +464,94 @@ impl TypeId { pub const fn fields(self, variant_index: usize) -> usize { intrinsics::type_id_fields(self, variant_index) } + + /// Returns the field representing type at the given index of the type represented by this `TypeId`. + /// + /// ``` + /// #![feature(type_info)] + /// use std::any::TypeId; + /// + /// struct Point { + /// x: u32, + /// y: u32, + /// } + /// assert_eq!(const { TypeId::of::().field(0, 0).type_id() }, TypeId::of::()); + /// assert_eq!(const { TypeId::of::().field(0, 1).type_id() }, TypeId::of::()); + /// + /// enum Enum { + /// Unit, + /// Tuple(u32, u64), + /// Struct { x: u32, y: u32, z: String }, + /// } + /// assert_eq!(const { TypeId::of::().field(1, 0).type_id() }, TypeId::of::()); + /// assert_eq!(const { TypeId::of::().field(2, 2).type_id() }, TypeId::of::()); + /// ``` + /// + /// The variant index and field index refer to the source order index of a variant in a type and + /// the source order index of a field in a variant, respectively. + /// + /// For enums, variant indexes are always `0..variant_count`, regardless of any custom discriminants that may have been defined. + /// `struct`s, `tuples`, and `unions`s are considered to have a single variant with variant index zero. + /// + /// As for field indexes, they may not be the same as the layout order for `repr(Rust)` types, but they are for `repr(C)` types. + /// + /// ``` + /// enum Enum { + /// Foo, // variant index == 0 + /// Bar { // variant index == 1 + /// a: (), // field index == 0 in `Bar` + /// b: (), // field index == 1 in `Bar` + /// } + /// } + /// ``` + /// + /// Out-of-bounds indexing will be treated as a compile-time error. + /// + /// ```compile_fail,E0080 + /// # #![feature(type_info)] + /// # use std::any::TypeId; + /// # + /// # struct Point { + /// # x: u32, + /// # y: u32, + /// # } + /// # enum Enum { + /// # Unit, + /// # Tuple(u32, u64), + /// # Struct { x: u32, y: u32, z: String }, + /// # } + /// const { + /// _ = TypeId::of::().field(0, 10); // error: indexing out of bounds: the len is 2 but the index is 10 + /// _ = TypeId::of::().field(2, 10); // error: indexing out of bounds: the len is 3 but the index is 10 + /// } + /// ``` + #[unstable(feature = "type_info", issue = "146922")] + #[rustc_const_unstable(feature = "type_info", issue = "146922")] + pub const fn field(self, variant_index: usize, field_index: usize) -> FieldId { + FieldId { type_id: intrinsics::type_id_field(self, variant_index, field_index) } + } +} + +/// `FieldId` is a wrapper of `TypeId`, representing a field of a struct, tuple or enum variant. +#[derive(Copy, PartialOrd, Ord, Hash)] +#[derive_const(Clone, PartialEq, Eq)] +#[unstable(feature = "type_info", issue = "146922")] +pub struct FieldId { + type_id: TypeId, +} + +#[unstable(feature = "type_info", issue = "146922")] +impl fmt::Debug for FieldId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "FieldId({:#034x})", self.type_id.as_u128()) + } +} + +impl FieldId { + /// Returns the `TypeId` of this field. + #[unstable(feature = "type_info", issue = "146922")] + #[rustc_const_unstable(feature = "type_info", issue = "146922")] + pub const fn type_id(self) -> TypeId { + self.type_id + } } diff --git a/library/coretests/tests/mem/type_info.rs b/library/coretests/tests/mem/type_info.rs index ab5b8d8ffe573..9a37a2ba0db5f 100644 --- a/library/coretests/tests/mem/type_info.rs +++ b/library/coretests/tests/mem/type_info.rs @@ -78,11 +78,14 @@ fn test_tuples() { assert!(ty_id.size() == Some(size_of::<(u8,)>())); assert!(ty_id.variants() == 1); assert!(ty_id.fields(0) == 1); + assert!(ty_id.field(0, 0).type_id() == TypeId::of::()); - let ty_id = TypeId::of::<(u8, u8)>(); - assert!(ty_id.size() == Some(size_of::<(u8, u8)>())); + let ty_id = TypeId::of::<(u8, u16)>(); + assert!(ty_id.size() == Some(size_of::<(u8, u16)>())); assert!(ty_id.variants() == 1); assert!(ty_id.fields(0) == 2); + assert!(ty_id.field(0, 0).type_id() == TypeId::of::()); + assert!(ty_id.field(0, 1).type_id() == TypeId::of::()); } } @@ -114,6 +117,9 @@ fn test_structs() { assert!(ty_id.size() == Some(size_of::())); assert!(ty_id.variants() == 1); assert!(ty_id.fields(0) == 3); + assert!(ty_id.field(0, 0).type_id() == TypeId::of::()); + assert!(ty_id.field(0, 1).type_id() == TypeId::of::()); + assert!(ty_id.field(0, 2).type_id() == TypeId::of::<&u16>()); } const { @@ -135,6 +141,13 @@ fn test_structs() { assert!(ty.fields[0].ty == TypeId::of::()); assert!(ty.fields[1].name == "1"); assert!(ty.fields[1].ty == TypeId::of::()); + + let ty_id = TypeId::of::(); + assert!(ty_id.size() == Some(size_of::())); + assert!(ty_id.variants() == 1); + assert!(ty_id.fields(0) == 2); + assert!(ty_id.field(0, 0).type_id() == TypeId::of::()); + assert!(ty_id.field(0, 1).type_id() == TypeId::of::()); } const { @@ -177,6 +190,8 @@ fn test_unions() { assert!(ty_id.size() == Some(size_of::())); assert!(ty_id.variants() == 1); assert!(ty_id.fields(0) == 2); + assert!(ty_id.field(0, 0).type_id() == TypeId::of::()); + assert!(ty_id.field(0, 1).type_id() == TypeId::of::()); } const { @@ -237,6 +252,9 @@ fn test_enums() { assert!(ty_id.fields(0) == 1); assert!(ty_id.fields(1) == 0); assert!(ty_id.fields(2) == 2); + assert!(ty_id.field(0, 0).type_id() == TypeId::of::()); + assert!(ty_id.field(2, 0).type_id() == TypeId::of::<()>()); + assert!(ty_id.field(2, 1).type_id() == TypeId::of::<&str>()); } const { @@ -251,6 +269,7 @@ fn test_enums() { assert!(ty_id.variants() == 2); assert!(ty_id.fields(0) == 0); assert!(ty_id.fields(1) == 1); + assert!(ty_id.field(1, 0).type_id() == TypeId::of::()); } } diff --git a/tests/ui/reflection/variant_index_out_of_bounds.rs b/tests/ui/reflection/variant_index_out_of_bounds.rs index 3f25e52050845..2e6ac7f65927c 100644 --- a/tests/ui/reflection/variant_index_out_of_bounds.rs +++ b/tests/ui/reflection/variant_index_out_of_bounds.rs @@ -8,3 +8,8 @@ const _: () = const { TypeId::of::>().fields(2); //~^ ERROR indexing out of bounds: the len is 2 but the index is 2 }; + +const _: () = const { + TypeId::of::>().field(0, 1); + //~^ ERROR indexing out of bounds: the len is 0 but the index is 1 +}; diff --git a/tests/ui/reflection/variant_index_out_of_bounds.stderr b/tests/ui/reflection/variant_index_out_of_bounds.stderr index dec9a8d1393fe..177b662d84b7b 100644 --- a/tests/ui/reflection/variant_index_out_of_bounds.stderr +++ b/tests/ui/reflection/variant_index_out_of_bounds.stderr @@ -17,6 +17,25 @@ LL | | LL | | }; | |_^ -error: aborting due to 1 previous error +error[E0080]: indexing out of bounds: the len is 0 but the index is 1 + --> $DIR/variant_index_out_of_bounds.rs:13:5 + | +LL | TypeId::of::>().field(0, 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_::{constant#0}` failed inside this call + | +note: inside `type_info::::field` + --> $SRC_DIR/core/src/mem/type_info.rs:LL:COL + +note: erroneous constant encountered + --> $DIR/variant_index_out_of_bounds.rs:12:15 + | +LL | const _: () = const { + | _______________^ +LL | | TypeId::of::>().field(0, 1); +LL | | +LL | | }; + | |_^ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. From 76de222d0d0baf554128717a9c8bbcc85114b21b Mon Sep 17 00:00:00 2001 From: Boxy Uwu Date: Mon, 25 May 2026 20:07:28 +0100 Subject: [PATCH 06/19] add relnotes --- RELEASES.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 87768b2f74e76..747ef283699a0 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,101 @@ +Version 1.96.0 (2026-05-28) +========================== + + + +Language +-------- +- [Allow passing `expr` metavariable to `cfg`](https://github.com/rust-lang/rust/pull/146961) +- [Always coerce never types in tuple expressions](https://github.com/rust-lang/rust/pull/147834) +- [Avoid incorrect inference guidance of function arguments in rare cases](https://github.com/rust-lang/rust/pull/150316) +- [Support s390x vector registers in inline assembly](https://github.com/rust-lang/rust/pull/154184) +- [Allow using constants of type `ManuallyDrop` as patterns (fixing a regression introduced in 1.94.0)](https://github.com/rust-lang/rust/pull/154891) + + + + +Compiler +-------- +- [Enable link relaxation feature for LoongArch Linux targets](https://github.com/rust-lang/rust/pull/153427) +- [Update `riscv64gc-unknown-fuchsia` baseline to RVA22 + vector](https://github.com/rust-lang/rust/pull/155072) + + + + + + +Libraries +--------- +- [Support iterating over ranges of `NonZero` integers](https://github.com/rust-lang/rust/pull/127534) +- [refactor 'valid for read/write' definition: exclude null; add that as an exception on individual methods instead](https://github.com/rust-lang/rust/pull/152615) +- [Fix SGX delayed host lookup via ToSocketAddr](https://github.com/rust-lang/rust/pull/152851) + + + + +Stabilized APIs +--------------- + +- [`assert_matches!`](https://doc.rust-lang.org/stable/std/macro.debug_assert_matches.html) +- [`debug_assert_matches!`](https://doc.rust-lang.org/stable/std/macro.debug_assert_matches.html) +- [`From for AssertUnwindSafe`](https://doc.rust-lang.org/stable/std/panic/struct.AssertUnwindSafe.html#impl-From%3CT%3E-for-AssertUnwindSafe%3CT%3E) +- [`From for LazyCell`](https://doc.rust-lang.org/stable/std/cell/struct.LazyCell.html#impl-From%3CT%3E-for-LazyCell%3CT,+F%3E) +- [`From for LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html#impl-From%3CT%3E-for-LazyLock%3CT,+F%3E) +- +- [`core::range::RangeToInclusive`](https://doc.rust-lang.org/stable/core/range/struct.RangeToInclusive.html) +- [`core::range::RangeToInclusiveIter`](https://doc.rust-lang.org/stable/core/range/struct.RangeToInclusiveIter.html) +- [`core::range::RangeFrom`](https://doc.rust-lang.org/stable/core/ops/struct.RangeFrom.html) +- [`core::range::RangeFromIter`](https://doc.rust-lang.org/stable/core/ops/struct.RangeFromIter.html) +- [`core::range::Range`](https://doc.rust-lang.org/stable/std/range/struct.Range.html) +- [`core::range::RangeIter`](https://doc.rust-lang.org/stable/std/range/struct.RangeIter.html) + + + + +Cargo +----- +- [Allow a dependency to specify both a git repository and an alternate registry.](https://github.com/rust-lang/cargo/pull/16810/) Just like with crates.io, the git repository will be used locally, but the registry version will be used when published. +- [Added `target.'cfg(..)'.rustdocflags` support in configuration.](https://github.com/rust-lang/cargo/pull/16846) + +Rustdoc +----- +- [Deprecation notes are now rendered like any other documentation](https://github.com/rust-lang/rust/pull/149931). Previously they used the css `white-space: pre-wrap;` property and stripped any `

` elements from the rendered html, however this caused issues and unintuitive behavior. The new behavior should be more predictable, however some multi-line deprecation notes will now be rendered as as single lines. If this is undesirable, you can use the standard markdown method of forcing a linebreak, which is `" \n"` (two spaces followed by a newline). +- [Don't emit rustdoc `missing_doc_code_examples` lint on impl items](https://github.com/rust-lang/rust/pull/154048) +- [Seperate methods and associated functions in sidebar](https://github.com/rust-lang/rust/pull/154644) + + +Compatibility Notes +------------------- +- [Fix layout of `#[repr(Int)]` enums in some edge cases involving fields of uninhabited zero-sized types](https://github.com/rust-lang/rust/pull/146989) +- [Prevent unsize-coercing into `Pin` where `Foo` doesn't implement `Deref`. Some such coercions were previously allowed, but produce a type with no useful public API.](https://github.com/rust-lang/rust/pull/149218) +- [rustc: Stop passing `--allow-undefined` on wasm targets](https://github.com/rust-lang/rust/pull/149868) +- [Gate the accidentally stabilized #![reexport_test_harness_main] attribute](https://github.com/rust-lang/rust/pull/152210) +- [Error on return-position-impl-trait-in-traits whose types are too private](https://github.com/rust-lang/rust/pull/152543) +- [Report the `uninhabited_static` lint in dependencies and make it deny-by-default](https://github.com/rust-lang/rust/pull/152853) +- [Distributed builds now contain non-split debuginfo for windows-gnu](https://github.com/rust-lang/rust/pull/152870) + This appears to improve the quality of backtraces. This change has no effect on the defaults for the output of rustc/cargo on these targets. +- [Check const generic arguments are correctly typed in more positions](https://github.com/rust-lang/rust/pull/152931) +- [Remove -Csoft-float](https://github.com/rust-lang/rust/pull/152973) +- [Importing structs with `::{self [as name]}`, e.g., `struct S {}; use S::{self as Other};`, is now no longer permitted because `{self}` imports require a module parent.](https://github.com/rust-lang/rust/pull/152996) +- [For `export_name`, `link_name`, and `link_section` attributes, if multiple of the same attribute is present, the first one now takes precedence.](https://github.com/rust-lang/rust/pull/153041) +- [Update the minimum external LLVM to 21](https://github.com/rust-lang/rust/pull/153684) +- On `avr` targets, C's `double` type is 32-bit by default, so [change `c_double` to `f32` on `avr` targets to match](https://github.com/rust-lang/rust/pull/154647). This is a breaking change, but necessary to make `c_double` match C's double. + + + + +Internal Changes +---------------- + +These changes do not affect any public interfaces of Rust, but they represent +significant improvements to the performance or internals of rustc and related +tools. + +- [JSON targets: `aarch64` softfloat targets now have to have `rustc_abi` set to `"softfloat"`](https://github.com/rust-lang/rust/pull/152941) +- [target specs: stricter checks for LLVM ABI values, and correlate that with cfg(target_abi)](https://github.com/rust-lang/rust/pull/153769) + + + Version 1.95.0 (2026-04-16) =========================== From a7cdee19d8223eaa401712150962fac237d9c655 Mon Sep 17 00:00:00 2001 From: Boxy Date: Mon, 25 May 2026 20:11:01 +0100 Subject: [PATCH 07/19] Apply suggestion from @BoxyUwU --- RELEASES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 747ef283699a0..854dfa4631bbd 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -41,7 +41,6 @@ Stabilized APIs - [`From for AssertUnwindSafe`](https://doc.rust-lang.org/stable/std/panic/struct.AssertUnwindSafe.html#impl-From%3CT%3E-for-AssertUnwindSafe%3CT%3E) - [`From for LazyCell`](https://doc.rust-lang.org/stable/std/cell/struct.LazyCell.html#impl-From%3CT%3E-for-LazyCell%3CT,+F%3E) - [`From for LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html#impl-From%3CT%3E-for-LazyLock%3CT,+F%3E) -- - [`core::range::RangeToInclusive`](https://doc.rust-lang.org/stable/core/range/struct.RangeToInclusive.html) - [`core::range::RangeToInclusiveIter`](https://doc.rust-lang.org/stable/core/range/struct.RangeToInclusiveIter.html) - [`core::range::RangeFrom`](https://doc.rust-lang.org/stable/core/ops/struct.RangeFrom.html) From b665316530342625ebc57d4c7137770c2625da84 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 27 May 2026 12:08:59 +0200 Subject: [PATCH 08/19] Allow building the source tarballs while offline Previously locally vendored dependencies wouldn't be reused when building the source tarball, instead everything would be downloaded from the internet again (if not in the cargo cache). --- src/bootstrap/src/core/build_steps/vendor.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/vendor.rs b/src/bootstrap/src/core/build_steps/vendor.rs index 246598550553a..17bee20a525b6 100644 --- a/src/bootstrap/src/core/build_steps/vendor.rs +++ b/src/bootstrap/src/core/build_steps/vendor.rs @@ -114,6 +114,13 @@ impl Step for Vendor { cmd.arg("--sync").arg(sync_arg); } + // Reuse vendored dependencies when building source tarball for offline support. + if builder.config.vendor { + cmd.arg("--respect-source-config") + .arg("--config") + .arg(builder.src.join(".cargo").join("config.toml")); + } + // Will read the libstd Cargo.toml // which uses the unstable `public-dependency` feature. cmd.env("RUSTC_BOOTSTRAP", "1"); @@ -135,6 +142,13 @@ impl Step for Vendor { cmd.arg("--versioned-dirs"); } + // Reuse vendored dependencies when building source tarball for offline support. + if builder.config.vendor { + cmd.arg("--respect-source-config") + .arg("--config") + .arg(builder.src.join("library").join(".cargo").join("config.toml")); + } + // Will read the libstd Cargo.toml // which uses the unstable `public-dependency` feature. cmd.env("RUSTC_BOOTSTRAP", "1"); From 2043790c3a6c0fed33c27acb5d91da52903a8e1d Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 27 May 2026 16:04:59 +0200 Subject: [PATCH 09/19] `#[expect]` is an attribute valid for outer style --- compiler/rustc_ast/src/ast.rs | 1 + tests/ui/parser/const-block-items/inner-attr.stderr | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index af8ad425507c4..682ba78cddc5f 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3497,6 +3497,7 @@ impl AttrItem { || self.path == sym::warn || self.path == sym::allow || self.path == sym::deny + || self.path == sym::expect } } diff --git a/tests/ui/parser/const-block-items/inner-attr.stderr b/tests/ui/parser/const-block-items/inner-attr.stderr index e0a70566332cf..8cd5d1487b083 100644 --- a/tests/ui/parser/const-block-items/inner-attr.stderr +++ b/tests/ui/parser/const-block-items/inner-attr.stderr @@ -8,6 +8,11 @@ LL | fn main() {} | ------------ the inner attribute doesn't annotate this function | = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files +help: to annotate the function, change the attribute from inner to outer style + | +LL - #![expect(unused)] +LL + #[expect(unused)] + | error: aborting due to 1 previous error From 6a51d20cd635d840cd26bff0bbdf93be6f75e977 Mon Sep 17 00:00:00 2001 From: Dnreikronos Date: Wed, 27 May 2026 12:05:42 -0300 Subject: [PATCH 10/19] Show crate root path in misplaced crate-level attribute diagnostic When a crate-level attribute like `#![feature(...)]` is used as an inner attribute inside a non-root module, the diagnostic now includes a help message pointing to the crate root file path, making it easier for users to find where the attribute should be placed. --- compiler/rustc_attr_parsing/src/errors.rs | 3 + .../rustc_attr_parsing/src/target_checking.rs | 12 +- tests/ui/attributes/attr-mix-new.stderr | 1 + .../ui/attributes/crate-only-as-outer.stderr | 2 + .../issue-43106-gating-of-builtin-attrs.rs | 9 + ...issue-43106-gating-of-builtin-attrs.stderr | 270 ++++++++++-------- tests/ui/lint/lint-misplaced-attr.stderr | 1 + 7 files changed, 171 insertions(+), 127 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index d2c9c1b1eb807..56f6d29778414 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -165,6 +165,9 @@ pub(crate) struct InvalidAttrStyle { #[note("this attribute does not have an `!`, which means it is applied to this {$target}")] pub target_span: Option, pub target: &'static str, + pub crate_root_path: String, + #[help("the crate root is at `{$crate_root_path}`")] + pub show_crate_root_help: bool, } #[derive(Diagnostic)] diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index d05f1baf63dad..496c386bf6303 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -5,7 +5,7 @@ use rustc_errors::{DiagArgValue, Diagnostic, MultiSpan, StashKey}; use rustc_feature::Features; use rustc_hir::attrs::AttributeKind; use rustc_hir::{AttrItem, Attribute, MethodKind, Target}; -use rustc_span::{BytePos, Span, Symbol, sym}; +use rustc_span::{BytePos, RemapPathScopeComponents, Span, Symbol, sym}; use crate::AttributeParser; use crate::context::AcceptContext; @@ -186,6 +186,14 @@ impl<'sess> AttributeParser<'sess> { let target_span = cx.target_span; let attr_span = cx.attr_span; + let (show_crate_root_help, crate_root_path) = is_used_as_inner + .then(|| cx.cx.sess.local_crate_source_file()) + .flatten() + .map(|src| { + (true, src.path(RemapPathScopeComponents::DIAGNOSTICS).display().to_string()) + }) + .unwrap_or_default(); + cx.emit_lint( rustc_session::lint::builtin::UNUSED_ATTRIBUTES, crate::errors::InvalidAttrStyle { @@ -193,6 +201,8 @@ impl<'sess> AttributeParser<'sess> { is_used_as_inner, target_span: (!is_used_as_inner).then_some(target_span), target: target.name(), + crate_root_path, + show_crate_root_help, }, attr_span, ); diff --git a/tests/ui/attributes/attr-mix-new.stderr b/tests/ui/attributes/attr-mix-new.stderr index 628d93ff534e4..782c0f5d17dd7 100644 --- a/tests/ui/attributes/attr-mix-new.stderr +++ b/tests/ui/attributes/attr-mix-new.stderr @@ -4,6 +4,7 @@ warning: the `#![feature]` attribute can only be used at the crate root LL | #![feature(globs)] | ^^^^^^^^^^^^^^^^^^ | + = help: the crate root is at `$DIR/attr-mix-new.rs` = note: requested on the command line with `-W unused-attributes` warning: 1 warning emitted diff --git a/tests/ui/attributes/crate-only-as-outer.stderr b/tests/ui/attributes/crate-only-as-outer.stderr index c1787a73d2907..e1692a7a1aae1 100644 --- a/tests/ui/attributes/crate-only-as-outer.stderr +++ b/tests/ui/attributes/crate-only-as-outer.stderr @@ -21,6 +21,8 @@ error: the `#![crate_name]` attribute can only be used at the crate root | LL | #![crate_name = "iwi"] | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/crate-only-as-outer.rs` error: aborting due to 2 previous errors diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs index 8f3e98cfc2a7c..96c9087dc07ea 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs @@ -503,6 +503,7 @@ mod no_std { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_std] } //~^ WARN the `#![no_std]` attribute can only be used at the crate root +//~| HELP the crate root is at #[no_std] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -764,6 +765,7 @@ mod windows_subsystem { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![windows_subsystem="windows"] } //~^ WARN the `#![windows_subsystem]` attribute can only be used at the crate root + //~| HELP the crate root is at #[windows_subsystem = "windows"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -790,6 +792,7 @@ mod crate_name { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![crate_name="0900"] } //~^ WARN the `#![crate_name]` attribute can only be used at the crate root +//~| HELP the crate root is at #[crate_name = "0900"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -814,6 +817,7 @@ mod crate_type { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![crate_type="0800"] } //~^ WARN the `#![crate_type]` attribute can only be used at the crate root +//~| HELP the crate root is at #[crate_type = "0800"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -838,6 +842,7 @@ mod feature { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![feature(x0600)] } //~^ WARN the `#![feature]` attribute can only be used at the crate root + //~| HELP the crate root is at #[feature(x0600)] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -863,6 +868,7 @@ mod no_main_1 { //~^ NOTE: this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_main] } //~^ WARN the `#![no_main]` attribute can only be used at the crate root + //~| HELP the crate root is at #[no_main] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -887,6 +893,7 @@ mod no_builtins { //~^ NOTE: this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_builtins] } //~^ WARN the `#![no_builtins]` attribute can only be used at the crate root + //~| HELP the crate root is at #[no_builtins] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -911,6 +918,7 @@ mod recursion_limit { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![recursion_limit="0200"] } //~^ WARN the `#![recursion_limit]` attribute can only be used at the crate root +//~| HELP the crate root is at #[recursion_limit="0200"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -935,6 +943,7 @@ mod type_length_limit { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![type_length_limit="0100"] } //~^ WARN the `#![type_length_limit]` attribute can only be used at the crate root +//~| HELP the crate root is at #[type_length_limit="0100"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr index f6ed182b17ef1..9e9d1622debd3 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr @@ -187,7 +187,7 @@ LL | #[deny(x5100)] impl S { } | ^^^^^ warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:685:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:686:1 | LL | #[link(name = "x")] | ^^^^^^^^^^^^^^^^^^^ @@ -224,7 +224,7 @@ LL | #![feature(rust1)] = note: `#[warn(stable_features)]` on by default warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:691:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:692:17 | LL | mod inner { #![link(name = "x")] } | ------------^^^^^^^^^^^^^^^^^^^^-- not an `extern` block @@ -232,7 +232,7 @@ LL | mod inner { #![link(name = "x")] } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:696:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:697:5 | LL | #[link(name = "x")] fn f() { } | ^^^^^^^^^^^^^^^^^^^ ---------- not an `extern` block @@ -240,7 +240,7 @@ LL | #[link(name = "x")] fn f() { } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:701:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:702:5 | LL | #[link(name = "x")] struct S; | ^^^^^^^^^^^^^^^^^^^ --------- not an `extern` block @@ -248,7 +248,7 @@ LL | #[link(name = "x")] struct S; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:706:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:707:5 | LL | #[link(name = "x")] type T = S; | ^^^^^^^^^^^^^^^^^^^ ----------- not an `extern` block @@ -256,7 +256,7 @@ LL | #[link(name = "x")] type T = S; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:711:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:712:5 | LL | #[link(name = "x")] impl S { } | ^^^^^^^^^^^^^^^^^^^ ---------- not an `extern` block @@ -264,7 +264,7 @@ LL | #[link(name = "x")] impl S { } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:716:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:717:5 | LL | #[link(name = "x")] extern "Rust" {} | ^^^^^^^^^^^^^^^^^^^ @@ -706,57 +706,59 @@ warning: the `#![no_std]` attribute can only be used at the crate root | LL | mod inner { #![no_std] } | ^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:507:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:508:5 | LL | #[no_std] fn f() { } | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:507:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:508:15 | LL | #[no_std] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:511:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:512:5 | LL | #[no_std] struct S; | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:511:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:512:15 | LL | #[no_std] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:515:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:516:5 | LL | #[no_std] type T = S; | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:515:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:516:15 | LL | #[no_std] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:519:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:520:5 | LL | #[no_std] impl S { } | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:519:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:520:15 | LL | #[no_std] impl S { } | ^^^^^^^^^^ warning: `#[cold]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:541:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:542:1 | LL | #[cold] | ^^^^^^^ @@ -765,7 +767,7 @@ LL | #[cold] = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:548:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:549:17 | LL | mod inner { #![cold] } | ^^^^^^^^ @@ -774,7 +776,7 @@ LL | mod inner { #![cold] } = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:556:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:557:5 | LL | #[cold] struct S; | ^^^^^^^ @@ -783,7 +785,7 @@ LL | #[cold] struct S; = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:562:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:563:5 | LL | #[cold] type T = S; | ^^^^^^^ @@ -792,7 +794,7 @@ LL | #[cold] type T = S; = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:568:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:569:5 | LL | #[cold] impl S { } | ^^^^^^^ @@ -801,7 +803,7 @@ LL | #[cold] impl S { } = help: `#[cold]` can only be applied to functions warning: `#[link_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:575:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:576:1 | LL | #[link_name = "1900"] | ^^^^^^^^^^^^^^^^^^^^^ @@ -810,7 +812,7 @@ LL | #[link_name = "1900"] = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on foreign modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:581:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:582:5 | LL | #[link_name = "1900"] | ^^^^^^^^^^^^^^^^^^^^^ @@ -819,7 +821,7 @@ LL | #[link_name = "1900"] = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:588:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:589:17 | LL | mod inner { #![link_name="1900"] } | ^^^^^^^^^^^^^^^^^^^^ @@ -828,7 +830,7 @@ LL | mod inner { #![link_name="1900"] } = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on functions - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:594:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:595:5 | LL | #[link_name = "1900"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^ @@ -837,7 +839,7 @@ LL | #[link_name = "1900"] fn f() { } = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:600:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:601:5 | LL | #[link_name = "1900"] struct S; | ^^^^^^^^^^^^^^^^^^^^^ @@ -846,7 +848,7 @@ LL | #[link_name = "1900"] struct S; = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:606:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:607:5 | LL | #[link_name = "1900"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^ @@ -855,7 +857,7 @@ LL | #[link_name = "1900"] type T = S; = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:612:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:613:5 | LL | #[link_name = "1900"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^ @@ -864,7 +866,7 @@ LL | #[link_name = "1900"] impl S { } = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_section]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:619:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:620:1 | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -873,7 +875,7 @@ LL | #[link_section = ",1800"] = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:625:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:626:17 | LL | mod inner { #![link_section=",1800"] } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -882,7 +884,7 @@ LL | mod inner { #![link_section=",1800"] } = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:633:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:634:5 | LL | #[link_section = ",1800"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -891,7 +893,7 @@ LL | #[link_section = ",1800"] struct S; = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:639:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:640:5 | LL | #[link_section = ",1800"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -900,7 +902,7 @@ LL | #[link_section = ",1800"] type T = S; = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:645:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:646:5 | LL | #[link_section = ",1800"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -909,7 +911,7 @@ LL | #[link_section = ",1800"] impl S { } = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on traits - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:651:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:652:5 | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -918,7 +920,7 @@ LL | #[link_section = ",1800"] = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on required trait methods - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:657:9 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:658:9 | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -927,7 +929,7 @@ LL | #[link_section = ",1800"] = help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks warning: `#[must_use]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:736:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:737:1 | LL | #[must_use] | ^^^^^^^^^^^ @@ -936,7 +938,7 @@ LL | #[must_use] = help: `#[must_use]` can be applied to data types, functions, and traits warning: `#[must_use]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:741:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:742:17 | LL | mod inner { #![must_use] } | ^^^^^^^^^^^^ @@ -945,7 +947,7 @@ LL | mod inner { #![must_use] } = help: `#[must_use]` can be applied to data types, functions, and traits warning: `#[must_use]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:750:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:751:5 | LL | #[must_use] type T = S; | ^^^^^^^^^^^ @@ -954,7 +956,7 @@ LL | #[must_use] type T = S; = help: `#[must_use]` can be applied to data types, functions, and traits warning: `#[must_use]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:755:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:756:5 | LL | #[must_use] impl S { } | ^^^^^^^^^^^ @@ -963,13 +965,13 @@ LL | #[must_use] impl S { } = help: `#[must_use]` can be applied to data types, functions, and traits warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:761:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:762:1 | LL | #[windows_subsystem = "windows"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:763:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:764:1 | LL | / mod windows_subsystem { LL | | @@ -979,67 +981,69 @@ LL | | } | |_^ warning: the `#![windows_subsystem]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:765:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:766:17 | LL | mod inner { #![windows_subsystem="windows"] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:768:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:770:5 | LL | #[windows_subsystem = "windows"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:768:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:770:38 | LL | #[windows_subsystem = "windows"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:772:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:774:5 | LL | #[windows_subsystem = "windows"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:772:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:774:38 | LL | #[windows_subsystem = "windows"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:776:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:778:5 | LL | #[windows_subsystem = "windows"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:776:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:778:38 | LL | #[windows_subsystem = "windows"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:780:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:782:5 | LL | #[windows_subsystem = "windows"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:780:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:782:38 | LL | #[windows_subsystem = "windows"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:787:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:789:1 | LL | #[crate_name = "0900"] | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:789:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:791:1 | LL | / mod crate_name { LL | | @@ -1049,67 +1053,69 @@ LL | | } | |_^ warning: the `#![crate_name]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:791:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:793:17 | LL | mod inner { #![crate_name="0900"] } | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:794:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:797:5 | LL | #[crate_name = "0900"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:794:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:797:28 | LL | #[crate_name = "0900"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:798:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:801:5 | LL | #[crate_name = "0900"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:798:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:801:28 | LL | #[crate_name = "0900"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:802:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:805:5 | LL | #[crate_name = "0900"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:802:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:805:28 | LL | #[crate_name = "0900"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:806:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:809:5 | LL | #[crate_name = "0900"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:806:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:809:28 | LL | #[crate_name = "0900"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:811:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:814:1 | LL | #[crate_type = "0800"] | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:813:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:816:1 | LL | / mod crate_type { LL | | @@ -1119,67 +1125,69 @@ LL | | } | |_^ warning: the `#![crate_type]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:815:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:17 | LL | mod inner { #![crate_type="0800"] } | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:5 | LL | #[crate_type = "0800"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:28 | LL | #[crate_type = "0800"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:5 | LL | #[crate_type = "0800"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:28 | LL | #[crate_type = "0800"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:5 | LL | #[crate_type = "0800"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:28 | LL | #[crate_type = "0800"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:834:5 | LL | #[crate_type = "0800"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:834:28 | LL | #[crate_type = "0800"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:835:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:839:1 | LL | #[feature(x0600)] | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:837:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:841:1 | LL | / mod feature { LL | | @@ -1189,67 +1197,69 @@ LL | | } | |_^ warning: the `#![feature]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:839:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:843:17 | LL | mod inner { #![feature(x0600)] } | ^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:842:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:847:5 | LL | #[feature(x0600)] fn f() { } | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:842:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:847:23 | LL | #[feature(x0600)] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:846:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:851:5 | LL | #[feature(x0600)] struct S; | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:846:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:851:23 | LL | #[feature(x0600)] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:850:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:855:5 | LL | #[feature(x0600)] type T = S; | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:850:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:855:23 | LL | #[feature(x0600)] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:854:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:859:5 | LL | #[feature(x0600)] impl S { } | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:854:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:859:23 | LL | #[feature(x0600)] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:860:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:865:1 | LL | #[no_main] | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:862:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:867:1 | LL | / mod no_main_1 { LL | | @@ -1259,67 +1269,69 @@ LL | | } | |_^ warning: the `#![no_main]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:864:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:869:17 | LL | mod inner { #![no_main] } | ^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:867:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:873:5 | LL | #[no_main] fn f() { } | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:867:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:873:16 | LL | #[no_main] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:871:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:877:5 | LL | #[no_main] struct S; | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:871:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:877:16 | LL | #[no_main] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:875:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:881:5 | LL | #[no_main] type T = S; | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:875:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:881:16 | LL | #[no_main] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:879:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:885:5 | LL | #[no_main] impl S { } | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:879:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:885:16 | LL | #[no_main] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:884:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:890:1 | LL | #[no_builtins] | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:886:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:892:1 | LL | / mod no_builtins { LL | | @@ -1329,67 +1341,69 @@ LL | | } | |_^ warning: the `#![no_builtins]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:888:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:894:17 | LL | mod inner { #![no_builtins] } | ^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:891:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:898:5 | LL | #[no_builtins] fn f() { } | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:891:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:898:20 | LL | #[no_builtins] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:895:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:902:5 | LL | #[no_builtins] struct S; | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:895:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:902:20 | LL | #[no_builtins] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:899:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:906:5 | LL | #[no_builtins] type T = S; | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:899:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:906:20 | LL | #[no_builtins] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:903:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:910:5 | LL | #[no_builtins] impl S { } | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:903:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:910:20 | LL | #[no_builtins] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:908:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:915:1 | LL | #[recursion_limit="0200"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:910:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:917:1 | LL | / mod recursion_limit { LL | | @@ -1399,67 +1413,69 @@ LL | | } | |_^ warning: the `#![recursion_limit]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:912:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:919:17 | LL | mod inner { #![recursion_limit="0200"] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:915:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:5 | LL | #[recursion_limit="0200"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:915:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:31 | LL | #[recursion_limit="0200"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:919:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:5 | LL | #[recursion_limit="0200"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:919:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:31 | LL | #[recursion_limit="0200"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:931:5 | LL | #[recursion_limit="0200"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:931:31 | LL | #[recursion_limit="0200"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:935:5 | LL | #[recursion_limit="0200"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:935:31 | LL | #[recursion_limit="0200"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:932:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:940:1 | LL | #[type_length_limit="0100"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:934:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:942:1 | LL | / mod type_length_limit { LL | | @@ -1469,55 +1485,57 @@ LL | | } | |_^ warning: the `#![type_length_limit]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:936:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:944:17 | LL | mod inner { #![type_length_limit="0100"] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:939:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:948:5 | LL | #[type_length_limit="0100"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:939:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:948:33 | LL | #[type_length_limit="0100"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:943:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:952:5 | LL | #[type_length_limit="0100"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:943:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:952:33 | LL | #[type_length_limit="0100"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:947:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:956:5 | LL | #[type_length_limit="0100"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:947:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:956:33 | LL | #[type_length_limit="0100"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:951:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:960:5 | LL | #[type_length_limit="0100"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:951:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:960:33 | LL | #[type_length_limit="0100"] impl S { } | ^^^^^^^^^^ diff --git a/tests/ui/lint/lint-misplaced-attr.stderr b/tests/ui/lint/lint-misplaced-attr.stderr index d46bbc44c1b2b..ca4f28c20a684 100644 --- a/tests/ui/lint/lint-misplaced-attr.stderr +++ b/tests/ui/lint/lint-misplaced-attr.stderr @@ -4,6 +4,7 @@ error: the `#![crate_type]` attribute can only be used at the crate root LL | #![crate_type = "bin"] | ^^^^^^^^^^^^^^^^^^^^^^ | + = help: the crate root is at `$DIR/lint-misplaced-attr.rs` note: the lint level is defined here --> $DIR/lint-misplaced-attr.rs:4:9 | From 1e62f5a348aed88c9aa325b3814e3eda59699cf9 Mon Sep 17 00:00:00 2001 From: Dnreikronos Date: Wed, 27 May 2026 14:43:25 -0300 Subject: [PATCH 11/19] Suppress crate-root help when attribute is in same file Skip the "the crate root is at ..." help message when the misplaced crate-level attribute is already in the crate root file, since it adds no useful information in that case. Add a cross-file test to verify the help still appears when the attribute is in a different file from the crate root. --- .../rustc_attr_parsing/src/target_checking.rs | 8 +- tests/ui/attributes/attr-mix-new.stderr | 1 - .../ui/attributes/crate-only-as-outer.stderr | 2 - .../crate-root-path-in-different-file.rs | 7 + .../crate-root-path-in-different-file.stderr | 15 + .../submod.rs | 1 + .../issue-43106-gating-of-builtin-attrs.rs | 17 +- ...issue-43106-gating-of-builtin-attrs.stderr | 270 ++++++++---------- tests/ui/lint/lint-misplaced-attr.stderr | 1 - 9 files changed, 160 insertions(+), 162 deletions(-) create mode 100644 tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs create mode 100644 tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr create mode 100644 tests/ui/attributes/crate-root-path-in-different-file/submod.rs diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 496c386bf6303..fe4d72b83282b 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -5,7 +5,7 @@ use rustc_errors::{DiagArgValue, Diagnostic, MultiSpan, StashKey}; use rustc_feature::Features; use rustc_hir::attrs::AttributeKind; use rustc_hir::{AttrItem, Attribute, MethodKind, Target}; -use rustc_span::{BytePos, RemapPathScopeComponents, Span, Symbol, sym}; +use rustc_span::{BytePos, FileName, RemapPathScopeComponents, Span, Symbol, sym}; use crate::AttributeParser; use crate::context::AcceptContext; @@ -189,6 +189,12 @@ impl<'sess> AttributeParser<'sess> { let (show_crate_root_help, crate_root_path) = is_used_as_inner .then(|| cx.cx.sess.local_crate_source_file()) .flatten() + .filter(|src| { + !matches!( + cx.cx.sess.source_map().span_to_filename(attr_span), + FileName::Real(ref name) if name == src + ) + }) .map(|src| { (true, src.path(RemapPathScopeComponents::DIAGNOSTICS).display().to_string()) }) diff --git a/tests/ui/attributes/attr-mix-new.stderr b/tests/ui/attributes/attr-mix-new.stderr index 782c0f5d17dd7..628d93ff534e4 100644 --- a/tests/ui/attributes/attr-mix-new.stderr +++ b/tests/ui/attributes/attr-mix-new.stderr @@ -4,7 +4,6 @@ warning: the `#![feature]` attribute can only be used at the crate root LL | #![feature(globs)] | ^^^^^^^^^^^^^^^^^^ | - = help: the crate root is at `$DIR/attr-mix-new.rs` = note: requested on the command line with `-W unused-attributes` warning: 1 warning emitted diff --git a/tests/ui/attributes/crate-only-as-outer.stderr b/tests/ui/attributes/crate-only-as-outer.stderr index e1692a7a1aae1..c1787a73d2907 100644 --- a/tests/ui/attributes/crate-only-as-outer.stderr +++ b/tests/ui/attributes/crate-only-as-outer.stderr @@ -21,8 +21,6 @@ error: the `#![crate_name]` attribute can only be used at the crate root | LL | #![crate_name = "iwi"] | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/crate-only-as-outer.rs` error: aborting due to 2 previous errors diff --git a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs b/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs new file mode 100644 index 0000000000000..1b054724bfd31 --- /dev/null +++ b/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs @@ -0,0 +1,7 @@ +#![deny(unused_attributes)] + +mod submod; + +fn main() {} + +//~? ERROR the `#![crate_name]` attribute can only be used at the crate root diff --git a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr b/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr new file mode 100644 index 0000000000000..807d73637e7f8 --- /dev/null +++ b/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr @@ -0,0 +1,15 @@ +error: the `#![crate_name]` attribute can only be used at the crate root + --> $DIR/submod.rs:1:1 + | +LL | #![crate_name = "bar"] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: the crate root is at `$DIR/crate-root-path-in-different-file.rs` +note: the lint level is defined here + --> $DIR/crate-root-path-in-different-file.rs:1:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/crate-root-path-in-different-file/submod.rs b/tests/ui/attributes/crate-root-path-in-different-file/submod.rs new file mode 100644 index 0000000000000..8c030e6dc3731 --- /dev/null +++ b/tests/ui/attributes/crate-root-path-in-different-file/submod.rs @@ -0,0 +1 @@ +#![crate_name = "bar"] diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs index 96c9087dc07ea..53de6e623329e 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs @@ -503,7 +503,6 @@ mod no_std { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_std] } //~^ WARN the `#![no_std]` attribute can only be used at the crate root -//~| HELP the crate root is at #[no_std] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -765,8 +764,7 @@ mod windows_subsystem { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![windows_subsystem="windows"] } //~^ WARN the `#![windows_subsystem]` attribute can only be used at the crate root - //~| HELP the crate root is at - + #[windows_subsystem = "windows"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -792,7 +790,6 @@ mod crate_name { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![crate_name="0900"] } //~^ WARN the `#![crate_name]` attribute can only be used at the crate root -//~| HELP the crate root is at #[crate_name = "0900"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -817,7 +814,6 @@ mod crate_type { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![crate_type="0800"] } //~^ WARN the `#![crate_type]` attribute can only be used at the crate root -//~| HELP the crate root is at #[crate_type = "0800"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -842,8 +838,7 @@ mod feature { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![feature(x0600)] } //~^ WARN the `#![feature]` attribute can only be used at the crate root - //~| HELP the crate root is at - + #[feature(x0600)] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -868,8 +863,7 @@ mod no_main_1 { //~^ NOTE: this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_main] } //~^ WARN the `#![no_main]` attribute can only be used at the crate root - //~| HELP the crate root is at - + #[no_main] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -893,8 +887,7 @@ mod no_builtins { //~^ NOTE: this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_builtins] } //~^ WARN the `#![no_builtins]` attribute can only be used at the crate root - //~| HELP the crate root is at - + #[no_builtins] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -918,7 +911,6 @@ mod recursion_limit { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![recursion_limit="0200"] } //~^ WARN the `#![recursion_limit]` attribute can only be used at the crate root -//~| HELP the crate root is at #[recursion_limit="0200"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute @@ -943,7 +935,6 @@ mod type_length_limit { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![type_length_limit="0100"] } //~^ WARN the `#![type_length_limit]` attribute can only be used at the crate root -//~| HELP the crate root is at #[type_length_limit="0100"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr index 9e9d1622debd3..f6ed182b17ef1 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr @@ -187,7 +187,7 @@ LL | #[deny(x5100)] impl S { } | ^^^^^ warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:686:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:685:1 | LL | #[link(name = "x")] | ^^^^^^^^^^^^^^^^^^^ @@ -224,7 +224,7 @@ LL | #![feature(rust1)] = note: `#[warn(stable_features)]` on by default warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:692:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:691:17 | LL | mod inner { #![link(name = "x")] } | ------------^^^^^^^^^^^^^^^^^^^^-- not an `extern` block @@ -232,7 +232,7 @@ LL | mod inner { #![link(name = "x")] } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:697:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:696:5 | LL | #[link(name = "x")] fn f() { } | ^^^^^^^^^^^^^^^^^^^ ---------- not an `extern` block @@ -240,7 +240,7 @@ LL | #[link(name = "x")] fn f() { } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:702:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:701:5 | LL | #[link(name = "x")] struct S; | ^^^^^^^^^^^^^^^^^^^ --------- not an `extern` block @@ -248,7 +248,7 @@ LL | #[link(name = "x")] struct S; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:707:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:706:5 | LL | #[link(name = "x")] type T = S; | ^^^^^^^^^^^^^^^^^^^ ----------- not an `extern` block @@ -256,7 +256,7 @@ LL | #[link(name = "x")] type T = S; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:712:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:711:5 | LL | #[link(name = "x")] impl S { } | ^^^^^^^^^^^^^^^^^^^ ---------- not an `extern` block @@ -264,7 +264,7 @@ LL | #[link(name = "x")] impl S { } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:717:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:716:5 | LL | #[link(name = "x")] extern "Rust" {} | ^^^^^^^^^^^^^^^^^^^ @@ -706,59 +706,57 @@ warning: the `#![no_std]` attribute can only be used at the crate root | LL | mod inner { #![no_std] } | ^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:508:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:507:5 | LL | #[no_std] fn f() { } | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:508:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:507:15 | LL | #[no_std] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:512:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:511:5 | LL | #[no_std] struct S; | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:512:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:511:15 | LL | #[no_std] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:516:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:515:5 | LL | #[no_std] type T = S; | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:516:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:515:15 | LL | #[no_std] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:520:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:519:5 | LL | #[no_std] impl S { } | ^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:520:15 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:519:15 | LL | #[no_std] impl S { } | ^^^^^^^^^^ warning: `#[cold]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:542:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:541:1 | LL | #[cold] | ^^^^^^^ @@ -767,7 +765,7 @@ LL | #[cold] = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:549:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:548:17 | LL | mod inner { #![cold] } | ^^^^^^^^ @@ -776,7 +774,7 @@ LL | mod inner { #![cold] } = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:557:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:556:5 | LL | #[cold] struct S; | ^^^^^^^ @@ -785,7 +783,7 @@ LL | #[cold] struct S; = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:563:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:562:5 | LL | #[cold] type T = S; | ^^^^^^^ @@ -794,7 +792,7 @@ LL | #[cold] type T = S; = help: `#[cold]` can only be applied to functions warning: `#[cold]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:569:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:568:5 | LL | #[cold] impl S { } | ^^^^^^^ @@ -803,7 +801,7 @@ LL | #[cold] impl S { } = help: `#[cold]` can only be applied to functions warning: `#[link_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:576:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:575:1 | LL | #[link_name = "1900"] | ^^^^^^^^^^^^^^^^^^^^^ @@ -812,7 +810,7 @@ LL | #[link_name = "1900"] = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on foreign modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:582:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:581:5 | LL | #[link_name = "1900"] | ^^^^^^^^^^^^^^^^^^^^^ @@ -821,7 +819,7 @@ LL | #[link_name = "1900"] = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:589:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:588:17 | LL | mod inner { #![link_name="1900"] } | ^^^^^^^^^^^^^^^^^^^^ @@ -830,7 +828,7 @@ LL | mod inner { #![link_name="1900"] } = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on functions - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:595:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:594:5 | LL | #[link_name = "1900"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^ @@ -839,7 +837,7 @@ LL | #[link_name = "1900"] fn f() { } = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:601:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:600:5 | LL | #[link_name = "1900"] struct S; | ^^^^^^^^^^^^^^^^^^^^^ @@ -848,7 +846,7 @@ LL | #[link_name = "1900"] struct S; = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:607:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:606:5 | LL | #[link_name = "1900"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^ @@ -857,7 +855,7 @@ LL | #[link_name = "1900"] type T = S; = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_name]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:613:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:612:5 | LL | #[link_name = "1900"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^ @@ -866,7 +864,7 @@ LL | #[link_name = "1900"] impl S { } = help: `#[link_name]` can be applied to foreign functions and foreign statics warning: `#[link_section]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:620:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:619:1 | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -875,7 +873,7 @@ LL | #[link_section = ",1800"] = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:626:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:625:17 | LL | mod inner { #![link_section=",1800"] } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -884,7 +882,7 @@ LL | mod inner { #![link_section=",1800"] } = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:634:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:633:5 | LL | #[link_section = ",1800"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -893,7 +891,7 @@ LL | #[link_section = ",1800"] struct S; = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:640:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:639:5 | LL | #[link_section = ",1800"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -902,7 +900,7 @@ LL | #[link_section = ",1800"] type T = S; = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:646:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:645:5 | LL | #[link_section = ",1800"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -911,7 +909,7 @@ LL | #[link_section = ",1800"] impl S { } = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on traits - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:652:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:651:5 | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -920,7 +918,7 @@ LL | #[link_section = ",1800"] = help: `#[link_section]` can be applied to functions and statics warning: `#[link_section]` attribute cannot be used on required trait methods - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:658:9 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:657:9 | LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -929,7 +927,7 @@ LL | #[link_section = ",1800"] = help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks warning: `#[must_use]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:737:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:736:1 | LL | #[must_use] | ^^^^^^^^^^^ @@ -938,7 +936,7 @@ LL | #[must_use] = help: `#[must_use]` can be applied to data types, functions, and traits warning: `#[must_use]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:742:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:741:17 | LL | mod inner { #![must_use] } | ^^^^^^^^^^^^ @@ -947,7 +945,7 @@ LL | mod inner { #![must_use] } = help: `#[must_use]` can be applied to data types, functions, and traits warning: `#[must_use]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:751:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:750:5 | LL | #[must_use] type T = S; | ^^^^^^^^^^^ @@ -956,7 +954,7 @@ LL | #[must_use] type T = S; = help: `#[must_use]` can be applied to data types, functions, and traits warning: `#[must_use]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:756:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:755:5 | LL | #[must_use] impl S { } | ^^^^^^^^^^^ @@ -965,13 +963,13 @@ LL | #[must_use] impl S { } = help: `#[must_use]` can be applied to data types, functions, and traits warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:762:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:761:1 | LL | #[windows_subsystem = "windows"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:764:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:763:1 | LL | / mod windows_subsystem { LL | | @@ -981,69 +979,67 @@ LL | | } | |_^ warning: the `#![windows_subsystem]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:766:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:765:17 | LL | mod inner { #![windows_subsystem="windows"] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:770:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:768:5 | LL | #[windows_subsystem = "windows"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:770:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:768:38 | LL | #[windows_subsystem = "windows"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:774:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:772:5 | LL | #[windows_subsystem = "windows"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:774:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:772:38 | LL | #[windows_subsystem = "windows"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:778:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:776:5 | LL | #[windows_subsystem = "windows"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:778:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:776:38 | LL | #[windows_subsystem = "windows"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![windows_subsystem]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:782:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:780:5 | LL | #[windows_subsystem = "windows"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:782:38 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:780:38 | LL | #[windows_subsystem = "windows"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:789:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:787:1 | LL | #[crate_name = "0900"] | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:791:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:789:1 | LL | / mod crate_name { LL | | @@ -1053,69 +1049,67 @@ LL | | } | |_^ warning: the `#![crate_name]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:793:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:791:17 | LL | mod inner { #![crate_name="0900"] } | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:797:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:794:5 | LL | #[crate_name = "0900"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:797:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:794:28 | LL | #[crate_name = "0900"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:801:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:798:5 | LL | #[crate_name = "0900"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:801:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:798:28 | LL | #[crate_name = "0900"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:805:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:802:5 | LL | #[crate_name = "0900"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:805:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:802:28 | LL | #[crate_name = "0900"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:809:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:806:5 | LL | #[crate_name = "0900"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:809:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:806:28 | LL | #[crate_name = "0900"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:814:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:811:1 | LL | #[crate_type = "0800"] | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:816:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:813:1 | LL | / mod crate_type { LL | | @@ -1125,69 +1119,67 @@ LL | | } | |_^ warning: the `#![crate_type]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:815:17 | LL | mod inner { #![crate_type="0800"] } | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:5 | LL | #[crate_type = "0800"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:28 | LL | #[crate_type = "0800"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:5 | LL | #[crate_type = "0800"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:28 | LL | #[crate_type = "0800"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:5 | LL | #[crate_type = "0800"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:28 | LL | #[crate_type = "0800"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_type]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:834:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:5 | LL | #[crate_type = "0800"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:834:28 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:28 | LL | #[crate_type = "0800"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:839:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:835:1 | LL | #[feature(x0600)] | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:841:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:837:1 | LL | / mod feature { LL | | @@ -1197,69 +1189,67 @@ LL | | } | |_^ warning: the `#![feature]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:843:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:839:17 | LL | mod inner { #![feature(x0600)] } | ^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:847:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:842:5 | LL | #[feature(x0600)] fn f() { } | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:847:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:842:23 | LL | #[feature(x0600)] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:851:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:846:5 | LL | #[feature(x0600)] struct S; | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:851:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:846:23 | LL | #[feature(x0600)] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:855:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:850:5 | LL | #[feature(x0600)] type T = S; | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:855:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:850:23 | LL | #[feature(x0600)] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![feature]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:859:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:854:5 | LL | #[feature(x0600)] impl S { } | ^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:859:23 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:854:23 | LL | #[feature(x0600)] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:865:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:860:1 | LL | #[no_main] | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:867:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:862:1 | LL | / mod no_main_1 { LL | | @@ -1269,69 +1259,67 @@ LL | | } | |_^ warning: the `#![no_main]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:869:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:864:17 | LL | mod inner { #![no_main] } | ^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:873:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:867:5 | LL | #[no_main] fn f() { } | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:873:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:867:16 | LL | #[no_main] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:877:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:871:5 | LL | #[no_main] struct S; | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:877:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:871:16 | LL | #[no_main] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:881:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:875:5 | LL | #[no_main] type T = S; | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:881:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:875:16 | LL | #[no_main] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_main]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:885:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:879:5 | LL | #[no_main] impl S { } | ^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:885:16 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:879:16 | LL | #[no_main] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:890:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:884:1 | LL | #[no_builtins] | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:892:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:886:1 | LL | / mod no_builtins { LL | | @@ -1341,69 +1329,67 @@ LL | | } | |_^ warning: the `#![no_builtins]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:894:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:888:17 | LL | mod inner { #![no_builtins] } | ^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:898:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:891:5 | LL | #[no_builtins] fn f() { } | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:898:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:891:20 | LL | #[no_builtins] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:902:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:895:5 | LL | #[no_builtins] struct S; | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:902:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:895:20 | LL | #[no_builtins] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:906:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:899:5 | LL | #[no_builtins] type T = S; | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:906:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:899:20 | LL | #[no_builtins] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:910:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:903:5 | LL | #[no_builtins] impl S { } | ^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:910:20 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:903:20 | LL | #[no_builtins] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:915:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:908:1 | LL | #[recursion_limit="0200"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:917:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:910:1 | LL | / mod recursion_limit { LL | | @@ -1413,69 +1399,67 @@ LL | | } | |_^ warning: the `#![recursion_limit]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:919:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:912:17 | LL | mod inner { #![recursion_limit="0200"] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:915:5 | LL | #[recursion_limit="0200"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:915:31 | LL | #[recursion_limit="0200"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:919:5 | LL | #[recursion_limit="0200"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:919:31 | LL | #[recursion_limit="0200"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:931:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:5 | LL | #[recursion_limit="0200"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:931:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:923:31 | LL | #[recursion_limit="0200"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:935:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:5 | LL | #[recursion_limit="0200"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:935:31 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:927:31 | LL | #[recursion_limit="0200"] impl S { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:940:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:932:1 | LL | #[type_length_limit="0100"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this module - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:942:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:934:1 | LL | / mod type_length_limit { LL | | @@ -1485,57 +1469,55 @@ LL | | } | |_^ warning: the `#![type_length_limit]` attribute can only be used at the crate root - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:944:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:936:17 | LL | mod inner { #![type_length_limit="0100"] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: the crate root is at `$DIR/issue-43106-gating-of-builtin-attrs.rs` warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:948:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:939:5 | LL | #[type_length_limit="0100"] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:948:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:939:33 | LL | #[type_length_limit="0100"] fn f() { } | ^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:952:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:943:5 | LL | #[type_length_limit="0100"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this struct - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:952:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:943:33 | LL | #[type_length_limit="0100"] struct S; | ^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:956:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:947:5 | LL | #[type_length_limit="0100"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this type alias - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:956:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:947:33 | LL | #[type_length_limit="0100"] type T = S; | ^^^^^^^^^^^ warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![type_length_limit]` - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:960:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:951:5 | LL | #[type_length_limit="0100"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this implementation block - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:960:33 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:951:33 | LL | #[type_length_limit="0100"] impl S { } | ^^^^^^^^^^ diff --git a/tests/ui/lint/lint-misplaced-attr.stderr b/tests/ui/lint/lint-misplaced-attr.stderr index ca4f28c20a684..d46bbc44c1b2b 100644 --- a/tests/ui/lint/lint-misplaced-attr.stderr +++ b/tests/ui/lint/lint-misplaced-attr.stderr @@ -4,7 +4,6 @@ error: the `#![crate_type]` attribute can only be used at the crate root LL | #![crate_type = "bin"] | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: the crate root is at `$DIR/lint-misplaced-attr.rs` note: the lint level is defined here --> $DIR/lint-misplaced-attr.rs:4:9 | From bb92226b4b6a636aa5287930adf7cd1c5e548232 Mon Sep 17 00:00:00 2001 From: Dnreikronos Date: Wed, 27 May 2026 14:53:53 -0300 Subject: [PATCH 12/19] Remove trailing whitespace left by deleted annotations --- .../feature-gates/issue-43106-gating-of-builtin-attrs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs index 53de6e623329e..8f3e98cfc2a7c 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs @@ -764,7 +764,7 @@ mod windows_subsystem { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![windows_subsystem="windows"] } //~^ WARN the `#![windows_subsystem]` attribute can only be used at the crate root - + #[windows_subsystem = "windows"] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -838,7 +838,7 @@ mod feature { //~^ NOTE this attribute does not have an `!`, which means it is applied to this module mod inner { #![feature(x0600)] } //~^ WARN the `#![feature]` attribute can only be used at the crate root - + #[feature(x0600)] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -863,7 +863,7 @@ mod no_main_1 { //~^ NOTE: this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_main] } //~^ WARN the `#![no_main]` attribute can only be used at the crate root - + #[no_main] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function @@ -887,7 +887,7 @@ mod no_builtins { //~^ NOTE: this attribute does not have an `!`, which means it is applied to this module mod inner { #![no_builtins] } //~^ WARN the `#![no_builtins]` attribute can only be used at the crate root - + #[no_builtins] fn f() { } //~^ WARN crate-level attribute should be an inner attribute //~| NOTE this attribute does not have an `!`, which means it is applied to this function From 1fa9548cb98667232033d037fe43cdd52cbcc0c7 Mon Sep 17 00:00:00 2001 From: Aria Givens Date: Wed, 27 May 2026 12:20:46 -0400 Subject: [PATCH 13/19] Support quotation mark suggestion for attributes in apple tests --- tests/ui/darwin-objc/darwin-objc-bad-arg.stderr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/darwin-objc/darwin-objc-bad-arg.stderr b/tests/ui/darwin-objc/darwin-objc-bad-arg.stderr index 99eeb27e30c1b..f75f07945a165 100644 --- a/tests/ui/darwin-objc/darwin-objc-bad-arg.stderr +++ b/tests/ui/darwin-objc/darwin-objc-bad-arg.stderr @@ -2,13 +2,13 @@ error: attribute value must be a literal --> $DIR/darwin-objc-bad-arg.rs:12:18 | LL | objc::class!(s); - | ^ + | ^ help: try adding quotation marks: `"s"` error: attribute value must be a literal --> $DIR/darwin-objc-bad-arg.rs:15:18 | LL | objc::class!(NSObject); - | ^^^^^^^^ + | ^^^^^^^^ help: try adding quotation marks: `"NSObject"` error: `objc::class!` expected a string literal --> $DIR/darwin-objc-bad-arg.rs:18:18 @@ -26,13 +26,13 @@ error: attribute value must be a literal --> $DIR/darwin-objc-bad-arg.rs:25:21 | LL | objc::selector!(s); - | ^ + | ^ help: try adding quotation marks: `"s"` error: attribute value must be a literal --> $DIR/darwin-objc-bad-arg.rs:28:21 | LL | objc::selector!(alloc); - | ^^^^^ + | ^^^^^ help: try adding quotation marks: `"alloc"` error: `objc::selector!` expected a string literal --> $DIR/darwin-objc-bad-arg.rs:31:21 From 59debaf661a4980f7d00ddf88fa422a02b5f91fc Mon Sep 17 00:00:00 2001 From: Dnreikronos Date: Wed, 27 May 2026 16:57:06 -0300 Subject: [PATCH 14/19] Mark submod.rs as auxiliary so compiletest skips it --- .../crate-root-path-in-different-file.stderr | 2 +- tests/ui/attributes/crate-root-path-in-different-file/submod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr b/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr index 807d73637e7f8..c0c69a7bd57a8 100644 --- a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr +++ b/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr @@ -1,5 +1,5 @@ error: the `#![crate_name]` attribute can only be used at the crate root - --> $DIR/submod.rs:1:1 + --> $DIR/submod.rs:2:1 | LL | #![crate_name = "bar"] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/crate-root-path-in-different-file/submod.rs b/tests/ui/attributes/crate-root-path-in-different-file/submod.rs index 8c030e6dc3731..f3a36d031b484 100644 --- a/tests/ui/attributes/crate-root-path-in-different-file/submod.rs +++ b/tests/ui/attributes/crate-root-path-in-different-file/submod.rs @@ -1 +1,2 @@ +//@ ignore-auxiliary (used by `./crate-root-path-in-different-file.rs`) #![crate_name = "bar"] From b513e539c3df674885b9f5ae8844b60e1ced22d1 Mon Sep 17 00:00:00 2001 From: Asuna Date: Wed, 27 May 2026 22:25:09 +0000 Subject: [PATCH 15/19] `FieldId` wraps FRT `TypeId` instead of the actual field `TypeId` --- .../src/const_eval/machine.rs | 61 ++++++++++--------- .../rustc_hir_analysis/src/check/intrinsic.rs | 6 +- compiler/rustc_span/src/symbol.rs | 3 +- library/core/src/intrinsics/mod.rs | 19 +++++- library/core/src/mem/type_info.rs | 32 ++++++++-- 5 files changed, 82 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index f37c57c73de73..1dee2f34371e8 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -647,7 +647,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { ecx.write_scalar(Scalar::from_target_usize(fields_num as u64, ecx), dest)?; } - sym::type_id_field => { + sym::type_id_field_representing_type => { let ty = ecx.read_type_id(&args[0])?; let variant_idx = ecx.read_target_usize(&args[1])? as usize; let field_idx = ecx.read_target_usize(&args[2])? as usize; @@ -661,37 +661,28 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { }); } - let field_ty = match ty.kind() { - ty::Adt(adt_def, generics) => { + let fields_num = match ty.kind() { + ty::Adt(adt_def, _) => { let variant_def = &adt_def.variants()[VariantIdx::from_usize(variant_idx)]; - let fields_num = variant_def.fields.len(); - if field_idx >= fields_num { - throw_ub!(BoundsCheckFailed { - len: fields_num as u64, - index: field_idx as u64 - }); - } - let field_def = &variant_def.fields[FieldIdx::from_usize(field_idx)]; - field_def.ty(ecx.tcx.tcx, generics).skip_norm_wip() - } - ty::Tuple(fields) => { - let fields_num = fields.len(); - if field_idx >= fields_num { - throw_ub!(BoundsCheckFailed { - len: fields_num as u64, - index: field_idx as u64 - }); - } - fields[field_idx] - } - _ => { - // Other types have no fields, so any field index is out of bounds. - throw_ub!(BoundsCheckFailed { len: 0, index: field_idx as u64 }); + variant_def.fields.len() } + ty::Tuple(fields) => fields.len(), + _ => 0, // Other types have no fields }; + if field_idx >= fields_num { + throw_ub!(BoundsCheckFailed { + len: fields_num as u64, + index: field_idx as u64 + }); + } - let field_ty = ecx.tcx.erase_and_anonymize_regions(field_ty); - ecx.write_type_id(field_ty, dest)?; + let frt = Ty::new_field_representing_type( + *ecx.tcx, + ty, + VariantIdx::from_usize(variant_idx), + FieldIdx::from_usize(field_idx), + ); + ecx.write_type_id(frt, dest)?; } sym::type_id_variants => { @@ -721,6 +712,20 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { ecx.write_scalar(Scalar::from_target_usize(offset, ecx), dest)?; } + sym::field_representing_type_actual_type_id => { + let frt_ty = ecx.read_type_id(&args[0])?; + + let field_ty = if let ty::Adt(def, args) = frt_ty.kind() + && let Some(FieldInfo { ty, .. }) = + def.field_representing_type_info(ecx.tcx.tcx, args) + { + ecx.tcx.erase_and_anonymize_regions(ty) + } else { + span_bug!(ecx.cur_span(), "expected field representing type, got {frt_ty}") + }; + ecx.write_type_id(field_ty, dest)?; + } + _ => { // We haven't handled the intrinsic, let's see if we can use a fallback body. if ecx.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden { diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index b37aa4fac4e98..c1edbb4fc520d 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -114,6 +114,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi | sym::fadd_algebraic | sym::fdiv_algebraic | sym::field_offset + | sym::field_representing_type_actual_type_id | sym::floorf16 | sym::floorf32 | sym::floorf64 @@ -213,7 +214,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi | sym::truncf128 | sym::type_id | sym::type_id_eq - | sym::type_id_field + | sym::type_id_field_representing_type | sym::type_id_fields | sym::type_id_variants | sym::type_id_vtable @@ -322,7 +323,7 @@ pub(crate) fn check_intrinsic_type( sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)), sym::type_id => (1, 0, vec![], type_id_ty()), sym::type_id_eq => (0, 0, vec![type_id_ty(), type_id_ty()], tcx.types.bool), - sym::type_id_field => { + sym::type_id_field_representing_type => { (0, 0, vec![type_id_ty(), tcx.types.usize, tcx.types.usize], type_id_ty()) } sym::type_id_fields => (0, 0, vec![type_id_ty(), tcx.types.usize], tcx.types.usize), @@ -347,6 +348,7 @@ pub(crate) fn check_intrinsic_type( vec![type_id_ty()], tcx.type_of(tcx.lang_items().type_struct().unwrap()).no_bound_vars().unwrap(), ), + sym::field_representing_type_actual_type_id => (0, 0, vec![type_id_ty()], type_id_ty()), sym::offload => ( 3, 0, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5d3b9ad64f103..90afa3bad1aa3 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -949,6 +949,7 @@ symbols! { field_offset, field_projections, field_representing_type, + field_representing_type_actual_type_id, field_representing_type_raw, field_type, fields, @@ -2098,7 +2099,7 @@ symbols! { type_changing_struct_update, type_id, type_id_eq, - type_id_field, + type_id_field_representing_type, type_id_fields, type_id_variants, type_id_vtable, diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 9b5aa9d6255a4..d1216f0f72125 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2964,12 +2964,14 @@ pub const fn type_id_fields(_id: crate::any::TypeId, _variant_index: usize) -> u panic!("`TypeId::fields` can only be called at compile-time") } -/// Gets the `TypeId` of the field at the given index of the type represented by this `TypeId`. +/// Gets the [`FieldRepresentingType`]'s `TypeId` at the given index of the type represented by this `TypeId`. /// /// The more user-friendly version of this intrinsic is [`core::any::TypeId::field`]. +/// +/// [`FieldRepresentingType`]: crate::field::FieldRepresentingType #[rustc_intrinsic] #[unstable(feature = "core_intrinsics", issue = "none")] -pub const fn type_id_field( +pub const fn type_id_field_representing_type( _id: crate::any::TypeId, _variant_index: usize, _field_index: usize, @@ -2977,6 +2979,19 @@ pub const fn type_id_field( panic!("`TypeId::field` can only be called at compile-time") } +/// Gets the actual field `TypeId` of the [`FieldRepresentingType`]'s `TypeId`. +/// +/// The more user-friendly version of this intrinsic is [`core::mem::type_info::FieldId::type_id`]. +/// +/// [`FieldRepresentingType`]: crate::field::FieldRepresentingType +#[rustc_intrinsic] +#[unstable(feature = "core_intrinsics", issue = "none")] +pub const fn field_representing_type_actual_type_id( + _frt_type_id: crate::any::TypeId, +) -> crate::any::TypeId { + panic!("`FieldId::type_id` can only be called at compile-time") +} + /// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`. /// /// This is used to implement functions like `slice::from_raw_parts_mut` and diff --git a/library/core/src/mem/type_info.rs b/library/core/src/mem/type_info.rs index 373eb81a201b6..8e7e51caad1f1 100644 --- a/library/core/src/mem/type_info.rs +++ b/library/core/src/mem/type_info.rs @@ -528,30 +528,50 @@ impl TypeId { #[unstable(feature = "type_info", issue = "146922")] #[rustc_const_unstable(feature = "type_info", issue = "146922")] pub const fn field(self, variant_index: usize, field_index: usize) -> FieldId { - FieldId { type_id: intrinsics::type_id_field(self, variant_index, field_index) } + FieldId { + frt_type_id: intrinsics::type_id_field_representing_type( + self, + variant_index, + field_index, + ), + } } } -/// `FieldId` is a wrapper of `TypeId`, representing a field of a struct, tuple or enum variant. +/// Field representing type ID. Representing a field of a struct, tuple or enum variant. #[derive(Copy, PartialOrd, Ord, Hash)] #[derive_const(Clone, PartialEq, Eq)] #[unstable(feature = "type_info", issue = "146922")] pub struct FieldId { - type_id: TypeId, + frt_type_id: TypeId, } #[unstable(feature = "type_info", issue = "146922")] impl fmt::Debug for FieldId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "FieldId({:#034x})", self.type_id.as_u128()) + write!(f, "FieldId({:#034x})", self.frt_type_id.as_u128()) } } impl FieldId { - /// Returns the `TypeId` of this field. + /// Returns the `TypeId` of the actual field type. + /// + /// ``` + /// #![feature(type_info)] + /// use std::any::TypeId; + /// + /// struct Point { + /// x: u32, + /// y: u32, + /// } + /// assert_eq!( + /// const { TypeId::of::().field(0, 0).type_id() }, + /// TypeId::of::() + /// ); + /// ``` #[unstable(feature = "type_info", issue = "146922")] #[rustc_const_unstable(feature = "type_info", issue = "146922")] pub const fn type_id(self) -> TypeId { - self.type_id + intrinsics::field_representing_type_actual_type_id(self.frt_type_id) } } From 8db956b55dcb7f3beee9a5f756663dad2e16d0fe Mon Sep 17 00:00:00 2001 From: Dnreikronos Date: Wed, 27 May 2026 20:55:46 -0300 Subject: [PATCH 16/19] Move multi-file test to use auxiliary/ directory layout Place submod.rs under tests/ui/attributes/auxiliary/ and use #[path] to include it, matching the preferred compiletest test structure. Removes the need for //@ ignore-auxiliary. --- tests/ui/attributes/auxiliary/submod.rs | 1 + .../crate-root-path-in-different-file.rs | 1 + .../crate-root-path-in-different-file.stderr | 2 +- tests/ui/attributes/crate-root-path-in-different-file/submod.rs | 2 -- 4 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 tests/ui/attributes/auxiliary/submod.rs rename tests/ui/attributes/{crate-root-path-in-different-file => }/crate-root-path-in-different-file.rs (80%) rename tests/ui/attributes/{crate-root-path-in-different-file => }/crate-root-path-in-different-file.stderr (92%) delete mode 100644 tests/ui/attributes/crate-root-path-in-different-file/submod.rs diff --git a/tests/ui/attributes/auxiliary/submod.rs b/tests/ui/attributes/auxiliary/submod.rs new file mode 100644 index 0000000000000..8c030e6dc3731 --- /dev/null +++ b/tests/ui/attributes/auxiliary/submod.rs @@ -0,0 +1 @@ +#![crate_name = "bar"] diff --git a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs b/tests/ui/attributes/crate-root-path-in-different-file.rs similarity index 80% rename from tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs rename to tests/ui/attributes/crate-root-path-in-different-file.rs index 1b054724bfd31..66e7b5d7a718b 100644 --- a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.rs +++ b/tests/ui/attributes/crate-root-path-in-different-file.rs @@ -1,5 +1,6 @@ #![deny(unused_attributes)] +#[path = "auxiliary/submod.rs"] mod submod; fn main() {} diff --git a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr b/tests/ui/attributes/crate-root-path-in-different-file.stderr similarity index 92% rename from tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr rename to tests/ui/attributes/crate-root-path-in-different-file.stderr index c0c69a7bd57a8..3ddb5bf455487 100644 --- a/tests/ui/attributes/crate-root-path-in-different-file/crate-root-path-in-different-file.stderr +++ b/tests/ui/attributes/crate-root-path-in-different-file.stderr @@ -1,5 +1,5 @@ error: the `#![crate_name]` attribute can only be used at the crate root - --> $DIR/submod.rs:2:1 + --> $DIR/auxiliary/submod.rs:1:1 | LL | #![crate_name = "bar"] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/crate-root-path-in-different-file/submod.rs b/tests/ui/attributes/crate-root-path-in-different-file/submod.rs deleted file mode 100644 index f3a36d031b484..0000000000000 --- a/tests/ui/attributes/crate-root-path-in-different-file/submod.rs +++ /dev/null @@ -1,2 +0,0 @@ -//@ ignore-auxiliary (used by `./crate-root-path-in-different-file.rs`) -#![crate_name = "bar"] From fd3b569601ad8c889c709fb943a384aa0aab65c8 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 27 May 2026 20:47:04 -0700 Subject: [PATCH 17/19] Apply suggestions from code review Co-authored-by: Josh Stone Co-authored-by: alexey semenyuk --- RELEASES.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 854dfa4631bbd..f46077ee409b8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -55,10 +55,11 @@ Cargo ----- - [Allow a dependency to specify both a git repository and an alternate registry.](https://github.com/rust-lang/cargo/pull/16810/) Just like with crates.io, the git repository will be used locally, but the registry version will be used when published. - [Added `target.'cfg(..)'.rustdocflags` support in configuration.](https://github.com/rust-lang/cargo/pull/16846) +- Fixed [CVE-2026-5222](https://blog.rust-lang.org/2026/05/25/cve-2026-5222/) and [CVE-2026-5223](https://blog.rust-lang.org/2026/05/25/cve-2026-5223/). Rustdoc ----- -- [Deprecation notes are now rendered like any other documentation](https://github.com/rust-lang/rust/pull/149931). Previously they used the css `white-space: pre-wrap;` property and stripped any `

` elements from the rendered html, however this caused issues and unintuitive behavior. The new behavior should be more predictable, however some multi-line deprecation notes will now be rendered as as single lines. If this is undesirable, you can use the standard markdown method of forcing a linebreak, which is `" \n"` (two spaces followed by a newline). +- [Deprecation notes are now rendered like any other documentation](https://github.com/rust-lang/rust/pull/149931). Previously they used the css `white-space: pre-wrap;` property and stripped any `

` elements from the rendered html, however this caused issues and unintuitive behavior. The new behavior should be more predictable, however some multi-line deprecation notes will now be rendered as as single lines. If this is undesirable, you can use the standard markdown method of forcing a linebreak, which is two spaces followed by a newline (`"\n"`). - [Don't emit rustdoc `missing_doc_code_examples` lint on impl items](https://github.com/rust-lang/rust/pull/154048) - [Seperate methods and associated functions in sidebar](https://github.com/rust-lang/rust/pull/154644) @@ -68,13 +69,13 @@ Compatibility Notes - [Fix layout of `#[repr(Int)]` enums in some edge cases involving fields of uninhabited zero-sized types](https://github.com/rust-lang/rust/pull/146989) - [Prevent unsize-coercing into `Pin` where `Foo` doesn't implement `Deref`. Some such coercions were previously allowed, but produce a type with no useful public API.](https://github.com/rust-lang/rust/pull/149218) - [rustc: Stop passing `--allow-undefined` on wasm targets](https://github.com/rust-lang/rust/pull/149868) -- [Gate the accidentally stabilized #![reexport_test_harness_main] attribute](https://github.com/rust-lang/rust/pull/152210) +- [Gate the accidentally stabilized `#![reexport_test_harness_main]` attribute](https://github.com/rust-lang/rust/pull/152210) - [Error on return-position-impl-trait-in-traits whose types are too private](https://github.com/rust-lang/rust/pull/152543) - [Report the `uninhabited_static` lint in dependencies and make it deny-by-default](https://github.com/rust-lang/rust/pull/152853) - [Distributed builds now contain non-split debuginfo for windows-gnu](https://github.com/rust-lang/rust/pull/152870) This appears to improve the quality of backtraces. This change has no effect on the defaults for the output of rustc/cargo on these targets. - [Check const generic arguments are correctly typed in more positions](https://github.com/rust-lang/rust/pull/152931) -- [Remove -Csoft-float](https://github.com/rust-lang/rust/pull/152973) +- [Remove `-Csoft-float`](https://github.com/rust-lang/rust/pull/152973) - [Importing structs with `::{self [as name]}`, e.g., `struct S {}; use S::{self as Other};`, is now no longer permitted because `{self}` imports require a module parent.](https://github.com/rust-lang/rust/pull/152996) - [For `export_name`, `link_name`, and `link_section` attributes, if multiple of the same attribute is present, the first one now takes precedence.](https://github.com/rust-lang/rust/pull/153041) - [Update the minimum external LLVM to 21](https://github.com/rust-lang/rust/pull/153684) @@ -91,7 +92,7 @@ significant improvements to the performance or internals of rustc and related tools. - [JSON targets: `aarch64` softfloat targets now have to have `rustc_abi` set to `"softfloat"`](https://github.com/rust-lang/rust/pull/152941) -- [target specs: stricter checks for LLVM ABI values, and correlate that with cfg(target_abi)](https://github.com/rust-lang/rust/pull/153769) +- [target specs: stricter checks for LLVM ABI values, and correlate that with `cfg(target_abi)`](https://github.com/rust-lang/rust/pull/153769) From dd6f520f7ec5c1cd4e86c646cc8cc45c67f3a947 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 27 May 2026 20:49:44 -0700 Subject: [PATCH 18/19] clean up spaces and add a rustdoc anchor --- RELEASES.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index f46077ee409b8..e3ab7a4b370e4 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -11,7 +11,6 @@ Language - [Support s390x vector registers in inline assembly](https://github.com/rust-lang/rust/pull/154184) - [Allow using constants of type `ManuallyDrop` as patterns (fixing a regression introduced in 1.94.0)](https://github.com/rust-lang/rust/pull/154891) - Compiler @@ -19,9 +18,6 @@ Compiler - [Enable link relaxation feature for LoongArch Linux targets](https://github.com/rust-lang/rust/pull/153427) - [Update `riscv64gc-unknown-fuchsia` baseline to RVA22 + vector](https://github.com/rust-lang/rust/pull/155072) - - - Libraries @@ -30,7 +26,6 @@ Libraries - [refactor 'valid for read/write' definition: exclude null; add that as an exception on individual methods instead](https://github.com/rust-lang/rust/pull/152615) - [Fix SGX delayed host lookup via ToSocketAddr](https://github.com/rust-lang/rust/pull/152851) - Stabilized APIs @@ -48,7 +43,6 @@ Stabilized APIs - [`core::range::Range`](https://doc.rust-lang.org/stable/std/range/struct.Range.html) - [`core::range::RangeIter`](https://doc.rust-lang.org/stable/std/range/struct.RangeIter.html) - Cargo @@ -57,11 +51,14 @@ Cargo - [Added `target.'cfg(..)'.rustdocflags` support in configuration.](https://github.com/rust-lang/cargo/pull/16846) - Fixed [CVE-2026-5222](https://blog.rust-lang.org/2026/05/25/cve-2026-5222/) and [CVE-2026-5223](https://blog.rust-lang.org/2026/05/25/cve-2026-5223/). + + Rustdoc ----- - [Deprecation notes are now rendered like any other documentation](https://github.com/rust-lang/rust/pull/149931). Previously they used the css `white-space: pre-wrap;` property and stripped any `

` elements from the rendered html, however this caused issues and unintuitive behavior. The new behavior should be more predictable, however some multi-line deprecation notes will now be rendered as as single lines. If this is undesirable, you can use the standard markdown method of forcing a linebreak, which is two spaces followed by a newline (`"\n"`). - [Don't emit rustdoc `missing_doc_code_examples` lint on impl items](https://github.com/rust-lang/rust/pull/154048) - [Seperate methods and associated functions in sidebar](https://github.com/rust-lang/rust/pull/154644) + Compatibility Notes @@ -81,7 +78,6 @@ Compatibility Notes - [Update the minimum external LLVM to 21](https://github.com/rust-lang/rust/pull/153684) - On `avr` targets, C's `double` type is 32-bit by default, so [change `c_double` to `f32` on `avr` targets to match](https://github.com/rust-lang/rust/pull/154647). This is a breaking change, but necessary to make `c_double` match C's double. - Internal Changes @@ -95,7 +91,6 @@ tools. - [target specs: stricter checks for LLVM ABI values, and correlate that with `cfg(target_abi)`](https://github.com/rust-lang/rust/pull/153769) - Version 1.95.0 (2026-04-16) =========================== From 63d96cbcc78dc191db6bc5388de75ef15bbb1628 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 27 May 2026 22:51:55 -0700 Subject: [PATCH 19/19] Fix `assert_matches!` link --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index e3ab7a4b370e4..4982b54f0f886 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -31,7 +31,7 @@ Libraries Stabilized APIs --------------- -- [`assert_matches!`](https://doc.rust-lang.org/stable/std/macro.debug_assert_matches.html) +- [`assert_matches!`](https://doc.rust-lang.org/stable/std/macro.assert_matches.html) - [`debug_assert_matches!`](https://doc.rust-lang.org/stable/std/macro.debug_assert_matches.html) - [`From for AssertUnwindSafe`](https://doc.rust-lang.org/stable/std/panic/struct.AssertUnwindSafe.html#impl-From%3CT%3E-for-AssertUnwindSafe%3CT%3E) - [`From for LazyCell`](https://doc.rust-lang.org/stable/std/cell/struct.LazyCell.html#impl-From%3CT%3E-for-LazyCell%3CT,+F%3E)