diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 8f908cf96c8c1..80d8167765322 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -271,6 +271,30 @@ declare_lint! { }; } +declare_lint! { + /// The `repeated_reprs` lint detects when the same representation is + /// specified more than once in a `#[repr(..)]` attribute. + /// + /// ### Example + /// + /// ```rust + /// #[repr(C)] + /// #[repr(C)] + /// enum Foo { A } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// While some representations may be specified more than once, the compiler + /// will reject repeated uses of some others. For consistency, prefer to + /// only specify the representation once. + pub REPEATED_REPRS, + Warn, + "detects repeated representations in `#[repr(..)]` attributes", +} + declare_lint! { /// The `meta_variable_misuse` lint detects possible meta-variable misuse /// in macro definitions. diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d698a7ed4127a..2b2477df527c7 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -40,7 +40,7 @@ use rustc_session::errors::feature_err; use rustc_session::lint; use rustc_session::lint::builtin::{ CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, - MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES, + MISPLACED_DIAGNOSTIC_ATTRIBUTES, REPEATED_REPRS, UNUSED_ATTRIBUTES, }; use rustc_span::edition::Edition; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym}; @@ -1212,24 +1212,59 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let mut is_c = false; let mut is_simd = false; let mut is_transparent = false; + let mut is_align = false; + let mut is_packed = false; + let mut repeated_repr = false; + let mut maybe_last_int_type = None; for (repr, _repr_span) in reprs { match repr { ReprAttr::ReprRust => { + if is_explicit_rust { + repeated_repr = true; + } is_explicit_rust = true; } ReprAttr::ReprC => { + if is_c { + repeated_repr = true; + } is_c = true; } - ReprAttr::ReprAlign(..) => {} - ReprAttr::ReprPacked(_) => {} + ReprAttr::ReprAlign(..) => { + if is_align { + repeated_repr = true; + } + is_align = true; + } + ReprAttr::ReprPacked(..) => { + if is_packed { + repeated_repr = true; + } + is_packed = true; + } ReprAttr::ReprSimd => { + if is_simd { + repeated_repr = true; + } is_simd = true; } ReprAttr::ReprTransparent => { + // No need to check for repeated transparent because that is already checked + // when checking for any other attribute together with transparent. is_transparent = true; } - ReprAttr::ReprInt(_) => { + ReprAttr::ReprInt(int_type) => { + if let Some(last_int_type) = maybe_last_int_type + && last_int_type == int_type + { + // We'll "miss" detecting repeated int reprs if the user specifies + // #[repr(u8, u64, u8)] for example. But that's okay because we've got + // conflicting reprs anyway so it's not worth the effort to do more precise + // tracking. + repeated_repr = true; + } + maybe_last_int_type = Some(int_type); int_reprs += 1; } }; @@ -1274,10 +1309,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.tcx.emit_node_span_lint( CONFLICTING_REPR_HINTS, hir_id, - hint_spans.collect::>(), + hint_spans.clone().collect::>(), errors::ReprConflictingLint, ); } + + if repeated_repr { + self.tcx.emit_node_span_lint( + REPEATED_REPRS, + hir_id, + hint_spans.collect::>(), + errors::RepeatedRepr, + ); + } } /// Outputs an error for attributes that can only be applied to macros, such as diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 97dd413e16cf6..3f9e4a16da9c3 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -703,6 +703,11 @@ pub(crate) struct TransparentIncompatible { pub target: String, } +#[derive(Diagnostic)] +#[diag("representation attribute is specified more than once")] +#[note("for consistency, only specify the representation once")] +pub(crate) struct RepeatedRepr; + #[derive(Diagnostic)] #[diag("deprecated attribute must be paired with either stable or unstable attribute", code = E0549)] pub(crate) struct DeprecatedAttribute { diff --git a/tests/ui/attributes/issue-100631.rs b/tests/ui/attributes/issue-100631.rs index 0fefcf83fd516..d496231c73026 100644 --- a/tests/ui/attributes/issue-100631.rs +++ b/tests/ui/attributes/issue-100631.rs @@ -2,6 +2,7 @@ // can reasonably deal with multiple attributes. // `repr` will use `TyCtxt::get_attrs` since it's `DuplicatesOk`. #[repr(C)] //~ ERROR: unsupported representation for zero-variant enum [E0084] +//~^ WARN representation attribute is specified more than once #[repr(C)] enum Foo {} diff --git a/tests/ui/attributes/issue-100631.stderr b/tests/ui/attributes/issue-100631.stderr index b2bd0a9632513..66e08738eb02c 100644 --- a/tests/ui/attributes/issue-100631.stderr +++ b/tests/ui/attributes/issue-100631.stderr @@ -1,12 +1,24 @@ -error[E0084]: unsupported representation for zero-variant enum +warning: representation attribute is specified more than once --> $DIR/issue-100631.rs:4:8 | LL | #[repr(C)] | ^ +LL | LL | #[repr(C)] + | ^ + | + = note: for consistency, only specify the representation once + = note: `#[warn(repeated_reprs)]` on by default + +error[E0084]: unsupported representation for zero-variant enum + --> $DIR/issue-100631.rs:4:8 + | +LL | #[repr(C)] + | ^ +... LL | enum Foo {} | -------- zero-variant enum -error: aborting due to 1 previous error +error: aborting due to 1 previous error; 1 warning emitted For more information about this error, try `rustc --explain E0084`. diff --git a/tests/ui/lint/unused/unused-attr-duplicate.rs b/tests/ui/lint/unused/unused-attr-duplicate.rs index 54c040f4bcac4..348c9590e8b27 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.rs +++ b/tests/ui/lint/unused/unused-attr-duplicate.rs @@ -64,8 +64,7 @@ fn t1() {} #[must_use = "some message"] //~^ ERROR unused attribute //~| WARN this was previously accepted -// No warnings for #[repr], would require more logic. -#[repr(C)] +#[repr(C)] //~ WARN representation attribute is specified more than once #[repr(C)] #[non_exhaustive] #[non_exhaustive] //~ ERROR unused attribute diff --git a/tests/ui/lint/unused/unused-attr-duplicate.stderr b/tests/ui/lint/unused/unused-attr-duplicate.stderr index f25263e9cef90..bf66392162878 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.stderr +++ b/tests/ui/lint/unused/unused-attr-duplicate.stderr @@ -16,6 +16,17 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ +warning: representation attribute is specified more than once + --> $DIR/unused-attr-duplicate.rs:67:8 + | +LL | #[repr(C)] + | ^ +LL | #[repr(C)] + | ^ + | + = note: for consistency, only specify the representation once + = note: `#[warn(repeated_reprs)]` on by default + error: unused attribute --> $DIR/unused-attr-duplicate.rs:37:1 | @@ -104,124 +115,124 @@ LL | #[must_use] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: unused attribute - --> $DIR/unused-attr-duplicate.rs:71:1 + --> $DIR/unused-attr-duplicate.rs:70:1 | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:70:1 + --> $DIR/unused-attr-duplicate.rs:69:1 | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr-duplicate.rs:77:1 + --> $DIR/unused-attr-duplicate.rs:76:1 | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:76:1 + --> $DIR/unused-attr-duplicate.rs:75:1 | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr-duplicate.rs:81:1 + --> $DIR/unused-attr-duplicate.rs:80:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:80:1 + --> $DIR/unused-attr-duplicate.rs:79:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: unused attribute - --> $DIR/unused-attr-duplicate.rs:84:1 + --> $DIR/unused-attr-duplicate.rs:83:1 | LL | #[cold] | ^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:83:1 + --> $DIR/unused-attr-duplicate.rs:82:1 | LL | #[cold] | ^^^^^^^ error: unused attribute - --> $DIR/unused-attr-duplicate.rs:86:1 + --> $DIR/unused-attr-duplicate.rs:85:1 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:85:1 + --> $DIR/unused-attr-duplicate.rs:84:1 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr-duplicate.rs:94:5 + --> $DIR/unused-attr-duplicate.rs:93:5 | LL | #[link_name = "rust_dbg_extern_identity_u32"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:93:5 + --> $DIR/unused-attr-duplicate.rs:92:5 | LL | #[link_name = "this_does_not_exist"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: unused attribute - --> $DIR/unused-attr-duplicate.rs:100:1 + --> $DIR/unused-attr-duplicate.rs:99:1 | LL | #[export_name = "exported_symbol_name2"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:99:1 + --> $DIR/unused-attr-duplicate.rs:98:1 | LL | #[export_name = "exported_symbol_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: unused attribute - --> $DIR/unused-attr-duplicate.rs:105:1 + --> $DIR/unused-attr-duplicate.rs:104:1 | LL | #[no_mangle] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:104:1 + --> $DIR/unused-attr-duplicate.rs:103:1 | LL | #[no_mangle] | ^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr-duplicate.rs:109:1 + --> $DIR/unused-attr-duplicate.rs:108:1 | LL | #[used] | ^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:108:1 + --> $DIR/unused-attr-duplicate.rs:107:1 | LL | #[used] | ^^^^^^^ error: unused attribute - --> $DIR/unused-attr-duplicate.rs:113:1 + --> $DIR/unused-attr-duplicate.rs:112:1 | LL | #[link_section = "__DATA,__mod_init_func"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:112:1 + --> $DIR/unused-attr-duplicate.rs:111:1 | LL | #[link_section = "__TEXT,__text"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -316,5 +327,5 @@ note: attribute also specified here LL | #![no_builtins] | ^^^^^^^^^^^^^^^ -error: aborting due to 25 previous errors +error: aborting due to 25 previous errors; 1 warning emitted diff --git a/tests/ui/repr/conflicting-repr-hints.rs b/tests/ui/repr/conflicting-repr-hints.rs index ed82b6a742c8d..032f2b2e6c608 100644 --- a/tests/ui/repr/conflicting-repr-hints.rs +++ b/tests/ui/repr/conflicting-repr-hints.rs @@ -36,14 +36,14 @@ struct G(i32); //~ ERROR type has conflicting packed and align representation hi #[repr(packed)] struct H(i32); //~ ERROR type has conflicting packed and align representation hints -#[repr(packed, packed(2))] +#[repr(packed, packed(2))] //~ WARN representation attribute is specified more than once struct I(i32); //~ ERROR type has conflicting packed representation hints -#[repr(packed(2))] +#[repr(packed(2))] //~ WARN representation attribute is specified more than once #[repr(packed)] struct J(i32); //~ ERROR type has conflicting packed representation hints -#[repr(packed, packed(1))] +#[repr(packed, packed(1))] //~ WARN attribute is specified more than once struct K(i32); #[repr(packed, align(8))] diff --git a/tests/ui/repr/conflicting-repr-hints.stderr b/tests/ui/repr/conflicting-repr-hints.stderr index 4da3d454e037d..a99546b754785 100644 --- a/tests/ui/repr/conflicting-repr-hints.stderr +++ b/tests/ui/repr/conflicting-repr-hints.stderr @@ -17,6 +17,33 @@ LL | #[repr(u32, u64)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #68585 +warning: representation attribute is specified more than once + --> $DIR/conflicting-repr-hints.rs:39:8 + | +LL | #[repr(packed, packed(2))] + | ^^^^^^ ^^^^^^^^^ + | + = note: for consistency, only specify the representation once + = note: `#[warn(repeated_reprs)]` on by default + +warning: representation attribute is specified more than once + --> $DIR/conflicting-repr-hints.rs:42:8 + | +LL | #[repr(packed(2))] + | ^^^^^^^^^ +LL | #[repr(packed)] + | ^^^^^^ + | + = note: for consistency, only specify the representation once + +warning: representation attribute is specified more than once + --> $DIR/conflicting-repr-hints.rs:46:8 + | +LL | #[repr(packed, packed(1))] + | ^^^^^^ ^^^^^^^^^ + | + = note: for consistency, only specify the representation once + error[E0587]: type has conflicting packed and align representation hints --> $DIR/conflicting-repr-hints.rs:29:1 | @@ -77,7 +104,7 @@ error[E0587]: type has conflicting packed and align representation hints LL | pub union U { | ^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 12 previous errors; 3 warnings emitted Some errors have detailed explanations: E0566, E0587, E0634. For more information about an error, try `rustc --explain E0566`. diff --git a/tests/ui/repr/repr-repeated-attrs.rs b/tests/ui/repr/repr-repeated-attrs.rs new file mode 100644 index 0000000000000..61e3ba05625d8 --- /dev/null +++ b/tests/ui/repr/repr-repeated-attrs.rs @@ -0,0 +1,69 @@ +// Tests to ensure we warn on repeated `#[repr(..)]` attributes. + +#[repr(transparent, transparent)] +//~^ ERROR transparent struct cannot have other repr hints +#[repr(transparent)] +struct SeveralTransparentReprs(*mut u8); + +#[repr(transparent)] +//~^ ERROR transparent struct cannot have other repr hints +#[repr(transparent)] +struct MultilineOnly(*mut u8); + +#[repr(Rust, Rust)] +//~^ WARN representation attribute is specified more than once +struct SeveralRustReprs(u8); + +#[repr(C, C)] +//~^ WARN representation attribute is specified more than once +#[repr(C, C, C)] +struct SeveralC(u8); + +#[repr(u8, u8)] //~ WARN representation attribute is specified more than once +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +enum SeveralPrimitiveRerprs { + Variant, +} + +#[repr(C, C, u8)] //~ WARN representation attribute is specified more than once +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +#[repr(C, u8, u8)] +enum SeveralCAndPrims { + Variant(u8), +} + +#[repr(Rust, u8, u8)] //~ WARN representation attribute is specified more than once +//~^ ERROR conflicting representation hints +//~^^ ERROR conflicting representation hints +//~| WARN this was previously accepted +enum RustAndPrimDisallowed { + Variant(u8), +} + +#[repr(u8, u8)] //~ WARN representation attribute is specified more than once +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +#[repr(u16)] +enum ConflictingPrimReprs { + Variant, +} + +#[repr(C, u8)] +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +enum CWithIntsCausesFCW1 { + A, + B, +} + +#[repr(C, C, u8, u8, u8)] //~ WARN representation attribute is specified more than once +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +enum CWithIntsCausesFCW2 { + A, + B, +} + +fn main() {} diff --git a/tests/ui/repr/repr-repeated-attrs.stderr b/tests/ui/repr/repr-repeated-attrs.stderr new file mode 100644 index 0000000000000..57af8ec804d76 --- /dev/null +++ b/tests/ui/repr/repr-repeated-attrs.stderr @@ -0,0 +1,227 @@ +error[E0692]: transparent struct cannot have other repr hints + --> $DIR/repr-repeated-attrs.rs:3:8 + | +LL | #[repr(transparent, transparent)] + | ^^^^^^^^^^^ ^^^^^^^^^^^ +LL | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ + +error[E0692]: transparent struct cannot have other repr hints + --> $DIR/repr-repeated-attrs.rs:8:8 + | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ +LL | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:13:8 + | +LL | #[repr(Rust, Rust)] + | ^^^^ ^^^^ + | + = note: for consistency, only specify the representation once + = note: `#[warn(repeated_reprs)]` on by default + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:17:8 + | +LL | #[repr(C, C)] + | ^ ^ +LL | +LL | #[repr(C, C, C)] + | ^ ^ ^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:22:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:22:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:29:8 + | +LL | #[repr(C, C, u8)] + | ^ ^ ^^ +... +LL | #[repr(C, u8, u8)] + | ^ ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:29:8 + | +LL | #[repr(C, C, u8)] + | ^ ^ ^^ +... +LL | #[repr(C, u8, u8)] + | ^ ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:37:8 + | +LL | #[repr(Rust, u8, u8)] + | ^^^^ ^^ ^^ + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:37:8 + | +LL | #[repr(Rust, u8, u8)] + | ^^^^ ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:37:8 + | +LL | #[repr(Rust, u8, u8)] + | ^^^^ ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:45:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ +... +LL | #[repr(u16)] + | ^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:45:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ +... +LL | #[repr(u16)] + | ^^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:53:8 + | +LL | #[repr(C, u8)] + | ^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:61:8 + | +LL | #[repr(C, C, u8, u8, u8)] + | ^ ^ ^^ ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + +warning: representation attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:61:8 + | +LL | #[repr(C, C, u8, u8, u8)] + | ^ ^ ^^ ^^ ^^ + | + = note: for consistency, only specify the representation once + +error: aborting due to 9 previous errors; 7 warnings emitted + +Some errors have detailed explanations: E0566, E0692. +For more information about an error, try `rustc --explain E0566`. +Future incompatibility report: Future breakage diagnostic: +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:22:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + +Future breakage diagnostic: +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:29:8 + | +LL | #[repr(C, C, u8)] + | ^ ^ ^^ +... +LL | #[repr(C, u8, u8)] + | ^ ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + +Future breakage diagnostic: +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:37:8 + | +LL | #[repr(Rust, u8, u8)] + | ^^^^ ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + +Future breakage diagnostic: +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:45:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ +... +LL | #[repr(u16)] + | ^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + +Future breakage diagnostic: +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:53:8 + | +LL | #[repr(C, u8)] + | ^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + +Future breakage diagnostic: +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:61:8 + | +LL | #[repr(C, C, u8, u8, u8)] + | ^ ^ ^^ ^^ ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 + = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default + diff --git a/tests/ui/structs-enums/align-enum.rs b/tests/ui/structs-enums/align-enum.rs index ff80a19211cda..a635af7352afe 100644 --- a/tests/ui/structs-enums/align-enum.rs +++ b/tests/ui/structs-enums/align-enum.rs @@ -11,7 +11,7 @@ enum Align16 { } // Raise alignment by maximum -#[repr(align(1), align(16))] +#[repr(align(1), align(16))] //~ WARN representation attribute is specified more than once #[repr(align(32))] #[repr(align(4))] enum Align32 { diff --git a/tests/ui/structs-enums/align-enum.stderr b/tests/ui/structs-enums/align-enum.stderr new file mode 100644 index 0000000000000..9b8c9842f81df --- /dev/null +++ b/tests/ui/structs-enums/align-enum.stderr @@ -0,0 +1,15 @@ +warning: representation attribute is specified more than once + --> $DIR/align-enum.rs:14:8 + | +LL | #[repr(align(1), align(16))] + | ^^^^^^^^ ^^^^^^^^^ +LL | #[repr(align(32))] + | ^^^^^^^^^ +LL | #[repr(align(4))] + | ^^^^^^^^ + | + = note: for consistency, only specify the representation once + = note: `#[warn(repeated_reprs)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/structs-enums/align-struct.rs b/tests/ui/structs-enums/align-struct.rs index 3d8dad6e324e3..2d1ebf6731a62 100644 --- a/tests/ui/structs-enums/align-struct.rs +++ b/tests/ui/structs-enums/align-struct.rs @@ -13,7 +13,7 @@ struct Align16(i32); struct Align1(i32); // Multiple attributes take the max -#[repr(align(4))] +#[repr(align(4))] //~ WARN representation attribute is specified more than once #[repr(align(16))] #[repr(align(8))] struct AlignMany(i32); diff --git a/tests/ui/structs-enums/align-struct.stderr b/tests/ui/structs-enums/align-struct.stderr new file mode 100644 index 0000000000000..f54e9cd14cd8b --- /dev/null +++ b/tests/ui/structs-enums/align-struct.stderr @@ -0,0 +1,15 @@ +warning: representation attribute is specified more than once + --> $DIR/align-struct.rs:16:8 + | +LL | #[repr(align(4))] + | ^^^^^^^^ +LL | #[repr(align(16))] + | ^^^^^^^^^ +LL | #[repr(align(8))] + | ^^^^^^^^ + | + = note: for consistency, only specify the representation once + = note: `#[warn(repeated_reprs)]` on by default + +warning: 1 warning emitted +