diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 195712559782d..28e90ea4f52b4 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -172,7 +172,19 @@ impl OptimizeAttr { } } -#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, StableHash, PrintAttribute)] +#[derive( + PartialEq, + Eq, + Debug, + PartialOrd, + Ord, + Encodable, + Decodable, + Copy, + Clone, + StableHash, + PrintAttribute +)] pub enum ReprAttr { ReprInt(IntType), ReprRust, @@ -188,7 +200,7 @@ pub enum TransparencyError { MultipleTransparencyAttrs(Span, Span), } -#[derive(Eq, PartialEq, Debug, Copy, Clone)] +#[derive(Eq, PartialEq, Debug, Copy, Clone, PartialOrd, Ord)] #[derive(Encodable, Decodable, StableHash, PrintAttribute)] pub enum IntType { SignedInt(ast::IntTy), diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 852f1cfda5168..1a392ae1c05da 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -367,7 +367,8 @@ fn register_builtins(store: &mut LintStore) { UNUSED_PARENS, UNUSED_BRACES, REDUNDANT_SEMICOLONS, - MAP_UNIT_FN + MAP_UNIT_FN, + REPEATED_REPRS ); add_lint_group!("let_underscore", LET_UNDERSCORE_DROP, LET_UNDERSCORE_LOCK); diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index d7339d1b60269..af5db6117f7b5 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -95,6 +95,7 @@ pub mod hardwired { REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE, RENAMED_AND_REMOVED_LINTS, + REPEATED_REPRS, REPR_C_ENUMS_LARGER_THAN_INT, RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS, RTSAN_NONBLOCKING_ASYNC, @@ -277,6 +278,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 7f9e4fc553455..e4ee552d5bd0e 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -30,7 +30,8 @@ use rustc_hir::{ }; use rustc_lint_defs::builtin::{ CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_ATTRIBUTES, - MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES, + MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, MISPLACED_DIAGNOSTIC_ATTRIBUTES, REPEATED_REPRS, + UNUSED_ATTRIBUTES, }; use rustc_macros::Diagnostic; use rustc_middle::hir::nested_filter; @@ -1221,20 +1222,49 @@ impl<'tcx> CheckAttrVisitor<'tcx> { ReprAttr::ReprC => { is_c = true; } - ReprAttr::ReprAlign(..) => {} - ReprAttr::ReprPacked(_) => {} + ReprAttr::ReprAlign(..) => (), + ReprAttr::ReprPacked(..) => (), ReprAttr::ReprSimd => { is_simd = true; } ReprAttr::ReprTransparent => { is_transparent = true; } - ReprAttr::ReprInt(_) => { + ReprAttr::ReprInt(..) => { int_reprs += 1; } }; } + if !reprs.is_empty() { + let sorted_reprs = { + let mut to_sort = reprs.to_owned(); + to_sort.sort_unstable(); + to_sort + }; + + // To collect all duplicates, get subslices where all of the elements of the subslice + // are equal, then filter out all those whose length is not 1. We could return warnings + // for each of them, but that's annoyingly excessive. So we instead collect all spans in + // one big Vec. + let spans: Vec = sorted_reprs + .chunk_by(|(a, _), (b, _)| a == b) + .map(ToOwned::to_owned) + .filter(|slice| slice.len() != 1) + .flatten() + .map(|(_, span)| span) + .collect(); + + if !spans.is_empty() { + self.tcx.emit_node_span_lint( + REPEATED_REPRS, + hir_id, + spans, + diagnostics::RepeatedRepr, + ); + } + } + // 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/diagnostics.rs b/compiler/rustc_passes/src/diagnostics.rs index 9864e9debf9d8..c343d9c7078e7 100644 --- a/compiler/rustc_passes/src/diagnostics.rs +++ b/compiler/rustc_passes/src/diagnostics.rs @@ -607,6 +607,11 @@ pub(crate) struct TransparentIncompatible { pub target: String, } +#[derive(Diagnostic)] +#[diag("`#[repr(..)]` 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..09b34ebfe7a2c 100644 --- a/tests/ui/attributes/issue-100631.rs +++ b/tests/ui/attributes/issue-100631.rs @@ -1,7 +1,9 @@ +//@ compile-flags: -W repeated-reprs // issue #100631, make sure `TyCtxt::get_attr` only called by case that compiler // 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 `#[repr(..)]` attribute is specified more than once [repeated_reprs] #[repr(C)] enum Foo {} diff --git a/tests/ui/attributes/issue-100631.stderr b/tests/ui/attributes/issue-100631.stderr index b2bd0a9632513..62d82c9b31335 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 - --> $DIR/issue-100631.rs:4:8 +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/issue-100631.rs:5:8 | LL | #[repr(C)] | ^ +LL | +LL | #[repr(C)] + | ^ + | + = note: for consistency, only specify the representation once + = note: requested on the command line with `-W repeated-reprs` + +error[E0084]: unsupported representation for zero-variant enum + --> $DIR/issue-100631.rs:5: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/issue-70819-dont-override-forbid-in-same-scope.stderr b/tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr index f40fb73acbb8b..b0eb5636d0479 100644 --- a/tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr +++ b/tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr @@ -449,3 +449,21 @@ note: the lint level is defined here LL | #![forbid(forbidden_lint_groups)] | ^^^^^^^^^^^^^^^^^^^^^ +Future breakage diagnostic: +error: warn(unused) incompatible with previous forbid + --> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:22:13 + | +LL | #![forbid(unused)] + | ------ `forbid` level set here +LL | #![deny(unused)] +LL | #![warn(unused)] + | ^^^^^^ overruled by previous forbid + | + = 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 #81670 +note: the lint level is defined here + --> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:17:11 + | +LL | #![forbid(forbidden_lint_groups)] + | ^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/ui/lint/outer-forbid.stderr b/tests/ui/lint/outer-forbid.stderr index abe5959176d4a..b2d7ad6c2aabc 100644 --- a/tests/ui/lint/outer-forbid.stderr +++ b/tests/ui/lint/outer-forbid.stderr @@ -489,3 +489,21 @@ note: the lint level is defined here LL | #![forbid(forbidden_lint_groups)] | ^^^^^^^^^^^^^^^^^^^^^ +Future breakage diagnostic: +error: allow(unused) incompatible with previous forbid + --> $DIR/outer-forbid.rs:25:9 + | +LL | #![forbid(unused, non_snake_case)] + | ------ `forbid` level set here +... +LL | #[allow(unused)] + | ^^^^^^ overruled by previous forbid + | + = 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 #81670 +note: the lint level is defined here + --> $DIR/outer-forbid.rs:18:11 + | +LL | #![forbid(forbidden_lint_groups)] + | ^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/ui/lint/unused/unused-attr-duplicate.rs b/tests/ui/lint/unused/unused-attr-duplicate.rs index 54c040f4bcac4..c62fc6036f60f 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.rs +++ b/tests/ui/lint/unused/unused-attr-duplicate.rs @@ -1,6 +1,6 @@ // Tests for repeating attribute warnings. //@ aux-build:lint_unused_extern_crate.rs -//@ compile-flags:--test +//@ compile-flags:--test -W repeated-reprs // Not tested due to extra requirements: // - panic_handler: needs extra setup // - target_feature: platform-specific @@ -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 `#[repr(..)]` attribute is specified more than once [repeated_reprs] #[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 3e4cb99a09e34..feb1a79bf9b92 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: `#[repr(..)]` 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: requested on the command line with `-W repeated-reprs` + error: unused attribute --> $DIR/unused-attr-duplicate.rs:14:1 | @@ -193,128 +204,128 @@ 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: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"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = 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: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: 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..6a265e13ad93d 100644 --- a/tests/ui/repr/conflicting-repr-hints.rs +++ b/tests/ui/repr/conflicting-repr-hints.rs @@ -1,3 +1,4 @@ +//@ compile-flags: -W repeated-reprs #![allow(dead_code)] #[repr(C)] @@ -43,7 +44,7 @@ struct I(i32); //~ ERROR type has conflicting packed representation hints #[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..2a81610e85f99 100644 --- a/tests/ui/repr/conflicting-repr-hints.stderr +++ b/tests/ui/repr/conflicting-repr-hints.stderr @@ -1,5 +1,5 @@ error[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:13:8 + --> $DIR/conflicting-repr-hints.rs:14:8 | LL | #[repr(C, u64)] | ^ ^^^ @@ -9,7 +9,7 @@ LL | #[repr(C, u64)] = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default error[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:19:8 + --> $DIR/conflicting-repr-hints.rs:20:8 | LL | #[repr(u32, u64)] | ^^^ ^^^ @@ -17,73 +17,82 @@ 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: `#[repr(..)]` attribute is specified more than once + --> $DIR/conflicting-repr-hints.rs:47:8 + | +LL | #[repr(packed, packed(1))] + | ^^^^^^ ^^^^^^^^^ + | + = note: for consistency, only specify the representation once + = note: requested on the command line with `-W repeated-reprs` + error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:29:1 + --> $DIR/conflicting-repr-hints.rs:30:1 | LL | struct F(i32); | ^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:33:1 + --> $DIR/conflicting-repr-hints.rs:34:1 | LL | struct G(i32); | ^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:37:1 + --> $DIR/conflicting-repr-hints.rs:38:1 | LL | struct H(i32); | ^^^^^^^^ error[E0634]: type has conflicting packed representation hints - --> $DIR/conflicting-repr-hints.rs:40:1 + --> $DIR/conflicting-repr-hints.rs:41:1 | LL | struct I(i32); | ^^^^^^^^ error[E0634]: type has conflicting packed representation hints - --> $DIR/conflicting-repr-hints.rs:44:1 + --> $DIR/conflicting-repr-hints.rs:45:1 | LL | struct J(i32); | ^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:50:1 + --> $DIR/conflicting-repr-hints.rs:51:1 | LL | union X { | ^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:57:1 + --> $DIR/conflicting-repr-hints.rs:58:1 | LL | union Y { | ^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:64:1 + --> $DIR/conflicting-repr-hints.rs:65:1 | LL | union Z { | ^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:70:1 + --> $DIR/conflicting-repr-hints.rs:71:1 | LL | pub struct S(u16); | ^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:73:1 + --> $DIR/conflicting-repr-hints.rs:74:1 | LL | pub union U { | ^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 12 previous errors; 1 warning emitted Some errors have detailed explanations: E0566, E0587, E0634. For more information about an error, try `rustc --explain E0566`. Future incompatibility report: Future breakage diagnostic: error[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:13:8 + --> $DIR/conflicting-repr-hints.rs:14:8 | LL | #[repr(C, u64)] | ^ ^^^ @@ -94,7 +103,7 @@ LL | #[repr(C, u64)] Future breakage diagnostic: error[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:19:8 + --> $DIR/conflicting-repr-hints.rs:20:8 | LL | #[repr(u32, u64)] | ^^^ ^^^ diff --git a/tests/ui/repr/repr-repeated-attrs.rs b/tests/ui/repr/repr-repeated-attrs.rs new file mode 100644 index 0000000000000..122eb9b7485ef --- /dev/null +++ b/tests/ui/repr/repr-repeated-attrs.rs @@ -0,0 +1,70 @@ +// Tests to ensure we warn on repeated `#[repr(..)]` attributes. +//@ compile-flags: -W repeated-reprs + +#[repr(transparent, transparent)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ ERROR transparent struct cannot have other repr hints +#[repr(transparent)] +struct SeveralTransparentReprs(*mut u8); + +#[repr(transparent)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ ERROR transparent struct cannot have other repr hints +#[repr(transparent)] +struct MultilineOnly(*mut u8); + +#[repr(Rust, Rust)] +//~^ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +struct SeveralRustReprs(u8); + +#[repr(C, C)] +//~^ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +#[repr(C, C, C)] +struct SeveralC(u8); + +#[repr(u8, u8)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +enum SeveralPrimitiveRerprs { + Variant, +} + +#[repr(C, C, u8)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ ERROR conflicting representation hints +//~| WARN this was previously accepted +#[repr(C, u8, u8)] +enum SeveralCAndPrims { + Variant(u8), +} + +#[repr(Rust, u8, u8)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ ERROR conflicting representation hints +//~^^ ERROR conflicting representation hints +//~| WARN this was previously accepted +enum RustAndPrimDisallowed { + Variant(u8), +} + +#[repr(u8, u8)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ 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 `#[repr(..)]` attribute is specified more than once [repeated_reprs] +//~^ 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..a1e54f6218889 --- /dev/null +++ b/tests/ui/repr/repr-repeated-attrs.stderr @@ -0,0 +1,246 @@ +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:4:8 + | +LL | #[repr(transparent, transparent)] + | ^^^^^^^^^^^ ^^^^^^^^^^^ +LL | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ + | + = note: for consistency, only specify the representation once + = note: requested on the command line with `-W repeated-reprs` + +error[E0692]: transparent struct cannot have other repr hints + --> $DIR/repr-repeated-attrs.rs:4:8 + | +LL | #[repr(transparent, transparent)] + | ^^^^^^^^^^^ ^^^^^^^^^^^ +LL | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ + +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:9:8 + | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ +LL | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ + | + = note: for consistency, only specify the representation once + +error[E0692]: transparent struct cannot have other repr hints + --> $DIR/repr-repeated-attrs.rs:9:8 + | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ +LL | +LL | #[repr(transparent)] + | ^^^^^^^^^^^ + +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:14:8 + | +LL | #[repr(Rust, Rust)] + | ^^^^ ^^^^ + | + = note: for consistency, only specify the representation once + +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:18:8 + | +LL | #[repr(C, C)] + | ^ ^ +LL | +LL | #[repr(C, C, C)] + | ^ ^ ^ + | + = note: for consistency, only specify the representation once + +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:23:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:23: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: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:30: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:30: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: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:38:14 + | +LL | #[repr(Rust, u8, u8)] + | ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:38:8 + | +LL | #[repr(Rust, u8, u8)] + | ^^^^ ^^ ^^ + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:38: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: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:46:8 + | +LL | #[repr(u8, u8)] + | ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:46: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 + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:54: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 + +warning: `#[repr(..)]` attribute is specified more than once + --> $DIR/repr-repeated-attrs.rs:62:8 + | +LL | #[repr(C, C, u8, u8, u8)] + | ^ ^ ^^ ^^ ^^ + | + = note: for consistency, only specify the representation once + +error[E0566]: conflicting representation hints + --> $DIR/repr-repeated-attrs.rs:62: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 + +error: aborting due to 9 previous errors; 9 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:23: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:30: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:38: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:46: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:54: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:62: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 +