From 87a08b15cbd9730f5bb8d1a6b79d2dcb35c2677c Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Tue, 2 Jun 2026 19:21:43 +0200 Subject: [PATCH 1/5] Integrate target checking for #[repr] into its attribute parser --- .../rustc_attr_parsing/src/attributes/repr.rs | 108 +++++++--- .../rustc_attr_parsing/src/target_checking.rs | 25 +-- .../src/error_codes/E0517.md | 6 +- compiler/rustc_passes/src/check_attr.rs | 103 +--------- compiler/rustc_passes/src/errors.rs | 50 ----- .../asm/invalid-repr-simd-on-enum-148634.rs | 2 +- .../invalid-repr-simd-on-enum-148634.stderr | 14 +- tests/ui/asm/naked-with-invalid-repr-attr.rs | 19 +- .../asm/naked-with-invalid-repr-attr.stderr | 100 ++++----- ...ow-inline-and-repr-at-invalid-positions.rs | 2 +- ...nline-and-repr-at-invalid-positions.stderr | 9 +- tests/ui/attributes/empty-repr.rs | 1 + tests/ui/attributes/empty-repr.stderr | 10 +- tests/ui/attributes/invalid-repr.rs | 2 +- tests/ui/attributes/invalid-repr.stderr | 12 +- tests/ui/attributes/malformed-attrs.rs | 1 - tests/ui/attributes/malformed-attrs.stderr | 167 ++++++++------- tests/ui/attributes/malformed-fn-align.rs | 2 +- tests/ui/attributes/malformed-fn-align.stderr | 20 +- tests/ui/attributes/malformed-reprs.rs | 1 - tests/ui/attributes/malformed-reprs.stderr | 21 +- tests/ui/attributes/malformed-static-align.rs | 2 +- .../attributes/malformed-static-align.stderr | 20 +- .../repr-align-in-trait-issue-132391.rs | 4 +- .../repr-align-in-trait-issue-132391.stderr | 10 +- ...nvalid-attributes-on-const-params-78957.rs | 6 +- ...id-attributes-on-const-params-78957.stderr | 37 ++-- tests/ui/enum-discriminant/eval-error.rs | 2 +- tests/ui/enum-discriminant/eval-error.stderr | 19 +- tests/ui/error-codes/E0517.rs | 15 -- tests/ui/error-codes/E0517.stderr | 36 ---- .../feature-gates/feature-gate-repr-simd.rs | 4 +- .../feature-gate-repr-simd.stderr | 38 ++-- ...sue-43106-gating-of-builtin-attrs-error.rs | 34 +--- ...43106-gating-of-builtin-attrs-error.stderr | 190 +++++++++--------- .../ui/layout/thaw-transmute-invalid-enum.rs | 2 +- .../layout/thaw-transmute-invalid-enum.stderr | 19 +- tests/ui/layout/thaw-validate-invalid-enum.rs | 2 +- .../layout/thaw-validate-invalid-enum.stderr | 20 +- ...st-prop-unions-known-panics-lint-123710.rs | 2 +- ...rop-unions-known-panics-lint-123710.stderr | 20 +- .../ui/proc-macro/ambiguous-builtin-attrs.rs | 4 +- .../proc-macro/ambiguous-builtin-attrs.stderr | 25 +-- tests/ui/repr/attr-usage-repr.rs | 10 +- tests/ui/repr/attr-usage-repr.stderr | 58 +++--- .../ui/repr/invalid-repr-on-structs-74082.rs | 4 +- .../repr/invalid-repr-on-structs-74082.stderr | 21 +- tests/ui/repr/issue-83505-repr-simd.rs | 2 +- tests/ui/repr/issue-83505-repr-simd.stderr | 13 +- tests/ui/repr/repr-disallow-on-variant.rs | 2 +- tests/ui/repr/repr-disallow-on-variant.stderr | 12 +- tests/ui/repr/repr-empty-packed.rs | 2 +- tests/ui/repr/repr-empty-packed.stderr | 16 +- tests/ui/repr/repr-transparent-other-items.rs | 4 +- .../repr/repr-transparent-other-items.stderr | 21 +- tests/ui/simd/repr-simd-on-enum.rs | 2 +- tests/ui/simd/repr-simd-on-enum.stderr | 16 +- 57 files changed, 566 insertions(+), 803 deletions(-) delete mode 100644 tests/ui/error-codes/E0517.rs delete mode 100644 tests/ui/error-codes/E0517.stderr diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 7b4e838a1a7fb..94391c33cf223 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -37,6 +37,13 @@ impl CombineAttributeParser for ReprParser { }; if list.is_empty() { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ])); + let attr_span = cx.attr_span; cx.adcx().warn_empty_attribute(attr_span); return vec![]; @@ -62,8 +69,12 @@ impl CombineAttributeParser for ReprParser { fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option { use ReprAttr::*; - macro_rules! no_args { + macro_rules! repr_int { ($constructor: expr) => {{ + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Enum), + Warn(Target::MacroCall), + ])); cx.expect_no_args(param.args())?; Some($constructor) }}; @@ -71,33 +82,82 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< match param.path().word_sym() { Some(sym::align) => { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ])); let l = cx.expect_list(param.args(), param.span())?; parse_repr_align(cx, l, AlignKind::Align) } - Some(sym::packed) => match param.args() { - ArgParser::NoArgs => Some(ReprPacked(Align::ONE)), - ArgParser::List(l) => parse_repr_align(cx, l, AlignKind::Packed), - ArgParser::NameValue(_) => { - cx.adcx().expected_list_or_no_args(param.span()); - None + Some(sym::packed) => { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Union), + Warn(Target::MacroCall), + ])); + match param.args() { + ArgParser::NoArgs => Some(ReprPacked(Align::ONE)), + ArgParser::List(l) => parse_repr_align(cx, l, AlignKind::Packed), + ArgParser::NameValue(_) => { + cx.adcx().expected_list_or_no_args(param.span()); + None + } } - }, - Some(sym::Rust) => no_args!(ReprRust), - Some(sym::C) => no_args!(ReprC), - Some(sym::simd) => no_args!(ReprSimd), - Some(sym::transparent) => no_args!(ReprTransparent), - Some(sym::i8) => no_args!(ReprInt(SignedInt(IntTy::I8))), - Some(sym::u8) => no_args!(ReprInt(UnsignedInt(UintTy::U8))), - Some(sym::i16) => no_args!(ReprInt(SignedInt(IntTy::I16))), - Some(sym::u16) => no_args!(ReprInt(UnsignedInt(UintTy::U16))), - Some(sym::i32) => no_args!(ReprInt(SignedInt(IntTy::I32))), - Some(sym::u32) => no_args!(ReprInt(UnsignedInt(UintTy::U32))), - Some(sym::i64) => no_args!(ReprInt(SignedInt(IntTy::I64))), - Some(sym::u64) => no_args!(ReprInt(UnsignedInt(UintTy::U64))), - Some(sym::i128) => no_args!(ReprInt(SignedInt(IntTy::I128))), - Some(sym::u128) => no_args!(ReprInt(UnsignedInt(UintTy::U128))), - Some(sym::isize) => no_args!(ReprInt(SignedInt(IntTy::Isize))), - Some(sym::usize) => no_args!(ReprInt(UnsignedInt(UintTy::Usize))), + } + + Some(sym::Rust) => { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ])); + cx.expect_no_args(param.args())?; + Some(ReprRust) + } + Some(sym::C) => { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ])); + cx.expect_no_args(param.args())?; + Some(ReprC) + } + Some(sym::simd) => { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), // Feature gated in `rustc_ast_passes` + Warn(Target::MacroCall), // FIXME: This is not feature gated (!!) + ])); + cx.expect_no_args(param.args())?; + Some(ReprSimd) + } + Some(sym::transparent) => { + cx.check_target(&AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ])); + cx.expect_no_args(param.args())?; + Some(ReprTransparent) + } + + Some(sym::i8) => repr_int!(ReprInt(SignedInt(IntTy::I8))), + Some(sym::u8) => repr_int!(ReprInt(UnsignedInt(UintTy::U8))), + Some(sym::i16) => repr_int!(ReprInt(SignedInt(IntTy::I16))), + Some(sym::u16) => repr_int!(ReprInt(UnsignedInt(UintTy::U16))), + Some(sym::i32) => repr_int!(ReprInt(SignedInt(IntTy::I32))), + Some(sym::u32) => repr_int!(ReprInt(UnsignedInt(UintTy::U32))), + Some(sym::i64) => repr_int!(ReprInt(SignedInt(IntTy::I64))), + Some(sym::u64) => repr_int!(ReprInt(UnsignedInt(UintTy::U64))), + Some(sym::i128) => repr_int!(ReprInt(SignedInt(IntTy::I128))), + Some(sym::u128) => repr_int!(ReprInt(UnsignedInt(UintTy::U128))), + Some(sym::isize) => repr_int!(ReprInt(SignedInt(IntTy::Isize))), + Some(sym::usize) => repr_int!(ReprInt(UnsignedInt(UintTy::Usize))), _ => { cx.adcx().expected_specific_argument( param.span(), diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 806c795f4e197..5811bcf8c8a88 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -102,25 +102,6 @@ impl<'sess> AttributeParser<'sess> { return; } - if matches!(cx.attr_path.segments.as_ref(), [sym::repr]) && cx.target == Target::Crate { - // The allowed targets of `repr` depend on its arguments. They can't be checked using - // the `AttributeParser` code. - let span = cx.attr_span; - let item = - cx.cx.first_line_of_next_item(span).map(|span| ItemFollowingInnerAttr { span }); - - let pound_to_opening_bracket = cx.attr_span.until(cx.inner_span); - - cx.dcx() - .create_err(InvalidAttrAtCrateLevel { - span, - pound_to_opening_bracket, - name: sym::repr, - item, - }) - .emit(); - } - let result = allowed_targets.is_allowed(cx.target); if matches!(result, AllowedResult::Allowed) { return; @@ -399,6 +380,12 @@ fn filter_targets( added_fake_targets.push(target_group_name); } +impl<'f, 'sess> AcceptContext<'f, 'sess> { + pub(crate) fn check_target(&mut self, allowed_targets: &AllowedTargets) { + AttributeParser::check_target(allowed_targets, self); + } +} + /// This is the list of all targets to which a attribute can be applied /// This is used for: /// - `rustc_dummy`, which can be applied to all targets diff --git a/compiler/rustc_error_codes/src/error_codes/E0517.md b/compiler/rustc_error_codes/src/error_codes/E0517.md index 5354a08bf31a7..1655904722fbc 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0517.md +++ b/compiler/rustc_error_codes/src/error_codes/E0517.md @@ -1,8 +1,12 @@ +#### Note: this error code is no longer emitted by the compiler. +This error code was replaced with the +`attribute cannot be used on...` diagnostic that does not have an error code. + A `#[repr(..)]` attribute was placed on an unsupported item. Examples of erroneous code: -```compile_fail,E0517 +```compile_fail #[repr(C)] type Foo = u8; diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f6765d604acb3..a265325fd8e77 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1205,7 +1205,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // #[repr(foo)] // #[repr(bar, align(8))] // ``` - let (reprs, first_attr_span) = + let (reprs, _first_attr_span) = find_attr!(attrs, Repr { reprs, first_span } => (reprs.as_slice(), Some(*first_span))) .unwrap_or((&[], None)); @@ -1215,123 +1215,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let mut is_simd = false; let mut is_transparent = false; - for (repr, repr_span) in reprs { + for (repr, _repr_span) in reprs { match repr { ReprAttr::ReprRust => { is_explicit_rust = true; - match target { - Target::Struct | Target::Union | Target::Enum => continue, - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - } } ReprAttr::ReprC => { is_c = true; - match target { - Target::Struct | Target::Union | Target::Enum => continue, - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - } - } - ReprAttr::ReprAlign(..) => match target { - Target::Struct | Target::Union | Target::Enum => {} - Target::Fn | Target::Method(_) if self.tcx.features().fn_align() => { - self.dcx().emit_err(errors::ReprAlignShouldBeAlign { - span: *repr_span, - item: target.plural_name(), - }); - } - Target::Static if self.tcx.features().static_align() => { - self.dcx().emit_err(errors::ReprAlignShouldBeAlignStatic { - span: *repr_span, - item: target.plural_name(), - }); - } - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - }, - ReprAttr::ReprPacked(_) => { - if target != Target::Struct && target != Target::Union { - self.dcx().emit_err(errors::AttrApplication::StructUnion { - hint_span: *repr_span, - span, - }); - } else { - continue; - } } + ReprAttr::ReprAlign(..) => {} + ReprAttr::ReprPacked(_) => {} ReprAttr::ReprSimd => { is_simd = true; - if target != Target::Struct { - self.dcx().emit_err(errors::AttrApplication::Struct { - hint_span: *repr_span, - span, - }); - } else { - continue; - } } ReprAttr::ReprTransparent => { is_transparent = true; - match target { - Target::Struct | Target::Union | Target::Enum => continue, - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - } } ReprAttr::ReprInt(_) => { int_reprs += 1; - if target != Target::Enum { - self.dcx().emit_err(errors::AttrApplication::Enum { - hint_span: *repr_span, - span, - }); - } else { - continue; - } } }; } - // catch `repr()` with no arguments, applied to an item (i.e. not `#![repr()]`) - if let Some(first_attr_span) = first_attr_span - && reprs.is_empty() - && item.is_some() - { - match target { - Target::Struct | Target::Union | Target::Enum => {} - Target::Fn | Target::Method(_) => { - self.dcx().emit_err(errors::ReprAlignShouldBeAlign { - span: first_attr_span, - item: target.plural_name(), - }); - } - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: first_attr_span, - span, - }); - } - } - return; - } - // Just point at all repr hints if there are any incompatibilities. // This is not ideal, but tracking precisely which ones are at fault is a huge hassle. let hint_spans = reprs.iter().map(|(_, span)| *span); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 208aa65cd0424..66c33b3e49756 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -698,38 +698,6 @@ pub(crate) struct UselessAssignment<'a> { )] pub(crate) struct InlineIgnoredForExported; -#[derive(Diagnostic)] -pub(crate) enum AttrApplication { - #[diag("attribute should be applied to an enum", code = E0517)] - Enum { - #[primary_span] - hint_span: Span, - #[label("not an enum")] - span: Span, - }, - #[diag("attribute should be applied to a struct", code = E0517)] - Struct { - #[primary_span] - hint_span: Span, - #[label("not a struct")] - span: Span, - }, - #[diag("attribute should be applied to a struct or union", code = E0517)] - StructUnion { - #[primary_span] - hint_span: Span, - #[label("not a struct or union")] - span: Span, - }, - #[diag("attribute should be applied to a struct, enum, or union", code = E0517)] - StructEnumUnion { - #[primary_span] - hint_span: Span, - #[label("not a struct, enum, or union")] - span: Span, - }, -} - #[derive(Diagnostic)] #[diag("transparent {$target} cannot have other repr hints", code = E0692)] pub(crate) struct TransparentIncompatible { @@ -1154,24 +1122,6 @@ pub(crate) enum UnexportableItem<'a> { }, } -#[derive(Diagnostic)] -#[diag("`#[repr(align(...))]` is not supported on {$item}")] -pub(crate) struct ReprAlignShouldBeAlign { - #[primary_span] - #[help("use `#[rustc_align(...)]` instead")] - pub span: Span, - pub item: &'static str, -} - -#[derive(Diagnostic)] -#[diag("`#[repr(align(...))]` is not supported on {$item}")] -pub(crate) struct ReprAlignShouldBeAlignStatic { - #[primary_span] - #[help("use `#[rustc_align_static(...)]` instead")] - pub span: Span, - pub item: &'static str, -} - #[derive(Diagnostic)] #[diag("`eii_macro_for` is only valid on functions and statics")] pub(crate) struct EiiImplTarget { diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs index 45f1f092e5268..f224eafa4cdf1 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs @@ -4,7 +4,7 @@ use std::arch::asm; #[repr(simd)] -//~^ ERROR attribute should be applied to a struct +//~^ ERROR attribute cannot be used on //~| ERROR unsupported representation for zero-variant enum enum Es {} diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr index 6992d03f4fa68..4099dd9bcd01b 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr @@ -1,11 +1,10 @@ -error[E0517]: attribute should be applied to a struct - --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:1 | LL | #[repr(simd)] - | ^^^^ -... -LL | enum Es {} - | ---------- not a struct + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to structs error[E0084]: unsupported representation for zero-variant enum --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8 @@ -18,5 +17,4 @@ LL | enum Es {} error: aborting due to 2 previous errors -Some errors have detailed explanations: E0084, E0517. -For more information about an error, try `rustc --explain E0084`. +For more information about this error, try `rustc --explain E0084`. diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.rs b/tests/ui/asm/naked-with-invalid-repr-attr.rs index 4620d007e4ec9..85e014ec9734e 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.rs +++ b/tests/ui/asm/naked-with-invalid-repr-attr.rs @@ -8,45 +8,40 @@ use std::arch::naked_asm; #[repr(C)] -//~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example1() { - //~^ NOTE not a struct, enum, or union naked_asm!("") } #[repr(transparent)] -//~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example2() { - //~^ NOTE not a struct, enum, or union naked_asm!("") } #[repr(C)] -//~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on #[rustc_align(16)] #[unsafe(naked)] extern "C" fn example3() { - //~^ NOTE not a struct, enum, or union naked_asm!("") } // note: two errors because of packed and C #[repr(C, packed)] -//~^ ERROR attribute should be applied to a struct or union [E0517] -//~| ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on +//~| ERROR attribute cannot be used on +//~| NOTE duplicate diagnostic emitted due to #[unsafe(naked)] extern "C" fn example4() { - //~^ NOTE not a struct, enum, or union - //~| NOTE not a struct or union naked_asm!("") } #[repr(u8)] -//~^ ERROR attribute should be applied to an enum [E0517] +//~^ ERROR `#[repr]` attribute cannot be used on #[unsafe(naked)] extern "C" fn example5() { - //~^ NOTE not an enum naked_asm!("") } diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.stderr b/tests/ui/asm/naked-with-invalid-repr-attr.stderr index 8530495be667a..4d0bb41d644a2 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.stderr +++ b/tests/ui/asm/naked-with-invalid-repr-attr.stderr @@ -1,77 +1,51 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:10:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:10:1 | -LL | #[repr(C)] - | ^ -... -LL | / extern "C" fn example1() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union +LL | #[repr(C)] + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:18:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:17:1 + | +LL | #[repr(transparent)] + | ^^^^^^^^^^^^^^^^^^^^ | -LL | #[repr(transparent)] - | ^^^^^^^^^^^ -... -LL | / extern "C" fn example2() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:26:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:24:1 + | +LL | #[repr(C)] + | ^^^^^^^^^^ | -LL | #[repr(C)] - | ^ -... -LL | / extern "C" fn example3() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:36:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:33:1 | -LL | #[repr(C, packed)] - | ^ -... -LL | / extern "C" fn example4() { -LL | | -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union +LL | #[repr(C, packed)] + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct or union - --> $DIR/naked-with-invalid-repr-attr.rs:36:11 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:33:1 + | +LL | #[repr(C, packed)] + | ^^^^^^^^^^^^^^^^^^ | -LL | #[repr(C, packed)] - | ^^^^^^ -... -LL | / extern "C" fn example4() { -LL | | -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct or union + = help: `#[repr]` can only be applied to data types + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0517]: attribute should be applied to an enum - --> $DIR/naked-with-invalid-repr-attr.rs:46:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:42:1 + | +LL | #[repr(u8)] + | ^^^^^^^^^^^ | -LL | #[repr(u8)] - | ^^ -... -LL | / extern "C" fn example5() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not an enum + = help: `#[repr]` can only be applied to enums error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs index f295ecf302598..36c69f0660925 100644 --- a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs @@ -1,5 +1,5 @@ //! Regression test for fn main() { #[inline] struct Foo; //~ ERROR attribute cannot be used on - #[repr(C)] fn foo() {} //~ ERROR attribute should be applied to a struct, enum, or union + #[repr(C)] fn foo() {} //~ ERROR attribute cannot be used on } diff --git a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr index fc8e22f171c20..2cff227793dfb 100644 --- a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr @@ -6,12 +6,13 @@ LL | #[inline] struct Foo; | = help: `#[inline]` can only be applied to functions -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:4:12 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:4:5 | LL | #[repr(C)] fn foo() {} - | ^ ----------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/attributes/empty-repr.rs b/tests/ui/attributes/empty-repr.rs index e6ba1baf031ab..10bd15af0f0f0 100644 --- a/tests/ui/attributes/empty-repr.rs +++ b/tests/ui/attributes/empty-repr.rs @@ -9,6 +9,7 @@ fn main() { fn test() where #[repr()] //~^ ERROR unused attribute +//~| ERROR attribute cannot be used on (): Sized { } diff --git a/tests/ui/attributes/empty-repr.stderr b/tests/ui/attributes/empty-repr.stderr index 6dfa2df75b737..bc99469477604 100644 --- a/tests/ui/attributes/empty-repr.stderr +++ b/tests/ui/attributes/empty-repr.stderr @@ -1,3 +1,11 @@ +error: `#[repr]` attribute cannot be used on where predicates + --> $DIR/empty-repr.rs:10:1 + | +LL | #[repr()] + | ^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + error: unused attribute --> $DIR/empty-repr.rs:10:1 | @@ -11,5 +19,5 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/attributes/invalid-repr.rs b/tests/ui/attributes/invalid-repr.rs index d7933533405c4..e88a51e9a3ab6 100644 --- a/tests/ui/attributes/invalid-repr.rs +++ b/tests/ui/attributes/invalid-repr.rs @@ -1,5 +1,5 @@ #[repr(align(16))] -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on pub type Foo = i32; fn main() {} diff --git a/tests/ui/attributes/invalid-repr.stderr b/tests/ui/attributes/invalid-repr.stderr index 3f5a305c6b700..3d23f92d6cf49 100644 --- a/tests/ui/attributes/invalid-repr.stderr +++ b/tests/ui/attributes/invalid-repr.stderr @@ -1,12 +1,10 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-repr.rs:1:8 +error: `#[repr]` attribute cannot be used on type aliases + --> $DIR/invalid-repr.rs:1:1 | LL | #[repr(align(16))] - | ^^^^^^^^^ -LL | -LL | pub type Foo = i32; - | ------------------- not a struct, enum, or union + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index c73feb9110f11..8eb1f3bcfd346 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -45,7 +45,6 @@ //~| ERROR attribute cannot be used on #[repr] //~^ ERROR malformed -//~| ERROR is not supported on functions #[rustc_as_ptr = 5] //~^ ERROR malformed #[inline = 5] diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index b31e4976837cf..1463098fc25ec 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -1,5 +1,5 @@ error[E0539]: malformed `cfg` attribute input - --> $DIR/malformed-attrs.rs:106:1 + --> $DIR/malformed-attrs.rs:105:1 | LL | #[cfg] | ^^^^^^ expected this to be a list @@ -11,7 +11,7 @@ LL | #[cfg(predicate)] | +++++++++++ error[E0539]: malformed `cfg_attr` attribute input - --> $DIR/malformed-attrs.rs:108:1 + --> $DIR/malformed-attrs.rs:107:1 | LL | #[cfg_attr] | ^^^^^^^^^^^ expected this to be a list @@ -23,13 +23,13 @@ LL | #[cfg_attr(predicate, attr1, attr2, ...)] | ++++++++++++++++++++++++++++++ error[E0463]: can't find crate for `wloop` - --> $DIR/malformed-attrs.rs:210:1 + --> $DIR/malformed-attrs.rs:209:1 | LL | extern crate wloop; | ^^^^^^^^^^^^^^^^^^^ can't find crate error: malformed `allow` attribute input - --> $DIR/malformed-attrs.rs:176:1 + --> $DIR/malformed-attrs.rs:175:1 | LL | #[allow] | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | #[allow(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input - --> $DIR/malformed-attrs.rs:178:1 + --> $DIR/malformed-attrs.rs:177:1 | LL | #[expect] | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | #[expect(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input - --> $DIR/malformed-attrs.rs:180:1 + --> $DIR/malformed-attrs.rs:179:1 | LL | #[warn] | ^^^^^^^ @@ -77,7 +77,7 @@ LL | #[warn(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input - --> $DIR/malformed-attrs.rs:182:1 + --> $DIR/malformed-attrs.rs:181:1 | LL | #[deny] | ^^^^^^^ @@ -93,7 +93,7 @@ LL | #[deny(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input - --> $DIR/malformed-attrs.rs:184:1 + --> $DIR/malformed-attrs.rs:183:1 | LL | #[forbid] | ^^^^^^^^^ @@ -109,23 +109,32 @@ LL | #[forbid(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:103:1 + --> $DIR/malformed-attrs.rs:102:1 | LL | #[proc_macro = 18] | ^^^^^^^^^^^^^^^^^^ error: the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:120:1 + --> $DIR/malformed-attrs.rs:119:1 | LL | #[proc_macro_attribute = 19] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:127:1 + --> $DIR/malformed-attrs.rs:126:1 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ +error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint + --> $DIR/malformed-attrs.rs:214:1 + | +LL | #[allow_internal_unsafe = 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(allow_internal_unsafe)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + error[E0539]: malformed `windows_subsystem` attribute input --> $DIR/malformed-attrs.rs:26:1 | @@ -224,7 +233,7 @@ LL | #[repr] = note: for more information, visit error[E0565]: malformed `rustc_as_ptr` attribute input - --> $DIR/malformed-attrs.rs:49:1 + --> $DIR/malformed-attrs.rs:48:1 | LL | #[rustc_as_ptr = 5] | ^^^^^^^^^^^^^^^---^ @@ -238,7 +247,7 @@ LL + #[rustc_as_ptr] | error[E0539]: malformed `rustc_align` attribute input - --> $DIR/malformed-attrs.rs:54:1 + --> $DIR/malformed-attrs.rs:53:1 | LL | #[rustc_align] | ^^^^^^^^^^^^^^ expected this to be a list @@ -249,7 +258,7 @@ LL | #[rustc_align()] | ++++++++++++++++++++++ error[E0539]: malformed `optimize` attribute input - --> $DIR/malformed-attrs.rs:56:1 + --> $DIR/malformed-attrs.rs:55:1 | LL | #[optimize] | ^^^^^^^^^^^ expected this to be a list @@ -264,7 +273,7 @@ LL | #[optimize(speed)] | +++++++ error[E0565]: malformed `cold` attribute input - --> $DIR/malformed-attrs.rs:58:1 + --> $DIR/malformed-attrs.rs:57:1 | LL | #[cold = 1] | ^^^^^^^---^ @@ -278,7 +287,7 @@ LL + #[cold] | error[E0539]: malformed `must_use` attribute input - --> $DIR/malformed-attrs.rs:60:1 + --> $DIR/malformed-attrs.rs:59:1 | LL | #[must_use()] | ^^^^^^^^^^--^ @@ -296,7 +305,7 @@ LL + #[must_use] | error[E0565]: malformed `no_mangle` attribute input - --> $DIR/malformed-attrs.rs:62:1 + --> $DIR/malformed-attrs.rs:61:1 | LL | #[no_mangle = 1] | ^^^^^^^^^^^^---^ @@ -310,7 +319,7 @@ LL + #[no_mangle] | error[E0565]: malformed `naked` attribute input - --> $DIR/malformed-attrs.rs:64:1 + --> $DIR/malformed-attrs.rs:63:1 | LL | #[unsafe(naked())] | ^^^^^^^^^^^^^^--^^ @@ -324,7 +333,7 @@ LL + #[unsafe(naked)] | error[E0565]: malformed `track_caller` attribute input - --> $DIR/malformed-attrs.rs:66:1 + --> $DIR/malformed-attrs.rs:65:1 | LL | #[track_caller()] | ^^^^^^^^^^^^^^--^ @@ -338,7 +347,7 @@ LL + #[track_caller] | error[E0539]: malformed `export_name` attribute input - --> $DIR/malformed-attrs.rs:68:1 + --> $DIR/malformed-attrs.rs:67:1 | LL | #[export_name()] | ^^^^^^^^^^^^^^^^ @@ -350,7 +359,7 @@ LL + #[export_name = "name"] | error[E0805]: malformed `used` attribute input - --> $DIR/malformed-attrs.rs:70:1 + --> $DIR/malformed-attrs.rs:69:1 | LL | #[used()] | ^^^^^^--^ @@ -368,7 +377,7 @@ LL + #[used] | error: `#[used]` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:70:1 + --> $DIR/malformed-attrs.rs:69:1 | LL | #[used()] | ^^^^^^^^^ @@ -376,7 +385,7 @@ LL | #[used()] = help: `#[used]` can only be applied to statics error[E0539]: malformed `crate_name` attribute input - --> $DIR/malformed-attrs.rs:73:1 + --> $DIR/malformed-attrs.rs:72:1 | LL | #[crate_name] | ^^^^^^^^^^^^^ @@ -387,7 +396,7 @@ LL | #[crate_name = "name"] | ++++++++ error[E0539]: malformed `target_feature` attribute input - --> $DIR/malformed-attrs.rs:78:1 + --> $DIR/malformed-attrs.rs:77:1 | LL | #[target_feature] | ^^^^^^^^^^^^^^^^^ expected this to be a list @@ -398,7 +407,7 @@ LL | #[target_feature(enable = "feat1, feat2")] | +++++++++++++++++++++++++ error[E0565]: malformed `export_stable` attribute input - --> $DIR/malformed-attrs.rs:80:1 + --> $DIR/malformed-attrs.rs:79:1 | LL | #[export_stable = 1] | ^^^^^^^^^^^^^^^^---^ @@ -412,7 +421,7 @@ LL + #[export_stable] | error[E0539]: malformed `link` attribute input - --> $DIR/malformed-attrs.rs:82:1 + --> $DIR/malformed-attrs.rs:81:1 | LL | #[link] | ^^^^^^^ expected this to be a list @@ -420,7 +429,7 @@ LL | #[link] = note: for more information, visit error[E0539]: malformed `link_name` attribute input - --> $DIR/malformed-attrs.rs:86:1 + --> $DIR/malformed-attrs.rs:85:1 | LL | #[link_name] | ^^^^^^^^^^^^ @@ -432,7 +441,7 @@ LL | #[link_name = "name"] | ++++++++ error[E0539]: malformed `link_section` attribute input - --> $DIR/malformed-attrs.rs:90:1 + --> $DIR/malformed-attrs.rs:89:1 | LL | #[link_section] | ^^^^^^^^^^^^^^^ @@ -444,7 +453,7 @@ LL | #[link_section = "name"] | ++++++++ error[E0539]: malformed `coverage` attribute input - --> $DIR/malformed-attrs.rs:92:1 + --> $DIR/malformed-attrs.rs:91:1 | LL | #[coverage] | ^^^^^^^^^^^ expected this to be a list @@ -457,13 +466,13 @@ LL | #[coverage(on)] | ++++ error[E0539]: malformed `sanitize` attribute input - --> $DIR/malformed-attrs.rs:94:1 + --> $DIR/malformed-attrs.rs:93:1 | LL | #[sanitize] | ^^^^^^^^^^^ expected this to be a list error[E0565]: malformed `no_implicit_prelude` attribute input - --> $DIR/malformed-attrs.rs:99:1 + --> $DIR/malformed-attrs.rs:98:1 | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^^^^----^ @@ -477,7 +486,7 @@ LL + #[no_implicit_prelude] | error[E0565]: malformed `proc_macro` attribute input - --> $DIR/malformed-attrs.rs:103:1 + --> $DIR/malformed-attrs.rs:102:1 | LL | #[proc_macro = 18] | ^^^^^^^^^^^^^----^ @@ -491,7 +500,7 @@ LL + #[proc_macro] | error[E0539]: malformed `instruction_set` attribute input - --> $DIR/malformed-attrs.rs:110:1 + --> $DIR/malformed-attrs.rs:109:1 | LL | #[instruction_set] | ^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -503,7 +512,7 @@ LL | #[instruction_set(set)] | +++++ error[E0539]: malformed `patchable_function_entry` attribute input - --> $DIR/malformed-attrs.rs:112:1 + --> $DIR/malformed-attrs.rs:111:1 | LL | #[patchable_function_entry] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -514,7 +523,7 @@ LL | #[patchable_function_entry(prefix_nops = m, entry_nops = n)] | +++++++++++++++++++++++++++++++++ error[E0565]: malformed `coroutine` attribute input - --> $DIR/malformed-attrs.rs:115:5 + --> $DIR/malformed-attrs.rs:114:5 | LL | #[coroutine = 63] || {} | ^^^^^^^^^^^^----^ @@ -528,7 +537,7 @@ LL + #[coroutine] || {} | error[E0565]: malformed `proc_macro_attribute` attribute input - --> $DIR/malformed-attrs.rs:120:1 + --> $DIR/malformed-attrs.rs:119:1 | LL | #[proc_macro_attribute = 19] | ^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -542,7 +551,7 @@ LL + #[proc_macro_attribute] | error[E0539]: malformed `must_use` attribute input - --> $DIR/malformed-attrs.rs:123:1 + --> $DIR/malformed-attrs.rs:122:1 | LL | #[must_use = 1] | ^^^^^^^^^^^^^-^ @@ -560,7 +569,7 @@ LL + #[must_use] | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/malformed-attrs.rs:127:1 + --> $DIR/malformed-attrs.rs:126:1 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -574,7 +583,7 @@ LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] | ++++++++++++++++++++++++++++++++++++++++++ error[E0539]: malformed `must_not_suspend` attribute input - --> $DIR/malformed-attrs.rs:132:1 + --> $DIR/malformed-attrs.rs:131:1 | LL | #[must_not_suspend()] | ^^^^^^^^^^^^^^^^^^--^ @@ -590,7 +599,7 @@ LL + #[must_not_suspend] | error[E0539]: malformed `cfi_encoding` attribute input - --> $DIR/malformed-attrs.rs:134:1 + --> $DIR/malformed-attrs.rs:133:1 | LL | #[cfi_encoding = ""] | ^^^^^^^^^^^^^^^^^--^ @@ -603,7 +612,7 @@ LL | #[cfi_encoding = "encoding"] | ++++++++ error[E0565]: malformed `marker` attribute input - --> $DIR/malformed-attrs.rs:153:1 + --> $DIR/malformed-attrs.rs:152:1 | LL | #[marker = 3] | ^^^^^^^^^---^ @@ -617,7 +626,7 @@ LL + #[marker] | error[E0565]: malformed `fundamental` attribute input - --> $DIR/malformed-attrs.rs:155:1 + --> $DIR/malformed-attrs.rs:154:1 | LL | #[fundamental()] | ^^^^^^^^^^^^^--^ @@ -631,7 +640,7 @@ LL + #[fundamental] | error[E0565]: malformed `ffi_pure` attribute input - --> $DIR/malformed-attrs.rs:163:5 + --> $DIR/malformed-attrs.rs:162:5 | LL | #[unsafe(ffi_pure = 1)] | ^^^^^^^^^^^^^^^^^^---^^ @@ -645,7 +654,7 @@ LL + #[unsafe(ffi_pure)] | error[E0539]: malformed `link_ordinal` attribute input - --> $DIR/malformed-attrs.rs:165:5 + --> $DIR/malformed-attrs.rs:164:5 | LL | #[link_ordinal] | ^^^^^^^^^^^^^^^ expected this to be a list @@ -657,7 +666,7 @@ LL | #[link_ordinal(ordinal)] | +++++++++ error[E0565]: malformed `ffi_const` attribute input - --> $DIR/malformed-attrs.rs:169:5 + --> $DIR/malformed-attrs.rs:168:5 | LL | #[unsafe(ffi_const = 1)] | ^^^^^^^^^^^^^^^^^^^---^^ @@ -671,13 +680,13 @@ LL + #[unsafe(ffi_const)] | error[E0539]: malformed `linkage` attribute input - --> $DIR/malformed-attrs.rs:171:5 + --> $DIR/malformed-attrs.rs:170:5 | LL | #[linkage] | ^^^^^^^^^^ expected this to be of the form `linkage = "..."` error[E0539]: malformed `debugger_visualizer` attribute input - --> $DIR/malformed-attrs.rs:186:1 + --> $DIR/malformed-attrs.rs:185:1 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -689,7 +698,7 @@ LL | #[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")] | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0565]: malformed `automatically_derived` attribute input - --> $DIR/malformed-attrs.rs:188:1 + --> $DIR/malformed-attrs.rs:187:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -703,7 +712,7 @@ LL + #[automatically_derived] | error[E0565]: malformed `non_exhaustive` attribute input - --> $DIR/malformed-attrs.rs:196:1 + --> $DIR/malformed-attrs.rs:195:1 | LL | #[non_exhaustive = 1] | ^^^^^^^^^^^^^^^^^---^ @@ -717,7 +726,7 @@ LL + #[non_exhaustive] | error[E0565]: malformed `thread_local` attribute input - --> $DIR/malformed-attrs.rs:202:1 + --> $DIR/malformed-attrs.rs:201:1 | LL | #[thread_local()] | ^^^^^^^^^^^^^^--^ @@ -731,7 +740,7 @@ LL + #[thread_local] | error[E0565]: malformed `no_link` attribute input - --> $DIR/malformed-attrs.rs:206:1 + --> $DIR/malformed-attrs.rs:205:1 | LL | #[no_link()] | ^^^^^^^^^--^ @@ -745,7 +754,7 @@ LL + #[no_link] | error[E0539]: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:208:1 + --> $DIR/malformed-attrs.rs:207:1 | LL | #[macro_use = 1] | ^^^^^^^^^^^^---^ @@ -763,7 +772,7 @@ LL + #[macro_use] | error[E0539]: malformed `macro_export` attribute input - --> $DIR/malformed-attrs.rs:213:1 + --> $DIR/malformed-attrs.rs:212:1 | LL | #[macro_export = 18] | ^^^^^^^^^^^^^^^----^ @@ -789,7 +798,7 @@ LL | #[allow_internal_unsafe = 1] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0565]: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:215:1 + --> $DIR/malformed-attrs.rs:214:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^---^ @@ -815,7 +824,7 @@ LL | | } | |_- not a `const fn` warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/malformed-attrs.rs:82:1 + --> $DIR/malformed-attrs.rs:81:1 | LL | #[link] | ^^^^^^^ @@ -829,18 +838,6 @@ LL | | } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: requested on the command line with `-W unused-attributes` -error: `#[repr(align(...))]` is not supported on functions - --> $DIR/malformed-attrs.rs:46:1 - | -LL | #[repr] - | ^^^^^^^ - | -help: use `#[rustc_align(...)]` instead - --> $DIR/malformed-attrs.rs:46:1 - | -LL | #[repr] - | ^^^^^^^ - error: valid forms for the attribute are `#[doc = "string"]`, `#[doc(alias)]`, `#[doc(attribute)]`, `#[doc(auto_cfg)]`, `#[doc(cfg)]`, `#[doc(fake_variadic)]`, `#[doc(hidden)]`, `#[doc(html_favicon_url)]`, `#[doc(html_logo_url)]`, `#[doc(html_no_source)]`, `#[doc(html_playground_url)]`, `#[doc(html_root_url)]`, `#[doc(include)]`, `#[doc(inline)]`, `#[doc(issue_tracker_base_url)]`, `#[doc(keyword)]`, `#[doc(masked)]`, `#[doc(no_default_passes)]`, `#[doc(no_inline)]`, `#[doc(notable_trait)]`, `#[doc(passes)]`, `#[doc(plugins)]`, `#[doc(rust_logo)]`, `#[doc(search_unbox)]`, `#[doc(spotlight)]`, and `#[doc(test)]` --> $DIR/malformed-attrs.rs:41:1 | @@ -854,7 +851,7 @@ LL | #![deny(invalid_doc_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^ error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/malformed-attrs.rs:51:1 + --> $DIR/malformed-attrs.rs:50:1 | LL | #[inline = 5] | ^^^^^^^^^^^^^ @@ -864,13 +861,13 @@ LL | #[inline = 5] = note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/malformed-attrs.rs:73:1 + --> $DIR/malformed-attrs.rs:72:1 | LL | #[crate_name] | ^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/malformed-attrs.rs:114:1 + --> $DIR/malformed-attrs.rs:113:1 | LL | / fn test() { LL | | #[coroutine = 63] || {} @@ -879,13 +876,13 @@ LL | | } | |_^ error: valid forms for the attribute are `#[doc = "string"]`, `#[doc(alias)]`, `#[doc(attribute)]`, `#[doc(auto_cfg)]`, `#[doc(cfg)]`, `#[doc(fake_variadic)]`, `#[doc(hidden)]`, `#[doc(html_favicon_url)]`, `#[doc(html_logo_url)]`, `#[doc(html_no_source)]`, `#[doc(html_playground_url)]`, `#[doc(html_root_url)]`, `#[doc(include)]`, `#[doc(inline)]`, `#[doc(issue_tracker_base_url)]`, `#[doc(keyword)]`, `#[doc(masked)]`, `#[doc(no_default_passes)]`, `#[doc(no_inline)]`, `#[doc(notable_trait)]`, `#[doc(passes)]`, `#[doc(plugins)]`, `#[doc(rust_logo)]`, `#[doc(search_unbox)]`, `#[doc(spotlight)]`, and `#[doc(test)]` - --> $DIR/malformed-attrs.rs:76:1 + --> $DIR/malformed-attrs.rs:75:1 | LL | #[doc] | ^^^^^^ warning: `#[link_name]` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:86:1 + --> $DIR/malformed-attrs.rs:85:1 | LL | #[link_name] | ^^^^^^^^^^^^ @@ -894,7 +891,7 @@ LL | #[link_name] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:96:1 + --> $DIR/malformed-attrs.rs:95:1 | LL | #[ignore()] | ^^^^^^^^^^^ @@ -903,7 +900,7 @@ LL | #[ignore()] = note: for more information, see issue #57571 warning: `#[no_implicit_prelude]` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:99:1 + --> $DIR/malformed-attrs.rs:98:1 | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -912,7 +909,7 @@ LL | #[no_implicit_prelude = 23] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: missing options for `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:138:1 + --> $DIR/malformed-attrs.rs:137:1 | LL | #[diagnostic::on_unimplemented] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -921,7 +918,7 @@ LL | #[diagnostic::on_unimplemented] = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default warning: malformed `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:140:1 + --> $DIR/malformed-attrs.rs:139:1 | LL | #[diagnostic::on_unimplemented = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here @@ -929,13 +926,13 @@ LL | #[diagnostic::on_unimplemented = 1] = help: only `message`, `note` and `label` are allowed as options warning: `#[diagnostic::do_not_recommend]` does not expect any arguments - --> $DIR/malformed-attrs.rs:147:1 + --> $DIR/malformed-attrs.rs:146:1 | LL | #[diagnostic::do_not_recommend()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: `#[automatically_derived]` attribute cannot be used on modules - --> $DIR/malformed-attrs.rs:188:1 + --> $DIR/malformed-attrs.rs:187:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -944,7 +941,7 @@ LL | #[automatically_derived = 18] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:222:1 + --> $DIR/malformed-attrs.rs:221:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ @@ -953,7 +950,7 @@ LL | #[ignore = 1] = note: for more information, see issue #57571 error[E0308]: mismatched types - --> $DIR/malformed-attrs.rs:115:23 + --> $DIR/malformed-attrs.rs:114:23 | LL | fn test() { | - help: a return type might be missing here: `-> _` @@ -961,15 +958,15 @@ LL | #[coroutine = 63] || {} | ^^^^^ expected `()`, found coroutine | = note: expected unit type `()` - found coroutine `{coroutine@$DIR/malformed-attrs.rs:115:23: 115:25}` + found coroutine `{coroutine@$DIR/malformed-attrs.rs:114:23: 114:25}` -error: aborting due to 73 previous errors; 8 warnings emitted +error: aborting due to 72 previous errors; 8 warnings emitted Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. For more information about an error, try `rustc --explain E0308`. Future incompatibility report: Future breakage diagnostic: error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/malformed-attrs.rs:51:1 + --> $DIR/malformed-attrs.rs:50:1 | LL | #[inline = 5] | ^^^^^^^^^^^^^ @@ -980,7 +977,7 @@ LL | #[inline = 5] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:96:1 + --> $DIR/malformed-attrs.rs:95:1 | LL | #[ignore()] | ^^^^^^^^^^^ @@ -991,7 +988,7 @@ LL | #[ignore()] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:222:1 + --> $DIR/malformed-attrs.rs:221:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/malformed-fn-align.rs b/tests/ui/attributes/malformed-fn-align.rs index 219218f034793..737bdf6ffbe81 100644 --- a/tests/ui/attributes/malformed-fn-align.rs +++ b/tests/ui/attributes/malformed-fn-align.rs @@ -23,7 +23,7 @@ fn f2() {} #[rustc_align(0)] //~ ERROR invalid alignment value: not a power of two fn f3() {} -#[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on functions +#[repr(align(16))] //~ ERROR attribute cannot be used on fn f4() {} #[rustc_align(-1)] //~ ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr index e5aa500a562d3..84ca5ae4c87de 100644 --- a/tests/ui/attributes/malformed-fn-align.stderr +++ b/tests/ui/attributes/malformed-fn-align.stderr @@ -49,6 +49,14 @@ error[E0589]: invalid alignment value: not a power of two LL | #[rustc_align(0)] | ^ +error: `#[repr]` attribute cannot be used on functions + --> $DIR/malformed-fn-align.rs:26:1 + | +LL | #[repr(align(16))] + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression --> $DIR/malformed-fn-align.rs:29:15 | @@ -119,18 +127,6 @@ LL | #[rustc_align(32)] | = help: `#[rustc_align]` can only be applied to functions -error: `#[repr(align(...))]` is not supported on functions - --> $DIR/malformed-fn-align.rs:26:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - | -help: use `#[rustc_align(...)]` instead - --> $DIR/malformed-fn-align.rs:26:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - error: aborting due to 15 previous errors Some errors have detailed explanations: E0539, E0589, E0805. diff --git a/tests/ui/attributes/malformed-reprs.rs b/tests/ui/attributes/malformed-reprs.rs index 9827d10c4ba71..258aee76fea7d 100644 --- a/tests/ui/attributes/malformed-reprs.rs +++ b/tests/ui/attributes/malformed-reprs.rs @@ -3,7 +3,6 @@ // This is a regression test for https://github.com/rust-lang/rust/issues/143522 #![repr] //~^ ERROR malformed `repr` attribute input [E0539] -//~| ERROR `repr` attribute cannot be used at crate level // This is a regression test for https://github.com/rust-lang/rust/issues/143479 #[repr(align(0))] diff --git a/tests/ui/attributes/malformed-reprs.stderr b/tests/ui/attributes/malformed-reprs.stderr index 6a5f6492fcab0..9250fb83f6d58 100644 --- a/tests/ui/attributes/malformed-reprs.stderr +++ b/tests/ui/attributes/malformed-reprs.stderr @@ -6,29 +6,14 @@ LL | #![repr] | = note: for more information, visit -error: `repr` attribute cannot be used at crate level - --> $DIR/malformed-reprs.rs:4:1 - | -LL | #![repr] - | ^^^^^^^^ -... -LL | enum Foo {} - | ----------- the inner attribute doesn't annotate this item - | -help: perhaps you meant to use an outer attribute - | -LL - #![repr] -LL + #[repr] - | - error[E0589]: invalid alignment value: not a power of two - --> $DIR/malformed-reprs.rs:9:14 + --> $DIR/malformed-reprs.rs:8:14 | LL | #[repr(align(0))] | ^ error[E0084]: unsupported representation for zero-variant enum - --> $DIR/malformed-reprs.rs:9:1 + --> $DIR/malformed-reprs.rs:8:1 | LL | #[repr(align(0))] | ^^^^^^^^^^^^^^^^^ @@ -36,7 +21,7 @@ LL | #[repr(align(0))] LL | enum Foo {} | -------- zero-variant enum -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0084, E0539, E0589. For more information about an error, try `rustc --explain E0084`. diff --git a/tests/ui/attributes/malformed-static-align.rs b/tests/ui/attributes/malformed-static-align.rs index 305d8acf8af24..83fc8bae54fda 100644 --- a/tests/ui/attributes/malformed-static-align.rs +++ b/tests/ui/attributes/malformed-static-align.rs @@ -10,7 +10,7 @@ static S2: () = (); #[rustc_align_static(0)] //~ ERROR invalid alignment value: not a power of two static S3: () = (); -#[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on static +#[repr(align(16))] //~ ERROR attribute cannot be used on static S4: () = (); #[rustc_align_static(16)] //~ ERROR `#[rustc_align_static]` attribute cannot be used on structs diff --git a/tests/ui/attributes/malformed-static-align.stderr b/tests/ui/attributes/malformed-static-align.stderr index 15f0dc71830a7..0efa79660c0a6 100644 --- a/tests/ui/attributes/malformed-static-align.stderr +++ b/tests/ui/attributes/malformed-static-align.stderr @@ -24,6 +24,14 @@ error[E0589]: invalid alignment value: not a power of two LL | #[rustc_align_static(0)] | ^ +error: `#[repr]` attribute cannot be used on statics + --> $DIR/malformed-static-align.rs:13:1 + | +LL | #[repr(align(16))] + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + error: `#[rustc_align_static]` attribute cannot be used on structs --> $DIR/malformed-static-align.rs:16:1 | @@ -32,18 +40,6 @@ LL | #[rustc_align_static(16)] | = help: `#[rustc_align_static]` can be applied to foreign statics and statics -error: `#[repr(align(...))]` is not supported on statics - --> $DIR/malformed-static-align.rs:13:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - | -help: use `#[rustc_align_static(...)]` instead - --> $DIR/malformed-static-align.rs:13:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - error: aborting due to 5 previous errors Some errors have detailed explanations: E0539, E0589. diff --git a/tests/ui/attributes/repr-align-in-trait-issue-132391.rs b/tests/ui/attributes/repr-align-in-trait-issue-132391.rs index 7b9f6c12deadb..43d222f1c3a03 100644 --- a/tests/ui/attributes/repr-align-in-trait-issue-132391.rs +++ b/tests/ui/attributes/repr-align-in-trait-issue-132391.rs @@ -1,5 +1,7 @@ trait MyTrait { - #[repr(align)] //~ ERROR malformed `repr` attribute input + #[repr(align)] + //~^ ERROR malformed `repr` attribute input + //~| ERROR attribute cannot be used on fn myfun(); } diff --git a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr index a8f5d3bab584a..0d0b757fd4f48 100644 --- a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr +++ b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr @@ -1,3 +1,11 @@ +error: `#[repr]` attribute cannot be used on required trait methods + --> $DIR/repr-align-in-trait-issue-132391.rs:2:5 + | +LL | #[repr(align)] + | ^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + error[E0539]: malformed `repr` attribute input --> $DIR/repr-align-in-trait-issue-132391.rs:2:5 | @@ -8,6 +16,6 @@ LL | #[repr(align)] | = note: for more information, visit -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs index 106b9ae269068..e228533b67574 100644 --- a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs +++ b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs @@ -9,7 +9,7 @@ pub struct Bar<#[cold] const N: usize>; //~^ ERROR attribute cannot be used on //~| WARN previously accepted pub struct Baz<#[repr(C)] const N: usize>; -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on // pub struct Foo2<#[inline] 'a>(PhantomData<&'a ()>); //~^ ERROR attribute cannot be used on @@ -17,7 +17,7 @@ pub struct Bar2<#[cold] 'a>(PhantomData<&'a ()>); //~^ ERROR attribute cannot be used on //~| WARN previously accepted pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on // pub struct Foo3<#[inline] T>(PhantomData); //~^ ERROR attribute cannot be used on @@ -25,6 +25,6 @@ pub struct Bar3<#[cold] T>(PhantomData); //~^ ERROR attribute cannot be used on //~| WARN previously accepted pub struct Baz3<#[repr(C)] T>(PhantomData); -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on fn main() {} diff --git a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr index 7b30a783fcffc..04640549bf747 100644 --- a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr +++ b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr @@ -6,6 +6,14 @@ LL | pub struct Foo<#[inline] const N: usize>; | = help: `#[inline]` can only be applied to functions +error: `#[repr]` attribute cannot be used on const parameters + --> $DIR/invalid-attributes-on-const-params-78957.rs:11:16 + | +LL | pub struct Baz<#[repr(C)] const N: usize>; + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + error: `#[inline]` attribute cannot be used on lifetime parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:14:17 | @@ -14,6 +22,14 @@ LL | pub struct Foo2<#[inline] 'a>(PhantomData<&'a ()>); | = help: `#[inline]` can only be applied to functions +error: `#[repr]` attribute cannot be used on lifetime parameters + --> $DIR/invalid-attributes-on-const-params-78957.rs:19:17 + | +LL | pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + error: `#[inline]` attribute cannot be used on type parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:22:17 | @@ -22,23 +38,13 @@ LL | pub struct Foo3<#[inline] T>(PhantomData); | = help: `#[inline]` can only be applied to functions -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-attributes-on-const-params-78957.rs:11:23 - | -LL | pub struct Baz<#[repr(C)] const N: usize>; - | ^ -------------- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-attributes-on-const-params-78957.rs:19:24 - | -LL | pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); - | ^ -- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-attributes-on-const-params-78957.rs:27:24 +error: `#[repr]` attribute cannot be used on type parameters + --> $DIR/invalid-attributes-on-const-params-78957.rs:27:17 | LL | pub struct Baz3<#[repr(C)] T>(PhantomData); - | ^ - not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types error: `#[cold]` attribute cannot be used on const parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:8:16 @@ -74,4 +80,3 @@ LL | pub struct Bar3<#[cold] T>(PhantomData); error: aborting due to 9 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/enum-discriminant/eval-error.rs b/tests/ui/enum-discriminant/eval-error.rs index 45ac9472a4b7b..fa7576b4fadb8 100644 --- a/tests/ui/enum-discriminant/eval-error.rs +++ b/tests/ui/enum-discriminant/eval-error.rs @@ -22,7 +22,7 @@ enum Bar2 { } #[repr(u8, packed)] -//~^ ERROR attribute should be applied to a struct or union +//~^ ERROR attribute cannot be used on enum Foo3 { A } diff --git a/tests/ui/enum-discriminant/eval-error.stderr b/tests/ui/enum-discriminant/eval-error.stderr index 77449656ea6a8..858560602d3c9 100644 --- a/tests/ui/enum-discriminant/eval-error.stderr +++ b/tests/ui/enum-discriminant/eval-error.stderr @@ -4,16 +4,13 @@ error: unions cannot have zero fields LL | union Foo2 {} | ^^^^^^^^^^^^^ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/eval-error.rs:24:12 - | -LL | #[repr(u8, packed)] - | ^^^^^^ -LL | -LL | / enum Foo3 { -LL | | A -LL | | } - | |_- not a struct or union +error: `#[repr]` attribute cannot be used on enums + --> $DIR/eval-error.rs:24:1 + | +LL | #[repr(u8, packed)] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/eval-error.rs:2:5 @@ -53,5 +50,5 @@ LL | let _: Option = None; error: aborting due to 5 previous errors -Some errors have detailed explanations: E0080, E0277, E0517, E0740. +Some errors have detailed explanations: E0080, E0277, E0740. For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/error-codes/E0517.rs b/tests/ui/error-codes/E0517.rs deleted file mode 100644 index 1dcaa2d741f6f..0000000000000 --- a/tests/ui/error-codes/E0517.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[repr(C)] //~ ERROR: E0517 -type Foo = u8; - -#[repr(packed)] //~ ERROR: E0517 -enum Foo2 {Bar, Baz} - -#[repr(u8)] //~ ERROR: E0517 -struct Foo3 {bar: bool, baz: bool} - -#[repr(C)] //~ ERROR: E0517 -impl Foo3 { -} - -fn main() { -} diff --git a/tests/ui/error-codes/E0517.stderr b/tests/ui/error-codes/E0517.stderr deleted file mode 100644 index 2f90d4d0baa5e..0000000000000 --- a/tests/ui/error-codes/E0517.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/E0517.rs:1:8 - | -LL | #[repr(C)] - | ^ -LL | type Foo = u8; - | -------------- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct or union - --> $DIR/E0517.rs:4:8 - | -LL | #[repr(packed)] - | ^^^^^^ -LL | enum Foo2 {Bar, Baz} - | -------------------- not a struct or union - -error[E0517]: attribute should be applied to an enum - --> $DIR/E0517.rs:7:8 - | -LL | #[repr(u8)] - | ^^ -LL | struct Foo3 {bar: bool, baz: bool} - | ---------------------------------- not an enum - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/E0517.rs:10:8 - | -LL | #[repr(C)] - | ^ -LL | / impl Foo3 { -LL | | } - | |_- not a struct, enum, or union - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.rs b/tests/ui/feature-gates/feature-gate-repr-simd.rs index 091dc479ef3d4..e73ad1e536aa3 100644 --- a/tests/ui/feature-gates/feature-gate-repr-simd.rs +++ b/tests/ui/feature-gates/feature-gate-repr-simd.rs @@ -7,11 +7,11 @@ struct Foo([u64; 2]); struct Bar([u64; 2]); #[repr(simd)] //~ ERROR: SIMD types are experimental -//~^ ERROR: attribute should be applied to a struct +//~^ ERROR: attribute cannot be used on union U {f: u32} #[repr(simd)] //~ ERROR: SIMD types are experimental -//~^ error: attribute should be applied to a struct +//~^ error: attribute cannot be used on enum E { X } fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.stderr b/tests/ui/feature-gates/feature-gate-repr-simd.stderr index 0f1929038fe00..7526db1525868 100644 --- a/tests/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/tests/ui/feature-gates/feature-gate-repr-simd.stderr @@ -38,6 +38,22 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +error: `#[repr]` attribute cannot be used on unions + --> $DIR/feature-gate-repr-simd.rs:9:1 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to structs + +error: `#[repr]` attribute cannot be used on enums + --> $DIR/feature-gate-repr-simd.rs:13:1 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to structs + error[E0566]: conflicting representation hints --> $DIR/feature-gate-repr-simd.rs:4:8 | @@ -51,28 +67,10 @@ LL | #[repr(simd)] = note: for more information, see issue #68585 = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default -error[E0517]: attribute should be applied to a struct - --> $DIR/feature-gate-repr-simd.rs:9:8 - | -LL | #[repr(simd)] - | ^^^^ -LL | -LL | union U {f: u32} - | ---------------- not a struct - -error[E0517]: attribute should be applied to a struct - --> $DIR/feature-gate-repr-simd.rs:13:8 - | -LL | #[repr(simd)] - | ^^^^ -LL | -LL | enum E { X } - | ------------ not a struct - error: aborting due to 7 previous errors -Some errors have detailed explanations: E0517, E0566, E0658. -For more information about an error, try `rustc --explain E0517`. +Some errors have detailed explanations: E0566, E0658. +For more information about an error, try `rustc --explain E0566`. Future incompatibility report: Future breakage diagnostic: error[E0566]: conflicting representation hints --> $DIR/feature-gate-repr-simd.rs:4:8 diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs index 66d36d9a5d6de..d11326d994f23 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs @@ -14,7 +14,7 @@ //~| NOTE: the `#[rustc_main]` attribute is an internal implementation detail that will never be stable //~| NOTE: the `#[rustc_main]` attribute is used internally to specify test entry point function #![repr()] -//~^ ERROR: `repr` attribute cannot be used at crate level +//~^ ERROR: attribute cannot be used //~| WARN unused attribute //~| NOTE empty list has no effect #![path = "3800"] @@ -37,8 +37,6 @@ #[inline] //~^ ERROR attribute cannot be used on mod inline { - //~^ NOTE the inner attribute doesn't annotate this item - mod inner { #![inline] } //~^ ERROR attribute cannot be used on @@ -121,50 +119,40 @@ mod export_name { } #[repr(C)] -//~^ ERROR: attribute should be applied to a struct, enum, or union +//~^ ERROR: attribute cannot be used on mod repr { -//~^ NOTE not a struct, enum, or union mod inner { #![repr(C)] } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(C)] fn f() { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on struct S; #[repr(C)] type T = S; - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(C)] impl S { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on } #[repr(Rust)] -//~^ ERROR: attribute should be applied to a struct, enum, or union +//~^ ERROR: attribute cannot be used on mod repr_rust { -//~^ NOTE not a struct, enum, or union mod inner { #![repr(Rust)] } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(Rust)] fn f() { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on struct S; #[repr(Rust)] type T = S; - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(Rust)] impl S { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on } fn main() {} diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 04cfdc4bea8b8..95510b940ef1d 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -24,20 +24,13 @@ LL | #![rustc_main] | = help: `#[rustc_main]` can only be applied to functions -error: `repr` attribute cannot be used at crate level +error: `#[repr]` attribute cannot be used on crates --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1 | LL | #![repr()] | ^^^^^^^^^^ -... -LL | mod inline { - | ------------ the inner attribute doesn't annotate this item - | -help: perhaps you meant to use an outer attribute - | -LL - #![repr()] -LL + #[repr()] | + = help: `#[repr]` can only be applied to data types error: `#[path]` attribute cannot be used on crates --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1 @@ -88,7 +81,7 @@ LL | #[inline] = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:42:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:40:17 | LL | mod inner { #![inline] } | ^^^^^^^^^^ @@ -96,7 +89,7 @@ LL | mod inner { #![inline] } = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:51:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:49:5 | LL | #[inline] struct S; | ^^^^^^^^^ @@ -104,7 +97,7 @@ LL | #[inline] struct S; = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:52:5 | LL | #[inline] type T = S; | ^^^^^^^^^ @@ -112,7 +105,7 @@ LL | #[inline] type T = S; = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:57:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:55:5 | LL | #[inline] impl S { } | ^^^^^^^^^ @@ -120,7 +113,7 @@ LL | #[inline] impl S { } = help: `#[inline]` can only be applied to functions error: `#[no_link]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:61:1 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:59:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -128,7 +121,7 @@ LL | #[no_link] = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:64:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:17 | LL | mod inner { #![no_link] } | ^^^^^^^^^^^ @@ -136,7 +129,7 @@ LL | mod inner { #![no_link] } = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on functions - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:65:5 | LL | #[no_link] fn f() { | ^^^^^^^^^^ @@ -144,7 +137,7 @@ LL | #[no_link] fn f() { = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:77:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:75:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -152,7 +145,7 @@ LL | #[no_link] = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:84:5 | LL | #[no_link]type T = S; | ^^^^^^^^^^ @@ -160,7 +153,7 @@ LL | #[no_link]type T = S; = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:89:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:87:5 | LL | #[no_link] impl S { } | ^^^^^^^^^^ @@ -168,7 +161,7 @@ LL | #[no_link] impl S { } = help: `#[no_link]` can only be applied to extern crates error: `#[export_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:98:1 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:1 | LL | #[export_name = "2200"] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,7 +169,7 @@ LL | #[export_name = "2200"] = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:101:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:99:17 | LL | mod inner { #![export_name="2200"] } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -184,7 +177,7 @@ LL | mod inner { #![export_name="2200"] } = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:104:5 | LL | #[export_name = "2200"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +185,7 @@ LL | #[export_name = "2200"] struct S; = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:107:5 | LL | #[export_name = "2200"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -200,7 +193,7 @@ LL | #[export_name = "2200"] type T = S; = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:110:5 | LL | #[export_name = "2200"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -208,106 +201,112 @@ LL | #[export_name = "2200"] impl S { } = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on required trait methods - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:116:9 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:114:9 | LL | #[export_name = "2200"] fn foo(); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:8 - | -LL | #[repr(C)] - | ^ -LL | -LL | / mod repr { -LL | | -LL | | mod inner { #![repr(C)] } -... | -LL | | } - | |_- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:147:8 - | -LL | #[repr(Rust)] - | ^^^^ -LL | -LL | / mod repr_rust { -LL | | -LL | | mod inner { #![repr(Rust)] } -... | -LL | | } - | |_- not a struct, enum, or union - -warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1 - | -LL | #![no_mangle] - | ^^^^^^^^^^^^^ `#[no_mangle]` is ignored - | -note: `#[export_name]` takes precedence - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1 - | -LL | #![export_name = "2200"] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = note: requested on the command line with `-W unused-attributes` -help: remove the `#[no_mangle]` attribute +error: `#[repr]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:121:1 | -LL - #![no_mangle] +LL | #[repr(C)] + | ^^^^^^^^^^ | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:25 +error: `#[repr]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:124:17 | LL | mod inner { #![repr(C)] } - | --------------------^---- not a struct, enum, or union + | ^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:131:12 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:5 | LL | #[repr(C)] fn f() { } - | ^ ---------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:12 +error: `#[repr]` attribute cannot be used on type aliases + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:132:5 | LL | #[repr(C)] type T = S; - | ^ ----------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:12 +error: `#[repr]` attribute cannot be used on inherent impl blocks + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:135:5 | LL | #[repr(C)] impl S { } - | ^ ---------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:25 +error: `#[repr]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:140:1 + | +LL | #[repr(Rust)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + +error: `#[repr]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:143:17 | LL | mod inner { #![repr(Rust)] } - | --------------------^^^^---- not a struct, enum, or union + | ^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:146:5 | LL | #[repr(Rust)] fn f() { } - | ^^^^ ---------- not a struct, enum, or union + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:161:12 +error: `#[repr]` attribute cannot be used on type aliases + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:5 | LL | #[repr(Rust)] type T = S; - | ^^^^ ----------- not a struct, enum, or union + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:165:12 +error: `#[repr]` attribute cannot be used on inherent impl blocks + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:154:5 | LL | #[repr(Rust)] impl S { } - | ^^^^ ---------- not a struct, enum, or union + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types + +warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]` + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1 + | +LL | #![no_mangle] + | ^^^^^^^^^^^^^ `#[no_mangle]` is ignored + | +note: `#[export_name]` takes precedence + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1 + | +LL | #![export_name = "2200"] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: requested on the command line with `-W unused-attributes` +help: remove the `#[no_mangle]` attribute + | +LL - #![no_mangle] + | error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^ @@ -317,7 +316,7 @@ LL | #[inline = "2100"] fn f() { } = note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default warning: `#[no_link]` attribute cannot be used on match arms - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:70:13 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:68:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -326,7 +325,7 @@ LL | #[no_link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_link]` attribute cannot be used on struct fields - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:80:9 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:78:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -335,7 +334,7 @@ LL | #[no_link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_link]` attribute cannot be used on macro defs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:92:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:90:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -362,11 +361,10 @@ LL | #![no_mangle] error: aborting due to 37 previous errors; 6 warnings emitted -Some errors have detailed explanations: E0517, E0658. -For more information about an error, try `rustc --explain E0517`. +For more information about this error, try `rustc --explain E0658`. Future incompatibility report: Future breakage diagnostic: error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/layout/thaw-transmute-invalid-enum.rs b/tests/ui/layout/thaw-transmute-invalid-enum.rs index 20fc8d463594b..d6326a0852cd3 100644 --- a/tests/ui/layout/thaw-transmute-invalid-enum.rs +++ b/tests/ui/layout/thaw-transmute-invalid-enum.rs @@ -20,7 +20,7 @@ enum Ox00 { } #[repr(C, packed(2))] -//~^ ERROR: attribute should be applied to a struct +//~^ ERROR: attribute cannot be used on enum OxFF { V = 0xFF, } diff --git a/tests/ui/layout/thaw-transmute-invalid-enum.stderr b/tests/ui/layout/thaw-transmute-invalid-enum.stderr index f57f0a2ad6981..83785176000a1 100644 --- a/tests/ui/layout/thaw-transmute-invalid-enum.stderr +++ b/tests/ui/layout/thaw-transmute-invalid-enum.stderr @@ -9,16 +9,13 @@ help: you might be missing a type parameter LL | fn test() { | ++++++++ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/thaw-transmute-invalid-enum.rs:22:11 - | -LL | #[repr(C, packed(2))] - | ^^^^^^^^^ -LL | -LL | / enum OxFF { -LL | | V = 0xFF, -LL | | } - | |_- not a struct or union +error: `#[repr]` attribute cannot be used on enums + --> $DIR/thaw-transmute-invalid-enum.rs:22:1 + | +LL | #[repr(C, packed(2))] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can be applied to structs and unions error[E0658]: use of unstable library feature `transmutability` --> $DIR/thaw-transmute-invalid-enum.rs:4:20 @@ -75,5 +72,5 @@ LL | a: std::mem::ManuallyDrop, error: aborting due to 7 previous errors -Some errors have detailed explanations: E0425, E0517, E0658, E0740. +Some errors have detailed explanations: E0425, E0658, E0740. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/layout/thaw-validate-invalid-enum.rs b/tests/ui/layout/thaw-validate-invalid-enum.rs index 51aff7fb556c2..cc954661e4fbe 100644 --- a/tests/ui/layout/thaw-validate-invalid-enum.rs +++ b/tests/ui/layout/thaw-validate-invalid-enum.rs @@ -1,6 +1,6 @@ //@ compile-flags: -Zvalidate-mir -#[repr(packed)] //~ ERROR: attribute should be applied to a struct +#[repr(packed)] //~ ERROR: attribute cannot be used on #[repr(u32)] enum E { A, diff --git a/tests/ui/layout/thaw-validate-invalid-enum.stderr b/tests/ui/layout/thaw-validate-invalid-enum.stderr index 9e522cba96aa1..c41130e803945 100644 --- a/tests/ui/layout/thaw-validate-invalid-enum.stderr +++ b/tests/ui/layout/thaw-validate-invalid-enum.stderr @@ -1,15 +1,10 @@ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/thaw-validate-invalid-enum.rs:3:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/thaw-validate-invalid-enum.rs:3:1 | -LL | #[repr(packed)] - | ^^^^^^ -LL | #[repr(u32)] -LL | / enum E { -LL | | A, -LL | | B, -LL | | C, -LL | | } - | |_- not a struct or union +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/thaw-validate-invalid-enum.rs:14:9 @@ -25,5 +20,4 @@ LL | e: std::mem::ManuallyDrop, error: aborting due to 2 previous errors -Some errors have detailed explanations: E0517, E0740. -For more information about an error, try `rustc --explain E0517`. +For more information about this error, try `rustc --explain E0740`. diff --git a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs index 2b93d0f8a609d..d765675fd4163 100644 --- a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs +++ b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs @@ -4,7 +4,7 @@ // which is a repr not supported for enums #[repr(packed)] -//~^ ERROR attribute should be applied to a struct or union +//~^ ERROR attribute cannot be used on #[repr(u32)] enum E { A, diff --git a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr index 44dde6120e8d6..de12a4d04d9b4 100644 --- a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr +++ b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr @@ -1,15 +1,10 @@ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:1 | -LL | #[repr(packed)] - | ^^^^^^ -... -LL | / enum E { -LL | | A, -LL | | B, -LL | | C, -LL | | } - | |_- not a struct or union +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:18:9 @@ -25,5 +20,4 @@ LL | e: std::mem::ManuallyDrop, error: aborting due to 2 previous errors -Some errors have detailed explanations: E0517, E0740. -For more information about an error, try `rustc --explain E0517`. +For more information about this error, try `rustc --explain E0740`. diff --git a/tests/ui/proc-macro/ambiguous-builtin-attrs.rs b/tests/ui/proc-macro/ambiguous-builtin-attrs.rs index e36a12beb8182..922a2e4c1f463 100644 --- a/tests/ui/proc-macro/ambiguous-builtin-attrs.rs +++ b/tests/ui/proc-macro/ambiguous-builtin-attrs.rs @@ -20,11 +20,11 @@ fn bench() {} fn non_macro_expanded_location<#[repr(C)] T>() { //~^ ERROR `repr` is ambiguous - //~| ERROR attribute should be applied to a struct, enum, or union + //~| ERROR attribute cannot be used on match 0u8 { #[repr(C)] //~^ ERROR `repr` is ambiguous - //~| ERROR attribute should be applied to a struct, enum, or union + //~| ERROR attribute cannot be used on _ => {} } } diff --git a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr index d057019862604..38e0589ef03a2 100644 --- a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr +++ b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr @@ -94,22 +94,23 @@ LL | use builtin_attrs::*; | ^^^^^^^^^^^^^^^^ = help: use `crate::feature` to refer to this attribute macro unambiguously -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/ambiguous-builtin-attrs.rs:21:39 +error: `#[repr]` attribute cannot be used on match arms + --> $DIR/ambiguous-builtin-attrs.rs:25:9 | -LL | fn non_macro_expanded_location<#[repr(C)] T>() { - | ^ - not a struct, enum, or union +LL | #[repr(C)] + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/ambiguous-builtin-attrs.rs:25:16 +error: `#[repr]` attribute cannot be used on type parameters + --> $DIR/ambiguous-builtin-attrs.rs:21:32 | -LL | #[repr(C)] - | ^ -... -LL | _ => {} - | ------- not a struct, enum, or union +LL | fn non_macro_expanded_location<#[repr(C)] T>() { + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types error: aborting due to 9 previous errors -Some errors have detailed explanations: E0425, E0517, E0659. +Some errors have detailed explanations: E0425, E0659. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/repr/attr-usage-repr.rs b/tests/ui/repr/attr-usage-repr.rs index 10256a7619e51..510ff8a89668d 100644 --- a/tests/ui/repr/attr-usage-repr.rs +++ b/tests/ui/repr/attr-usage-repr.rs @@ -1,6 +1,6 @@ #![feature(repr_simd)] -#[repr(C)] //~ ERROR: attribute should be applied to a struct, enum, or union +#[repr(C)] //~ ERROR: attribute cannot be used on fn f() {} #[repr(C)] @@ -12,7 +12,7 @@ struct SPacked(f64, f64); #[repr(simd)] struct SSimd([f64; 2]); -#[repr(i8)] //~ ERROR: attribute should be applied to an enum +#[repr(i8)] //~ ERROR: `#[repr]` attribute cannot be used on struct SInt(f64, f64); #[repr(C)] @@ -27,13 +27,13 @@ enum EAlign { B, } -#[repr(packed)] //~ ERROR: attribute should be applied to a struct +#[repr(packed)] //~ ERROR: attribute cannot be used on enum EPacked { A, B, } -#[repr(simd)] //~ ERROR: attribute should be applied to a struct +#[repr(simd)] //~ ERROR: attribute cannot be used on enum ESimd { A, B, @@ -45,7 +45,7 @@ enum EInt { B, } -#[repr()] //~ ERROR attribute should be applied to a struct, enum, or union [E0517] +#[repr()] //~ ERROR attribute cannot be used on //~^ WARN unused attribute type SirThisIsAType = i32; diff --git a/tests/ui/repr/attr-usage-repr.stderr b/tests/ui/repr/attr-usage-repr.stderr index 33aa3c2f9f21a..d6ad67a315319 100644 --- a/tests/ui/repr/attr-usage-repr.stderr +++ b/tests/ui/repr/attr-usage-repr.stderr @@ -1,49 +1,42 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/attr-usage-repr.rs:3:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/attr-usage-repr.rs:3:1 | LL | #[repr(C)] - | ^ -LL | fn f() {} - | --------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to an enum - --> $DIR/attr-usage-repr.rs:15:8 +error: `#[repr]` attribute cannot be used on structs + --> $DIR/attr-usage-repr.rs:15:1 | LL | #[repr(i8)] - | ^^ -LL | struct SInt(f64, f64); - | ---------------------- not an enum + | ^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to enums -error[E0517]: attribute should be applied to a struct or union - --> $DIR/attr-usage-repr.rs:30:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/attr-usage-repr.rs:30:1 + | +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ | -LL | #[repr(packed)] - | ^^^^^^ -LL | / enum EPacked { -LL | | A, -LL | | B, -LL | | } - | |_- not a struct or union + = help: `#[repr]` can be applied to structs and unions -error[E0517]: attribute should be applied to a struct - --> $DIR/attr-usage-repr.rs:36:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/attr-usage-repr.rs:36:1 | -LL | #[repr(simd)] - | ^^^^ -LL | / enum ESimd { -LL | | A, -LL | | B, -LL | | } - | |_- not a struct +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to structs -error[E0517]: attribute should be applied to a struct, enum, or union +error: `#[repr]` attribute cannot be used on type aliases --> $DIR/attr-usage-repr.rs:48:1 | LL | #[repr()] | ^^^^^^^^^ -LL | -LL | type SirThisIsAType = i32; - | -------------------------- not a struct, enum, or union + | + = help: `#[repr]` can only be applied to data types warning: unused attribute --> $DIR/attr-usage-repr.rs:48:1 @@ -64,4 +57,3 @@ LL | #[repr()] error: aborting due to 5 previous errors; 2 warnings emitted -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.rs b/tests/ui/repr/invalid-repr-on-structs-74082.rs index 8b9807fad8ce2..4887666bf0174 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.rs +++ b/tests/ui/repr/invalid-repr-on-structs-74082.rs @@ -1,10 +1,10 @@ // https://github.com/rust-lang/rust/issues/74082 #![allow(dead_code)] -#[repr(i128)] //~ ERROR: attribute should be applied to an enum +#[repr(i128)] //~ ERROR: `#[repr]` attribute cannot be used on struct Foo; -#[repr(u128)] //~ ERROR: attribute should be applied to an enum +#[repr(u128)] //~ ERROR: `#[repr]` attribute cannot be used on struct Bar; fn main() {} diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.stderr b/tests/ui/repr/invalid-repr-on-structs-74082.stderr index e11beb811fbff..6ffde26b8edea 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.stderr +++ b/tests/ui/repr/invalid-repr-on-structs-74082.stderr @@ -1,19 +1,18 @@ -error[E0517]: attribute should be applied to an enum - --> $DIR/invalid-repr-on-structs-74082.rs:4:8 +error: `#[repr]` attribute cannot be used on structs + --> $DIR/invalid-repr-on-structs-74082.rs:4:1 | LL | #[repr(i128)] - | ^^^^ -LL | struct Foo; - | ----------- not an enum + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to enums -error[E0517]: attribute should be applied to an enum - --> $DIR/invalid-repr-on-structs-74082.rs:7:8 +error: `#[repr]` attribute cannot be used on structs + --> $DIR/invalid-repr-on-structs-74082.rs:7:1 | LL | #[repr(u128)] - | ^^^^ -LL | struct Bar; - | ----------- not an enum + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to enums error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/issue-83505-repr-simd.rs b/tests/ui/repr/issue-83505-repr-simd.rs index bebbc636728fd..1b649ac763497 100644 --- a/tests/ui/repr/issue-83505-repr-simd.rs +++ b/tests/ui/repr/issue-83505-repr-simd.rs @@ -3,7 +3,7 @@ #![crate_type="lib"] #[repr(simd)] -//~^ ERROR: attribute should be applied to a struct [E0517] +//~^ ERROR: attribute cannot be used on //~| ERROR: unsupported representation for zero-variant enum [E0084] //~| ERROR: SIMD types are experimental and possibly buggy [E0658] diff --git a/tests/ui/repr/issue-83505-repr-simd.stderr b/tests/ui/repr/issue-83505-repr-simd.stderr index 57cfbeb95de87..b074ba93e4932 100644 --- a/tests/ui/repr/issue-83505-repr-simd.stderr +++ b/tests/ui/repr/issue-83505-repr-simd.stderr @@ -16,14 +16,13 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0517]: attribute should be applied to a struct - --> $DIR/issue-83505-repr-simd.rs:5:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/issue-83505-repr-simd.rs:5:1 | LL | #[repr(simd)] - | ^^^^ -... -LL | enum Es {} - | ---------- not a struct + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to structs error[E0084]: unsupported representation for zero-variant enum --> $DIR/issue-83505-repr-simd.rs:5:8 @@ -36,5 +35,5 @@ LL | enum Es {} error: aborting due to 4 previous errors -Some errors have detailed explanations: E0084, E0517, E0658. +Some errors have detailed explanations: E0084, E0658. For more information about an error, try `rustc --explain E0084`. diff --git a/tests/ui/repr/repr-disallow-on-variant.rs b/tests/ui/repr/repr-disallow-on-variant.rs index d9bd0b0e38a69..8a16905d4b7b4 100644 --- a/tests/ui/repr/repr-disallow-on-variant.rs +++ b/tests/ui/repr/repr-disallow-on-variant.rs @@ -2,7 +2,7 @@ struct Test; enum Foo { #[repr(u8)] - //~^ ERROR attribute should be applied to an enum + //~^ ERROR `#[repr]` attribute cannot be used on Variant, } diff --git a/tests/ui/repr/repr-disallow-on-variant.stderr b/tests/ui/repr/repr-disallow-on-variant.stderr index ebdb851b7a64f..ab96e45e343f3 100644 --- a/tests/ui/repr/repr-disallow-on-variant.stderr +++ b/tests/ui/repr/repr-disallow-on-variant.stderr @@ -1,12 +1,10 @@ -error[E0517]: attribute should be applied to an enum - --> $DIR/repr-disallow-on-variant.rs:4:12 +error: `#[repr]` attribute cannot be used on enum variants + --> $DIR/repr-disallow-on-variant.rs:4:5 | LL | #[repr(u8)] - | ^^ -LL | -LL | Variant, - | ------- not an enum + | ^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to enums error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/repr-empty-packed.rs b/tests/ui/repr/repr-empty-packed.rs index 6e390a12b15ac..6caa4667e73b7 100644 --- a/tests/ui/repr/repr-empty-packed.rs +++ b/tests/ui/repr/repr-empty-packed.rs @@ -2,7 +2,7 @@ #![deny(unused_attributes)] #[repr()] //~ ERROR unused attribute -#[repr(packed)] //~ ERROR attribute should be applied to a struct or union +#[repr(packed)] //~ ERROR attribute cannot be used on enums pub enum Foo { Bar, Baz(i32), diff --git a/tests/ui/repr/repr-empty-packed.stderr b/tests/ui/repr/repr-empty-packed.stderr index adf32c9552967..6a3b14f5906d0 100644 --- a/tests/ui/repr/repr-empty-packed.stderr +++ b/tests/ui/repr/repr-empty-packed.stderr @@ -1,13 +1,10 @@ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/repr-empty-packed.rs:5:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/repr-empty-packed.rs:5:1 | -LL | #[repr(packed)] - | ^^^^^^ -LL | / pub enum Foo { -LL | | Bar, -LL | | Baz(i32), -LL | | } - | |_- not a struct or union +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can be applied to structs and unions error: unused attribute --> $DIR/repr-empty-packed.rs:4:1 @@ -24,4 +21,3 @@ LL | #![deny(unused_attributes)] error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/repr-transparent-other-items.rs b/tests/ui/repr/repr-transparent-other-items.rs index e537e3e1a6365..4c3ef28a2f18f 100644 --- a/tests/ui/repr/repr-transparent-other-items.rs +++ b/tests/ui/repr/repr-transparent-other-items.rs @@ -1,9 +1,9 @@ // See also repr-transparent.rs -#[repr(transparent)] //~ ERROR should be applied to a struct +#[repr(transparent)] //~ ERROR attribute cannot be used on fn cant_repr_this() {} -#[repr(transparent)] //~ ERROR should be applied to a struct +#[repr(transparent)] //~ ERROR attribute cannot be used on static CANT_REPR_THIS: u32 = 0; fn main() {} diff --git a/tests/ui/repr/repr-transparent-other-items.stderr b/tests/ui/repr/repr-transparent-other-items.stderr index 14e6f13e1ae44..a768c321ef101 100644 --- a/tests/ui/repr/repr-transparent-other-items.stderr +++ b/tests/ui/repr/repr-transparent-other-items.stderr @@ -1,19 +1,18 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/repr-transparent-other-items.rs:3:8 +error: `#[repr]` attribute cannot be used on functions + --> $DIR/repr-transparent-other-items.rs:3:1 | LL | #[repr(transparent)] - | ^^^^^^^^^^^ -LL | fn cant_repr_this() {} - | ---------------------- not a struct, enum, or union + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/repr-transparent-other-items.rs:6:8 +error: `#[repr]` attribute cannot be used on statics + --> $DIR/repr-transparent-other-items.rs:6:1 | LL | #[repr(transparent)] - | ^^^^^^^^^^^ -LL | static CANT_REPR_THIS: u32 = 0; - | ------------------------------- not a struct, enum, or union + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to data types error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/simd/repr-simd-on-enum.rs b/tests/ui/simd/repr-simd-on-enum.rs index 49cf9e92d36cf..4762b43487122 100644 --- a/tests/ui/simd/repr-simd-on-enum.rs +++ b/tests/ui/simd/repr-simd-on-enum.rs @@ -2,7 +2,7 @@ #![feature(repr_simd)] -#[repr(simd)] //~ ERROR attribute should be applied to a struct +#[repr(simd)] //~ ERROR attribute cannot be used on enum Aligned { Zero = 0, One = 1, diff --git a/tests/ui/simd/repr-simd-on-enum.stderr b/tests/ui/simd/repr-simd-on-enum.stderr index 6a19a16e8eae5..2711c99a90cfb 100644 --- a/tests/ui/simd/repr-simd-on-enum.stderr +++ b/tests/ui/simd/repr-simd-on-enum.stderr @@ -1,14 +1,10 @@ -error[E0517]: attribute should be applied to a struct - --> $DIR/repr-simd-on-enum.rs:5:8 +error: `#[repr]` attribute cannot be used on enums + --> $DIR/repr-simd-on-enum.rs:5:1 | -LL | #[repr(simd)] - | ^^^^ -LL | / enum Aligned { -LL | | Zero = 0, -LL | | One = 1, -LL | | } - | |_- not a struct +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr]` can only be applied to structs error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0517`. From b40c43d8b81c1a10980c15b91c4a723dc05dc87d Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Tue, 2 Jun 2026 19:39:21 +0200 Subject: [PATCH 2/5] Add specific arguments to the diagnostic message --- .../rustc_attr_parsing/src/attributes/repr.rs | 46 +++++++++---------- compiler/rustc_attr_parsing/src/interface.rs | 2 +- .../src/session_diagnostics.rs | 5 +- .../rustc_attr_parsing/src/target_checking.rs | 6 ++- .../invalid-repr-simd-on-enum-148634.stderr | 4 +- tests/ui/asm/naked-with-invalid-repr-attr.rs | 3 +- .../asm/naked-with-invalid-repr-attr.stderr | 27 ++++++----- ...nline-and-repr-at-invalid-positions.stderr | 4 +- tests/ui/attributes/empty-repr.stderr | 4 +- tests/ui/attributes/invalid-repr.stderr | 4 +- tests/ui/attributes/malformed-fn-align.stderr | 4 +- .../attributes/malformed-static-align.stderr | 4 +- .../repr-align-in-trait-issue-132391.stderr | 4 +- ...id-attributes-on-const-params-78957.stderr | 12 ++--- tests/ui/enum-discriminant/eval-error.stderr | 4 +- .../feature-gate-repr-simd.stderr | 8 ++-- ...43106-gating-of-builtin-attrs-error.stderr | 44 +++++++++--------- .../layout/thaw-transmute-invalid-enum.stderr | 4 +- .../layout/thaw-validate-invalid-enum.stderr | 4 +- ...rop-unions-known-panics-lint-123710.stderr | 4 +- .../proc-macro/ambiguous-builtin-attrs.stderr | 8 ++-- tests/ui/repr/attr-usage-repr.rs | 2 +- tests/ui/repr/attr-usage-repr.stderr | 20 ++++---- .../ui/repr/invalid-repr-on-structs-74082.rs | 4 +- .../repr/invalid-repr-on-structs-74082.stderr | 8 ++-- tests/ui/repr/issue-83505-repr-simd.stderr | 4 +- tests/ui/repr/repr-disallow-on-variant.rs | 2 +- tests/ui/repr/repr-disallow-on-variant.stderr | 4 +- tests/ui/repr/repr-empty-packed.stderr | 4 +- .../repr/repr-transparent-other-items.stderr | 8 ++-- tests/ui/simd/repr-simd-on-enum.stderr | 4 +- 31 files changed, 133 insertions(+), 132 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 94391c33cf223..31a303ec53758 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -37,7 +37,7 @@ impl CombineAttributeParser for ReprParser { }; if list.is_empty() { - cx.check_target(&AllowedTargets::AllowList(&[ + cx.check_target("()", &AllowedTargets::AllowList(&[ Allow(Target::Struct), Allow(Target::Enum), Allow(Target::Union), @@ -70,8 +70,8 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< use ReprAttr::*; macro_rules! repr_int { - ($constructor: expr) => {{ - cx.check_target(&AllowedTargets::AllowList(&[ + ($arg: ident, $constructor: expr) => {{ + cx.check_target(concat!("(", stringify!($arg), ")"), &AllowedTargets::AllowList(&[ Allow(Target::Enum), Warn(Target::MacroCall), ])); @@ -82,7 +82,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< match param.path().word_sym() { Some(sym::align) => { - cx.check_target(&AllowedTargets::AllowList(&[ + cx.check_target("(align(...))", &AllowedTargets::AllowList(&[ Allow(Target::Struct), Allow(Target::Enum), Allow(Target::Union), @@ -92,7 +92,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< parse_repr_align(cx, l, AlignKind::Align) } Some(sym::packed) => { - cx.check_target(&AllowedTargets::AllowList(&[ + cx.check_target("(packed)", &AllowedTargets::AllowList(&[ Allow(Target::Struct), Allow(Target::Union), Warn(Target::MacroCall), @@ -108,7 +108,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< } Some(sym::Rust) => { - cx.check_target(&AllowedTargets::AllowList(&[ + cx.check_target("(Rust)",&AllowedTargets::AllowList(&[ Allow(Target::Struct), Allow(Target::Enum), Allow(Target::Union), @@ -118,7 +118,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< Some(ReprRust) } Some(sym::C) => { - cx.check_target(&AllowedTargets::AllowList(&[ + cx.check_target("(C)", &AllowedTargets::AllowList(&[ Allow(Target::Struct), Allow(Target::Enum), Allow(Target::Union), @@ -128,36 +128,36 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< Some(ReprC) } Some(sym::simd) => { - cx.check_target(&AllowedTargets::AllowList(&[ - Allow(Target::Struct), // Feature gated in `rustc_ast_passes` + cx.check_target("(simd)", &AllowedTargets::AllowList(&[ + Allow(Target::Struct), // Feature gated in `rustc_ast_passes` Warn(Target::MacroCall), // FIXME: This is not feature gated (!!) ])); cx.expect_no_args(param.args())?; Some(ReprSimd) } Some(sym::transparent) => { - cx.check_target(&AllowedTargets::AllowList(&[ + cx.check_target("(transparent)", &AllowedTargets::AllowList(&[ Allow(Target::Struct), Allow(Target::Enum), - Allow(Target::Union), + Allow(Target::Union), // Feature gated in `rustc_hir_analysis` Warn(Target::MacroCall), ])); cx.expect_no_args(param.args())?; Some(ReprTransparent) } - Some(sym::i8) => repr_int!(ReprInt(SignedInt(IntTy::I8))), - Some(sym::u8) => repr_int!(ReprInt(UnsignedInt(UintTy::U8))), - Some(sym::i16) => repr_int!(ReprInt(SignedInt(IntTy::I16))), - Some(sym::u16) => repr_int!(ReprInt(UnsignedInt(UintTy::U16))), - Some(sym::i32) => repr_int!(ReprInt(SignedInt(IntTy::I32))), - Some(sym::u32) => repr_int!(ReprInt(UnsignedInt(UintTy::U32))), - Some(sym::i64) => repr_int!(ReprInt(SignedInt(IntTy::I64))), - Some(sym::u64) => repr_int!(ReprInt(UnsignedInt(UintTy::U64))), - Some(sym::i128) => repr_int!(ReprInt(SignedInt(IntTy::I128))), - Some(sym::u128) => repr_int!(ReprInt(UnsignedInt(UintTy::U128))), - Some(sym::isize) => repr_int!(ReprInt(SignedInt(IntTy::Isize))), - Some(sym::usize) => repr_int!(ReprInt(UnsignedInt(UintTy::Usize))), + Some(sym::i8) => repr_int!(i8, ReprInt(SignedInt(IntTy::I8))), + Some(sym::u8) => repr_int!(u8, ReprInt(UnsignedInt(UintTy::U8))), + Some(sym::i16) => repr_int!(i16, ReprInt(SignedInt(IntTy::I16))), + Some(sym::u16) => repr_int!(u16, ReprInt(UnsignedInt(UintTy::U16))), + Some(sym::i32) => repr_int!(i32, ReprInt(SignedInt(IntTy::I32))), + Some(sym::u32) => repr_int!(u32, ReprInt(UnsignedInt(UintTy::U32))), + Some(sym::i64) => repr_int!(i64, ReprInt(SignedInt(IntTy::I64))), + Some(sym::u64) => repr_int!(u64, ReprInt(UnsignedInt(UintTy::U64))), + Some(sym::i128) => repr_int!(i128, ReprInt(SignedInt(IntTy::I128))), + Some(sym::u128) => repr_int!(u128, ReprInt(UnsignedInt(UintTy::U128))), + Some(sym::isize) => repr_int!(isize, ReprInt(SignedInt(IntTy::Isize))), + Some(sym::usize) => repr_int!(usize, ReprInt(UnsignedInt(UintTy::Usize))), _ => { cx.adcx().expected_specific_argument( param.span(), diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 86bf89dcb9585..e473942084e4e 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -415,7 +415,7 @@ impl<'sess> AttributeParser<'sess> { (accept.accept_fn)(&mut cx, &args); finalizers.push(accept.finalizer); - Self::check_target(&accept.allowed_targets, &mut cx); + Self::check_target(&accept.allowed_targets, "", &mut cx); #[cfg(debug_assertions)] if !cx.shared.has_lint_been_emitted.load(Ordering::Relaxed) { cx.shared.cx.check_args_used(&attr, &args) diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 2c28b5b2d8a5a..5d2c2a4d2bfb2 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -331,8 +331,8 @@ pub(crate) struct EmptyConfusables { } #[derive(Diagnostic)] -#[help("`#[{$name}]` can {$only}be applied to {$applied}")] -#[diag("`#[{$name}]` attribute cannot be used on {$target}")] +#[help("`#[{$name}{$attribute_args}]` can {$only}be applied to {$applied}")] +#[diag("`#[{$name}{$attribute_args}]` attribute cannot be used on {$target}")] pub(crate) struct InvalidTarget { #[primary_span] #[suggestion( @@ -346,6 +346,7 @@ pub(crate) struct InvalidTarget { pub target: &'static str, pub applied: DiagArgValue, pub only: &'static str, + pub attribute_args: &'static str, #[warning( "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" )] diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 5811bcf8c8a88..79fde116d382f 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -89,6 +89,7 @@ pub(crate) enum Policy { impl<'sess> AttributeParser<'sess> { pub(crate) fn check_target( allowed_targets: &AllowedTargets, + attribute_args: &'static str, cx: &mut AcceptContext<'_, 'sess>, ) { if matches!(cx.should_emit, ShouldEmit::Nothing) { @@ -115,6 +116,7 @@ impl<'sess> AttributeParser<'sess> { target: cx.target.plural_name(), only: if only { "only " } else { "" }, applied: DiagArgValue::StrListSepByAnd(applied.into_iter().map(Cow::Owned).collect()), + attribute_args, previously_accepted: matches!(result, AllowedResult::Warn), }; @@ -381,8 +383,8 @@ fn filter_targets( } impl<'f, 'sess> AcceptContext<'f, 'sess> { - pub(crate) fn check_target(&mut self, allowed_targets: &AllowedTargets) { - AttributeParser::check_target(allowed_targets, self); + pub(crate) fn check_target(&mut self, attribute_args: &'static str, allowed_targets: &AllowedTargets) { + AttributeParser::check_target(allowed_targets, attribute_args, self); } } diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr index 4099dd9bcd01b..29e30bd7c5078 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(simd)]` attribute cannot be used on enums --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to structs + = help: `#[repr(simd)]` can only be applied to structs error[E0084]: unsupported representation for zero-variant enum --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8 diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.rs b/tests/ui/asm/naked-with-invalid-repr-attr.rs index 85e014ec9734e..333fb0c4e544d 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.rs +++ b/tests/ui/asm/naked-with-invalid-repr-attr.rs @@ -33,14 +33,13 @@ extern "C" fn example3() { #[repr(C, packed)] //~^ ERROR attribute cannot be used on //~| ERROR attribute cannot be used on -//~| NOTE duplicate diagnostic emitted due to #[unsafe(naked)] extern "C" fn example4() { naked_asm!("") } #[repr(u8)] -//~^ ERROR `#[repr]` attribute cannot be used on +//~^ ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example5() { naked_asm!("") diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.stderr b/tests/ui/asm/naked-with-invalid-repr-attr.stderr index 4d0bb41d644a2..f98feb5e34b70 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.stderr +++ b/tests/ui/asm/naked-with-invalid-repr-attr.stderr @@ -1,51 +1,50 @@ -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(C)]` attribute cannot be used on functions --> $DIR/naked-with-invalid-repr-attr.rs:10:1 | LL | #[repr(C)] | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(transparent)]` attribute cannot be used on functions --> $DIR/naked-with-invalid-repr-attr.rs:17:1 | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(transparent)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(C)]` attribute cannot be used on functions --> $DIR/naked-with-invalid-repr-attr.rs:24:1 | LL | #[repr(C)] | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(C)]` attribute cannot be used on functions --> $DIR/naked-with-invalid-repr-attr.rs:33:1 | LL | #[repr(C, packed)] | ^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(packed)]` attribute cannot be used on functions --> $DIR/naked-with-invalid-repr-attr.rs:33:1 | LL | #[repr(C, packed)] | ^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = help: `#[repr(packed)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions - --> $DIR/naked-with-invalid-repr-attr.rs:42:1 +error: `#[repr(u8)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:41:1 | LL | #[repr(u8)] | ^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to enums + = help: `#[repr(u8)]` can only be applied to enums error: aborting due to 6 previous errors diff --git a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr index 2cff227793dfb..0f03232cd5cc6 100644 --- a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr @@ -6,13 +6,13 @@ LL | #[inline] struct Foo; | = help: `#[inline]` can only be applied to functions -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(C)]` attribute cannot be used on functions --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:4:5 | LL | #[repr(C)] fn foo() {} | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types error: aborting due to 2 previous errors diff --git a/tests/ui/attributes/empty-repr.stderr b/tests/ui/attributes/empty-repr.stderr index bc99469477604..5ef0f4c6d652c 100644 --- a/tests/ui/attributes/empty-repr.stderr +++ b/tests/ui/attributes/empty-repr.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on where predicates +error: `#[repr()]` attribute cannot be used on where predicates --> $DIR/empty-repr.rs:10:1 | LL | #[repr()] | ^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr()]` can only be applied to data types error: unused attribute --> $DIR/empty-repr.rs:10:1 diff --git a/tests/ui/attributes/invalid-repr.stderr b/tests/ui/attributes/invalid-repr.stderr index 3d23f92d6cf49..4eadc9cc16f87 100644 --- a/tests/ui/attributes/invalid-repr.stderr +++ b/tests/ui/attributes/invalid-repr.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on type aliases +error: `#[repr(align(...))]` attribute cannot be used on type aliases --> $DIR/invalid-repr.rs:1:1 | LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(align(...))]` can only be applied to data types error: aborting due to 1 previous error diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr index 84ca5ae4c87de..4d6e023fb5259 100644 --- a/tests/ui/attributes/malformed-fn-align.stderr +++ b/tests/ui/attributes/malformed-fn-align.stderr @@ -49,13 +49,13 @@ error[E0589]: invalid alignment value: not a power of two LL | #[rustc_align(0)] | ^ -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(align(...))]` attribute cannot be used on functions --> $DIR/malformed-fn-align.rs:26:1 | LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(align(...))]` can only be applied to data types error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression --> $DIR/malformed-fn-align.rs:29:15 diff --git a/tests/ui/attributes/malformed-static-align.stderr b/tests/ui/attributes/malformed-static-align.stderr index 0efa79660c0a6..76c07f798714c 100644 --- a/tests/ui/attributes/malformed-static-align.stderr +++ b/tests/ui/attributes/malformed-static-align.stderr @@ -24,13 +24,13 @@ error[E0589]: invalid alignment value: not a power of two LL | #[rustc_align_static(0)] | ^ -error: `#[repr]` attribute cannot be used on statics +error: `#[repr(align(...))]` attribute cannot be used on statics --> $DIR/malformed-static-align.rs:13:1 | LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(align(...))]` can only be applied to data types error: `#[rustc_align_static]` attribute cannot be used on structs --> $DIR/malformed-static-align.rs:16:1 diff --git a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr index 0d0b757fd4f48..3d3af82d6dbd1 100644 --- a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr +++ b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on required trait methods +error: `#[repr(align(...))]` attribute cannot be used on required trait methods --> $DIR/repr-align-in-trait-issue-132391.rs:2:5 | LL | #[repr(align)] | ^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(align(...))]` can only be applied to data types error[E0539]: malformed `repr` attribute input --> $DIR/repr-align-in-trait-issue-132391.rs:2:5 diff --git a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr index 04640549bf747..cbf9a5a03f881 100644 --- a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr +++ b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr @@ -6,13 +6,13 @@ LL | pub struct Foo<#[inline] const N: usize>; | = help: `#[inline]` can only be applied to functions -error: `#[repr]` attribute cannot be used on const parameters +error: `#[repr(C)]` attribute cannot be used on const parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:11:16 | LL | pub struct Baz<#[repr(C)] const N: usize>; | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types error: `#[inline]` attribute cannot be used on lifetime parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:14:17 @@ -22,13 +22,13 @@ LL | pub struct Foo2<#[inline] 'a>(PhantomData<&'a ()>); | = help: `#[inline]` can only be applied to functions -error: `#[repr]` attribute cannot be used on lifetime parameters +error: `#[repr(C)]` attribute cannot be used on lifetime parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:19:17 | LL | pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types error: `#[inline]` attribute cannot be used on type parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:22:17 @@ -38,13 +38,13 @@ LL | pub struct Foo3<#[inline] T>(PhantomData); | = help: `#[inline]` can only be applied to functions -error: `#[repr]` attribute cannot be used on type parameters +error: `#[repr(C)]` attribute cannot be used on type parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:27:17 | LL | pub struct Baz3<#[repr(C)] T>(PhantomData); | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types error: `#[cold]` attribute cannot be used on const parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:8:16 diff --git a/tests/ui/enum-discriminant/eval-error.stderr b/tests/ui/enum-discriminant/eval-error.stderr index 858560602d3c9..d355ac3ec04b0 100644 --- a/tests/ui/enum-discriminant/eval-error.stderr +++ b/tests/ui/enum-discriminant/eval-error.stderr @@ -4,13 +4,13 @@ error: unions cannot have zero fields LL | union Foo2 {} | ^^^^^^^^^^^^^ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(packed)]` attribute cannot be used on enums --> $DIR/eval-error.rs:24:1 | LL | #[repr(u8, packed)] | ^^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can be applied to structs and unions + = help: `#[repr(packed)]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/eval-error.rs:2:5 diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.stderr b/tests/ui/feature-gates/feature-gate-repr-simd.stderr index 7526db1525868..1eab0a04988a5 100644 --- a/tests/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/tests/ui/feature-gates/feature-gate-repr-simd.stderr @@ -38,21 +38,21 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: `#[repr]` attribute cannot be used on unions +error: `#[repr(simd)]` attribute cannot be used on unions --> $DIR/feature-gate-repr-simd.rs:9:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to structs + = help: `#[repr(simd)]` can only be applied to structs -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(simd)]` attribute cannot be used on enums --> $DIR/feature-gate-repr-simd.rs:13:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to structs + = help: `#[repr(simd)]` can only be applied to structs error[E0566]: conflicting representation hints --> $DIR/feature-gate-repr-simd.rs:4:8 diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 95510b940ef1d..7d252af4f94fe 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -24,13 +24,13 @@ LL | #![rustc_main] | = help: `#[rustc_main]` can only be applied to functions -error: `#[repr]` attribute cannot be used on crates +error: `#[repr()]` attribute cannot be used on crates --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1 | LL | #![repr()] | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr()]` can only be applied to data types error: `#[path]` attribute cannot be used on crates --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1 @@ -208,85 +208,85 @@ LL | #[export_name = "2200"] fn foo(); | = help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks -error: `#[repr]` attribute cannot be used on modules +error: `#[repr(C)]` attribute cannot be used on modules --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:121:1 | LL | #[repr(C)] | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on modules +error: `#[repr(C)]` attribute cannot be used on modules --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:124:17 | LL | mod inner { #![repr(C)] } | ^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(C)]` attribute cannot be used on functions --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:5 | LL | #[repr(C)] fn f() { } | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on type aliases +error: `#[repr(C)]` attribute cannot be used on type aliases --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:132:5 | LL | #[repr(C)] type T = S; | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on inherent impl blocks +error: `#[repr(C)]` attribute cannot be used on inherent impl blocks --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:135:5 | LL | #[repr(C)] impl S { } | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on modules +error: `#[repr(Rust)]` attribute cannot be used on modules --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:140:1 | LL | #[repr(Rust)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(Rust)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on modules +error: `#[repr(Rust)]` attribute cannot be used on modules --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:143:17 | LL | mod inner { #![repr(Rust)] } | ^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(Rust)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(Rust)]` attribute cannot be used on functions --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:146:5 | LL | #[repr(Rust)] fn f() { } | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(Rust)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on type aliases +error: `#[repr(Rust)]` attribute cannot be used on type aliases --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:5 | LL | #[repr(Rust)] type T = S; | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(Rust)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on inherent impl blocks +error: `#[repr(Rust)]` attribute cannot be used on inherent impl blocks --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:154:5 | LL | #[repr(Rust)] impl S { } | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(Rust)]` can only be applied to data types warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]` --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1 diff --git a/tests/ui/layout/thaw-transmute-invalid-enum.stderr b/tests/ui/layout/thaw-transmute-invalid-enum.stderr index 83785176000a1..7732e21409fc4 100644 --- a/tests/ui/layout/thaw-transmute-invalid-enum.stderr +++ b/tests/ui/layout/thaw-transmute-invalid-enum.stderr @@ -9,13 +9,13 @@ help: you might be missing a type parameter LL | fn test() { | ++++++++ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(packed)]` attribute cannot be used on enums --> $DIR/thaw-transmute-invalid-enum.rs:22:1 | LL | #[repr(C, packed(2))] | ^^^^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can be applied to structs and unions + = help: `#[repr(packed)]` can be applied to structs and unions error[E0658]: use of unstable library feature `transmutability` --> $DIR/thaw-transmute-invalid-enum.rs:4:20 diff --git a/tests/ui/layout/thaw-validate-invalid-enum.stderr b/tests/ui/layout/thaw-validate-invalid-enum.stderr index c41130e803945..c7076d9162ea1 100644 --- a/tests/ui/layout/thaw-validate-invalid-enum.stderr +++ b/tests/ui/layout/thaw-validate-invalid-enum.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(packed)]` attribute cannot be used on enums --> $DIR/thaw-validate-invalid-enum.rs:3:1 | LL | #[repr(packed)] | ^^^^^^^^^^^^^^^ | - = help: `#[repr]` can be applied to structs and unions + = help: `#[repr(packed)]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/thaw-validate-invalid-enum.rs:14:9 diff --git a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr index de12a4d04d9b4..4aff0575e5f56 100644 --- a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr +++ b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(packed)]` attribute cannot be used on enums --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:1 | LL | #[repr(packed)] | ^^^^^^^^^^^^^^^ | - = help: `#[repr]` can be applied to structs and unions + = help: `#[repr(packed)]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:18:9 diff --git a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr index 38e0589ef03a2..f14acd1b78532 100644 --- a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr +++ b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr @@ -94,21 +94,21 @@ LL | use builtin_attrs::*; | ^^^^^^^^^^^^^^^^ = help: use `crate::feature` to refer to this attribute macro unambiguously -error: `#[repr]` attribute cannot be used on match arms +error: `#[repr(C)]` attribute cannot be used on match arms --> $DIR/ambiguous-builtin-attrs.rs:25:9 | LL | #[repr(C)] | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on type parameters +error: `#[repr(C)]` attribute cannot be used on type parameters --> $DIR/ambiguous-builtin-attrs.rs:21:32 | LL | fn non_macro_expanded_location<#[repr(C)] T>() { | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types error: aborting due to 9 previous errors diff --git a/tests/ui/repr/attr-usage-repr.rs b/tests/ui/repr/attr-usage-repr.rs index 510ff8a89668d..ecb2be07bc587 100644 --- a/tests/ui/repr/attr-usage-repr.rs +++ b/tests/ui/repr/attr-usage-repr.rs @@ -12,7 +12,7 @@ struct SPacked(f64, f64); #[repr(simd)] struct SSimd([f64; 2]); -#[repr(i8)] //~ ERROR: `#[repr]` attribute cannot be used on +#[repr(i8)] //~ ERROR: attribute cannot be used on struct SInt(f64, f64); #[repr(C)] diff --git a/tests/ui/repr/attr-usage-repr.stderr b/tests/ui/repr/attr-usage-repr.stderr index d6ad67a315319..5511f90582d66 100644 --- a/tests/ui/repr/attr-usage-repr.stderr +++ b/tests/ui/repr/attr-usage-repr.stderr @@ -1,42 +1,42 @@ -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(C)]` attribute cannot be used on functions --> $DIR/attr-usage-repr.rs:3:1 | LL | #[repr(C)] | ^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(C)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on structs +error: `#[repr(i8)]` attribute cannot be used on structs --> $DIR/attr-usage-repr.rs:15:1 | LL | #[repr(i8)] | ^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to enums + = help: `#[repr(i8)]` can only be applied to enums -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(packed)]` attribute cannot be used on enums --> $DIR/attr-usage-repr.rs:30:1 | LL | #[repr(packed)] | ^^^^^^^^^^^^^^^ | - = help: `#[repr]` can be applied to structs and unions + = help: `#[repr(packed)]` can be applied to structs and unions -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(simd)]` attribute cannot be used on enums --> $DIR/attr-usage-repr.rs:36:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to structs + = help: `#[repr(simd)]` can only be applied to structs -error: `#[repr]` attribute cannot be used on type aliases +error: `#[repr()]` attribute cannot be used on type aliases --> $DIR/attr-usage-repr.rs:48:1 | LL | #[repr()] | ^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr()]` can only be applied to data types warning: unused attribute --> $DIR/attr-usage-repr.rs:48:1 diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.rs b/tests/ui/repr/invalid-repr-on-structs-74082.rs index 4887666bf0174..776c87a877d39 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.rs +++ b/tests/ui/repr/invalid-repr-on-structs-74082.rs @@ -1,10 +1,10 @@ // https://github.com/rust-lang/rust/issues/74082 #![allow(dead_code)] -#[repr(i128)] //~ ERROR: `#[repr]` attribute cannot be used on +#[repr(i128)] //~ ERROR: attribute cannot be used on struct Foo; -#[repr(u128)] //~ ERROR: `#[repr]` attribute cannot be used on +#[repr(u128)] //~ ERROR: attribute cannot be used on struct Bar; fn main() {} diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.stderr b/tests/ui/repr/invalid-repr-on-structs-74082.stderr index 6ffde26b8edea..a9dc539f62ce6 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.stderr +++ b/tests/ui/repr/invalid-repr-on-structs-74082.stderr @@ -1,18 +1,18 @@ -error: `#[repr]` attribute cannot be used on structs +error: `#[repr(i128)]` attribute cannot be used on structs --> $DIR/invalid-repr-on-structs-74082.rs:4:1 | LL | #[repr(i128)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to enums + = help: `#[repr(i128)]` can only be applied to enums -error: `#[repr]` attribute cannot be used on structs +error: `#[repr(u128)]` attribute cannot be used on structs --> $DIR/invalid-repr-on-structs-74082.rs:7:1 | LL | #[repr(u128)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to enums + = help: `#[repr(u128)]` can only be applied to enums error: aborting due to 2 previous errors diff --git a/tests/ui/repr/issue-83505-repr-simd.stderr b/tests/ui/repr/issue-83505-repr-simd.stderr index b074ba93e4932..4694fa770b6c2 100644 --- a/tests/ui/repr/issue-83505-repr-simd.stderr +++ b/tests/ui/repr/issue-83505-repr-simd.stderr @@ -16,13 +16,13 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(simd)]` attribute cannot be used on enums --> $DIR/issue-83505-repr-simd.rs:5:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to structs + = help: `#[repr(simd)]` can only be applied to structs error[E0084]: unsupported representation for zero-variant enum --> $DIR/issue-83505-repr-simd.rs:5:8 diff --git a/tests/ui/repr/repr-disallow-on-variant.rs b/tests/ui/repr/repr-disallow-on-variant.rs index 8a16905d4b7b4..384a1701c11de 100644 --- a/tests/ui/repr/repr-disallow-on-variant.rs +++ b/tests/ui/repr/repr-disallow-on-variant.rs @@ -2,7 +2,7 @@ struct Test; enum Foo { #[repr(u8)] - //~^ ERROR `#[repr]` attribute cannot be used on + //~^ ERROR attribute cannot be used on Variant, } diff --git a/tests/ui/repr/repr-disallow-on-variant.stderr b/tests/ui/repr/repr-disallow-on-variant.stderr index ab96e45e343f3..39556fb589b5d 100644 --- a/tests/ui/repr/repr-disallow-on-variant.stderr +++ b/tests/ui/repr/repr-disallow-on-variant.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on enum variants +error: `#[repr(u8)]` attribute cannot be used on enum variants --> $DIR/repr-disallow-on-variant.rs:4:5 | LL | #[repr(u8)] | ^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to enums + = help: `#[repr(u8)]` can only be applied to enums error: aborting due to 1 previous error diff --git a/tests/ui/repr/repr-empty-packed.stderr b/tests/ui/repr/repr-empty-packed.stderr index 6a3b14f5906d0..903a5ff6fea21 100644 --- a/tests/ui/repr/repr-empty-packed.stderr +++ b/tests/ui/repr/repr-empty-packed.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(packed)]` attribute cannot be used on enums --> $DIR/repr-empty-packed.rs:5:1 | LL | #[repr(packed)] | ^^^^^^^^^^^^^^^ | - = help: `#[repr]` can be applied to structs and unions + = help: `#[repr(packed)]` can be applied to structs and unions error: unused attribute --> $DIR/repr-empty-packed.rs:4:1 diff --git a/tests/ui/repr/repr-transparent-other-items.stderr b/tests/ui/repr/repr-transparent-other-items.stderr index a768c321ef101..ddab462eb162f 100644 --- a/tests/ui/repr/repr-transparent-other-items.stderr +++ b/tests/ui/repr/repr-transparent-other-items.stderr @@ -1,18 +1,18 @@ -error: `#[repr]` attribute cannot be used on functions +error: `#[repr(transparent)]` attribute cannot be used on functions --> $DIR/repr-transparent-other-items.rs:3:1 | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(transparent)]` can only be applied to data types -error: `#[repr]` attribute cannot be used on statics +error: `#[repr(transparent)]` attribute cannot be used on statics --> $DIR/repr-transparent-other-items.rs:6:1 | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to data types + = help: `#[repr(transparent)]` can only be applied to data types error: aborting due to 2 previous errors diff --git a/tests/ui/simd/repr-simd-on-enum.stderr b/tests/ui/simd/repr-simd-on-enum.stderr index 2711c99a90cfb..5edbcb71be6a0 100644 --- a/tests/ui/simd/repr-simd-on-enum.stderr +++ b/tests/ui/simd/repr-simd-on-enum.stderr @@ -1,10 +1,10 @@ -error: `#[repr]` attribute cannot be used on enums +error: `#[repr(simd)]` attribute cannot be used on enums --> $DIR/repr-simd-on-enum.rs:5:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ | - = help: `#[repr]` can only be applied to structs + = help: `#[repr(simd)]` can only be applied to structs error: aborting due to 1 previous error From a78d21887ce5df2da769e523501f0c9214422367 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sun, 31 May 2026 21:02:00 +0200 Subject: [PATCH 3/5] Re-add hints for `rustc_align` --- .../rustc_attr_parsing/src/attributes/repr.rs | 107 +++++++++++------- .../src/session_diagnostics.rs | 10 ++ .../rustc_attr_parsing/src/target_checking.rs | 27 ++++- tests/ui/attributes/malformed-attrs.stderr | 11 +- tests/ui/attributes/malformed-fn-align.stderr | 1 + .../attributes/malformed-static-align.stderr | 1 + 6 files changed, 102 insertions(+), 55 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 31a303ec53758..8b187a65419fe 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -37,12 +37,15 @@ impl CombineAttributeParser for ReprParser { }; if list.is_empty() { - cx.check_target("()", &AllowedTargets::AllowList(&[ - Allow(Target::Struct), - Allow(Target::Enum), - Allow(Target::Union), - Warn(Target::MacroCall), - ])); + cx.check_target( + "()", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); let attr_span = cx.attr_span; cx.adcx().warn_empty_attribute(attr_span); @@ -71,10 +74,10 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< macro_rules! repr_int { ($arg: ident, $constructor: expr) => {{ - cx.check_target(concat!("(", stringify!($arg), ")"), &AllowedTargets::AllowList(&[ - Allow(Target::Enum), - Warn(Target::MacroCall), - ])); + cx.check_target( + concat!("(", stringify!($arg), ")"), + &AllowedTargets::AllowList(&[Allow(Target::Enum), Warn(Target::MacroCall)]), + ); cx.expect_no_args(param.args())?; Some($constructor) }}; @@ -82,21 +85,27 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< match param.path().word_sym() { Some(sym::align) => { - cx.check_target("(align(...))", &AllowedTargets::AllowList(&[ - Allow(Target::Struct), - Allow(Target::Enum), - Allow(Target::Union), - Warn(Target::MacroCall), - ])); + cx.check_target( + "(align(...))", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); let l = cx.expect_list(param.args(), param.span())?; parse_repr_align(cx, l, AlignKind::Align) } Some(sym::packed) => { - cx.check_target("(packed)", &AllowedTargets::AllowList(&[ - Allow(Target::Struct), - Allow(Target::Union), - Warn(Target::MacroCall), - ])); + cx.check_target( + "(packed)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); match param.args() { ArgParser::NoArgs => Some(ReprPacked(Align::ONE)), ArgParser::List(l) => parse_repr_align(cx, l, AlignKind::Packed), @@ -108,40 +117,52 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< } Some(sym::Rust) => { - cx.check_target("(Rust)",&AllowedTargets::AllowList(&[ - Allow(Target::Struct), - Allow(Target::Enum), - Allow(Target::Union), - Warn(Target::MacroCall), - ])); + cx.check_target( + "(Rust)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); cx.expect_no_args(param.args())?; Some(ReprRust) } Some(sym::C) => { - cx.check_target("(C)", &AllowedTargets::AllowList(&[ - Allow(Target::Struct), - Allow(Target::Enum), - Allow(Target::Union), - Warn(Target::MacroCall), - ])); + cx.check_target( + "(C)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); cx.expect_no_args(param.args())?; Some(ReprC) } Some(sym::simd) => { - cx.check_target("(simd)", &AllowedTargets::AllowList(&[ - Allow(Target::Struct), // Feature gated in `rustc_ast_passes` - Warn(Target::MacroCall), // FIXME: This is not feature gated (!!) - ])); + cx.check_target( + "(simd)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), // Feature gated in `rustc_ast_passes` + Warn(Target::MacroCall), // FIXME: This is not feature gated (!!) + ]), + ); cx.expect_no_args(param.args())?; Some(ReprSimd) } Some(sym::transparent) => { - cx.check_target("(transparent)", &AllowedTargets::AllowList(&[ - Allow(Target::Struct), - Allow(Target::Enum), - Allow(Target::Union), // Feature gated in `rustc_hir_analysis` - Warn(Target::MacroCall), - ])); + cx.check_target( + "(transparent)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), // Feature gated in `rustc_hir_analysis` + Warn(Target::MacroCall), + ]), + ); cx.expect_no_args(param.args())?; Some(ReprTransparent) } diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 5d2c2a4d2bfb2..1d4d8d8123633 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -347,12 +347,22 @@ pub(crate) struct InvalidTarget { pub applied: DiagArgValue, pub only: &'static str, pub attribute_args: &'static str, + #[subdiagnostic] + pub help: Option, #[warning( "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" )] pub previously_accepted: bool, } +#[derive(Subdiagnostic)] +pub(crate) enum InvalidTargetHelp { + #[help("use `#[rustc_align(...)]` instead")] + UseRustcAlign, + #[help("use `#[rustc_align_static(...)]` instead")] + UseRustcAlignStatic, +} + #[derive(Diagnostic)] #[diag("invalid alignment value: {$error_part}", code = E0589)] pub(crate) struct InvalidAlignmentValue { diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 79fde116d382f..30a7133caa15e 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -11,7 +11,7 @@ use crate::context::AcceptContext; use crate::errors::{ InvalidAttrAtCrateLevel, ItemFollowingInnerAttr, UnsupportedAttributesInWhere, }; -use crate::session_diagnostics::InvalidTarget; +use crate::session_diagnostics::{InvalidTarget, InvalidTargetHelp}; use crate::target_checking::Policy::Allow; use crate::{AttributeParser, ShouldEmit}; @@ -117,6 +117,7 @@ impl<'sess> AttributeParser<'sess> { only: if only { "only " } else { "" }, applied: DiagArgValue::StrListSepByAnd(applied.into_iter().map(Cow::Owned).collect()), attribute_args, + help: Self::target_checking_help(attribute_args, cx), previously_accepted: matches!(result, AllowedResult::Warn), }; @@ -147,6 +148,24 @@ impl<'sess> AttributeParser<'sess> { } } + fn target_checking_help( + attribute_args: &'static str, + cx: &AcceptContext<'_, '_>, + ) -> Option { + match &*cx.attr_path.segments { + [sym::repr] if attribute_args == "(align(...))" => match cx.target { + Target::Fn | Target::Method(..) if cx.features().fn_align() => { + Some(InvalidTargetHelp::UseRustcAlign) + } + Target::Static if cx.features().static_align() => { + Some(InvalidTargetHelp::UseRustcAlignStatic) + } + _ => None, + }, + _ => None, + } + } + pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>) { if cx.target == Target::Crate { return; @@ -383,7 +402,11 @@ fn filter_targets( } impl<'f, 'sess> AcceptContext<'f, 'sess> { - pub(crate) fn check_target(&mut self, attribute_args: &'static str, allowed_targets: &AllowedTargets) { + pub(crate) fn check_target( + &mut self, + attribute_args: &'static str, + allowed_targets: &AllowedTargets, + ) { AttributeParser::check_target(allowed_targets, attribute_args, self); } } diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index 1463098fc25ec..4026c49295138 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -126,15 +126,6 @@ error: the `#[proc_macro_derive]` attribute is only usable with crates of the `p LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ -error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint - --> $DIR/malformed-attrs.rs:214:1 - | -LL | #[allow_internal_unsafe = 1] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(allow_internal_unsafe)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error[E0539]: malformed `windows_subsystem` attribute input --> $DIR/malformed-attrs.rs:26:1 | @@ -789,7 +780,7 @@ LL + #[macro_export] | error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint - --> $DIR/malformed-attrs.rs:215:1 + --> $DIR/malformed-attrs.rs:214:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr index 4d6e023fb5259..59cab345c9b7a 100644 --- a/tests/ui/attributes/malformed-fn-align.stderr +++ b/tests/ui/attributes/malformed-fn-align.stderr @@ -56,6 +56,7 @@ LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^^^^ | = help: `#[repr(align(...))]` can only be applied to data types + = help: use `#[rustc_align(...)]` instead error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression --> $DIR/malformed-fn-align.rs:29:15 diff --git a/tests/ui/attributes/malformed-static-align.stderr b/tests/ui/attributes/malformed-static-align.stderr index 76c07f798714c..dd449f56ac005 100644 --- a/tests/ui/attributes/malformed-static-align.stderr +++ b/tests/ui/attributes/malformed-static-align.stderr @@ -31,6 +31,7 @@ LL | #[repr(align(16))] | ^^^^^^^^^^^^^^^^^^ | = help: `#[repr(align(...))]` can only be applied to data types + = help: use `#[rustc_align_static(...)]` instead error: `#[rustc_align_static]` attribute cannot be used on structs --> $DIR/malformed-static-align.rs:16:1 From 80d33c74c24724c40a756521bad2693f4b3c5f8b Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sun, 31 May 2026 21:15:41 +0200 Subject: [PATCH 4/5] Add debug assertion to ensure target checking is not missed --- .../rustc_attr_parsing/src/attributes/repr.rs | 4 +--- compiler/rustc_attr_parsing/src/context.rs | 4 ++++ compiler/rustc_attr_parsing/src/interface.rs | 4 ++++ .../rustc_attr_parsing/src/target_checking.rs | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 8b187a65419fe..b6e63de1a2095 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -63,9 +63,7 @@ impl CombineAttributeParser for ReprParser { reprs } - //FIXME Still checked fully in `check_attr.rs` - //This one is slightly more complicated because the allowed targets depend on the arguments - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::ManuallyChecked; const STABILITY: AttributeStability = AttributeStability::Stable; } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 61d7f5dc5687a..8d56717be48aa 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -366,6 +366,10 @@ pub struct AcceptContext<'f, 'sess> { /// The name of the attribute we're currently accepting. pub(crate) attr_path: AttrPath, + + /// Used for `AllowedTargets::ManuallyChecked`, to assert that the manual target check has been done + #[cfg(debug_assertions)] + pub(crate) has_target_been_checked: bool, } impl<'f, 'sess: 'f> SharedContext<'f, 'sess> { diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index e473942084e4e..6e63bf2d78fdc 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -240,6 +240,8 @@ impl<'sess> AttributeParser<'sess> { template, attr_safety: attr_safety.unwrap_or(Safety::Default), attr_path, + #[cfg(debug_assertions)] + has_target_been_checked: false, }; parse_fn(&mut cx, args) } @@ -410,6 +412,8 @@ impl<'sess> AttributeParser<'sess> { template: &accept.template, attr_safety: n.item.unsafety, attr_path: attr_path.clone(), + #[cfg(debug_assertions)] + has_target_been_checked: false, }; (accept.accept_fn)(&mut cx, &args); diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 30a7133caa15e..bd592b68dc79e 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -19,6 +19,10 @@ use crate::{AttributeParser, ShouldEmit}; pub(crate) enum AllowedTargets { AllowList(&'static [Policy]), AllowListWarnRest(&'static [Policy]), + /// This is useful for argument-dependent target checking. + /// If debug assertions are enabled, + /// this emits a delayed bug if the `cx.check_target(...)` method is not called during attribute parsing. + ManuallyChecked, } pub(crate) enum AllowedResult { @@ -52,6 +56,7 @@ impl AllowedTargets { AllowedResult::Warn } } + AllowedTargets::ManuallyChecked => unreachable!(), } } @@ -59,6 +64,7 @@ impl AllowedTargets { match self { AllowedTargets::AllowList(list) => list, AllowedTargets::AllowListWarnRest(list) => list, + AllowedTargets::ManuallyChecked => unreachable!(), } .iter() .filter_map(|target| match target { @@ -96,6 +102,15 @@ impl<'sess> AttributeParser<'sess> { return; } + if let AllowedTargets::ManuallyChecked = allowed_targets { + #[cfg(debug_assertions)] + if !cx.has_target_been_checked { + cx.dcx().delayed_bug("Attribute target has not been checked"); + } + + return; + } + // For crate-level attributes we emit a specific set of lints to warn // people about accidentally not using them on the crate. if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets { @@ -407,6 +422,10 @@ impl<'f, 'sess> AcceptContext<'f, 'sess> { attribute_args: &'static str, allowed_targets: &AllowedTargets, ) { + #[cfg(debug_assertions)] + { + self.has_target_been_checked = true; + } AttributeParser::check_target(allowed_targets, attribute_args, self); } } From 79e666b885a9afac4f22b19164d9dfde778f168d Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sun, 31 May 2026 21:24:18 +0200 Subject: [PATCH 5/5] Add regression test for repr on mac call --- tests/ui/attributes/attr-on-mac-call.rs | 30 +++++++++ tests/ui/attributes/attr-on-mac-call.stderr | 73 ++++++++++++++++++++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/tests/ui/attributes/attr-on-mac-call.rs b/tests/ui/attributes/attr-on-mac-call.rs index 577272a99a0d9..2498682503e6b 100644 --- a/tests/ui/attributes/attr-on-mac-call.rs +++ b/tests/ui/attributes/attr-on-mac-call.rs @@ -70,4 +70,34 @@ fn main() { //~^ WARN attribute cannot be used on macro calls //~| WARN previously accepted unreachable!(); + + #[repr()] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + //~| WARN unused attribute + unreachable!(); + #[repr(u8)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(align(8))] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(packed)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(C)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(Rust)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(simd)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); } diff --git a/tests/ui/attributes/attr-on-mac-call.stderr b/tests/ui/attributes/attr-on-mac-call.stderr index 1171d4ff96f94..5881685313e96 100644 --- a/tests/ui/attributes/attr-on-mac-call.stderr +++ b/tests/ui/attributes/attr-on-mac-call.stderr @@ -201,5 +201,76 @@ LL | #[should_panic] = help: `#[should_panic]` can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -warning: 22 warnings emitted +warning: `#[repr()]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:74:5 + | +LL | #[repr()] + | ^^^^^^^^^ + | + = help: `#[repr()]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: unused attribute + --> $DIR/attr-on-mac-call.rs:74:5 + | +LL | #[repr()] + | ^^^^^^^^^ help: remove this attribute + | + = note: using `repr` with an empty list has no effect + +warning: `#[repr(u8)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:79:5 + | +LL | #[repr(u8)] + | ^^^^^^^^^^^ + | + = help: `#[repr(u8)]` can only be applied to enums + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(align(...))]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:83:5 + | +LL | #[repr(align(8))] + | ^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(align(...))]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(packed)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:87:5 + | +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(C)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:91:5 + | +LL | #[repr(C)] + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(Rust)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:95:5 + | +LL | #[repr(Rust)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(simd)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:99:5 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: 30 warnings emitted