Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ fn register_builtins(store: &mut LintStore) {
"dependency_on_unit_never_type_fallback",
"the code warned by this lint no longer compiles",
);
store.register_removed(
"conflicting_repr_hints",
"converted into a hard error, \
see <https://github.com/rust-lang/rust/issues/68585> for more information",
);
}

fn register_internals(store: &mut LintStore) {
Expand Down
37 changes: 0 additions & 37 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub mod hardwired {
BINDINGS_WITH_VARIANT_NAME,
BREAK_WITH_LABEL_AND_LOOP,
COHERENCE_LEAK_CHECK,
CONFLICTING_REPR_HINTS,
CONST_EVALUATABLE_UNCHECKED,
CONST_ITEM_MUTATION,
DEAD_CODE,
Expand Down Expand Up @@ -247,42 +246,6 @@ declare_lint! {
crate_level_only
}

declare_lint! {
/// The `conflicting_repr_hints` lint detects [`repr` attributes] with
/// conflicting hints.
///
/// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
///
/// ### Example
///
/// ```rust,compile_fail
/// #[repr(u32, u64)]
/// enum Foo {
/// Variant1,
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The compiler incorrectly accepted these conflicting representations in
/// the past. This is a [future-incompatible] lint to transition this to a
/// hard error in the future. See [issue #68585] for more details.
///
/// To correct the issue, remove one of the conflicting hints.
///
/// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub CONFLICTING_REPR_HINTS,
Deny,
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(FutureReleaseError #68585),
report_in_deps: true,
};
}

declare_lint! {
/// The `repeated_reprs` lint detects when the same representation is
/// specified more than once in a `#[repr(..)]` attribute.
Expand Down
19 changes: 7 additions & 12 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ use rustc_hir::{
ItemKind, Mod, Node, ParamName, TraitItem,
};
use rustc_lint_defs::builtin::{
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_ATTRIBUTES,
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, MISPLACED_DIAGNOSTIC_ATTRIBUTES, REPEATED_REPRS,
UNUSED_ATTRIBUTES,
INVALID_DOC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
MISPLACED_DIAGNOSTIC_ATTRIBUTES, REPEATED_REPRS, UNUSED_ATTRIBUTES,
};
use rustc_macros::Diagnostic;
use rustc_middle::hir::nested_filter;
Expand Down Expand Up @@ -1083,17 +1082,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let hint_spans = hint_spans.clone().collect();
self.dcx().emit_err(diagnostics::ReprConflicting { hint_spans });
}
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
// Also error on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
if (int_reprs > 1)
|| (is_simd && is_c)
|| (int_reprs == 1 && is_c && item.is_some_and(is_c_like_enum))
|| (int_reprs == 1 && is_c && item.is_some_and(is_fieldless_enum))
{
self.tcx.emit_node_span_lint(
CONFLICTING_REPR_HINTS,
hir_id,
hint_spans.collect::<Vec<Span>>(),
diagnostics::ReprConflictingLint,
);
let hint_spans = hint_spans.clone().collect();
self.dcx().emit_err(diagnostics::ReprConflicting { hint_spans });
}
}

Expand Down Expand Up @@ -1522,7 +1517,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
}
}

fn is_c_like_enum(item: &Item<'_>) -> bool {
fn is_fieldless_enum(item: &Item<'_>) -> bool {
if let ItemKind::Enum(_, _, ref def) = item.kind {
for variant in def.variants {
match variant.data {
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ pub(crate) struct ReprConflicting {
pub hint_spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag("conflicting representation hints", code = E0566)]
pub(crate) struct ReprConflictingLint;

#[derive(Diagnostic)]
#[diag("couldn't read {$file}: {$error}")]
pub(crate) struct DebugVisualizerUnreadable<'a> {
Expand Down
10 changes: 5 additions & 5 deletions tests/rustdoc-json/attrs/repr_combination.rs

@mejrs mejrs Nov 8, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you turn these enums into enums with fields rather than deleting them?

Something like

#[repr(usize, C)]
pub enum EnumWithField {
    First(u32),
}

is rendered as

Image

so we should keep these tests around.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's what these tests are for. :) Good catch, thanks!

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
//@ is "$.index[?(@.name=='ReprCI8')].attrs" '[{"repr":{"align":null,"int":"i8","kind":"c","packed":null}}]'
#[repr(C, i8)]
pub enum ReprCI8 {
First,
First(usize),
}

//@ is "$.index[?(@.name=='SeparateReprCI16')].attrs" '[{"repr":{"align":null,"int":"i16","kind":"c","packed":null}}]'
#[repr(C)]
#[repr(i16)]
pub enum SeparateReprCI16 {
First,
First(usize),
}

//@ is "$.index[?(@.name=='ReversedReprCUsize')].attrs" '[{"repr":{"align":null,"int":"usize","kind":"c","packed":null}}]'
#[repr(usize, C)]
pub enum ReversedReprCUsize {
First,
First(usize),
}

//@ is "$.index[?(@.name=='ReprCPacked')].attrs" '[{"repr":{"align":null,"int":null,"kind":"c","packed":1}}]'
Expand Down Expand Up @@ -68,13 +68,13 @@ pub struct ReversedReprCAlign {
//@ is "$.index[?(@.name=='AlignedExplicitRepr')].attrs" '[{"repr":{"align":16,"int":"isize","kind":"c","packed":null}}]'
#[repr(C, align(16), isize)]
pub enum AlignedExplicitRepr {
First,
First(usize),
}

//@ is "$.index[?(@.name=='ReorderedAlignedExplicitRepr')].attrs" '[{"repr":{"align":16,"int":"isize","kind":"c","packed":null}}]'
#[repr(isize, C, align(16))]
pub enum ReorderedAlignedExplicitRepr {
First,
First(usize),
}

//@ is "$.index[?(@.name=='Transparent')].attrs" '[{"repr":{"align":null,"int":null,"kind":"transparent","packed":null}}]'
Expand Down
1 change: 0 additions & 1 deletion tests/ui/feature-gates/feature-gate-repr-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
struct Foo([u64; 2]);

#[repr(C)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
#[repr(simd)] //~ ERROR: SIMD types are experimental
struct Bar([u64; 2]);

Expand Down
29 changes: 5 additions & 24 deletions tests/ui/feature-gates/feature-gate-repr-simd.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | #[repr(simd)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: SIMD types are experimental and possibly buggy
--> $DIR/feature-gate-repr-simd.rs:6:8
--> $DIR/feature-gate-repr-simd.rs:5:8
|
LL | #[repr(simd)]
| ^^^^
Expand All @@ -19,7 +19,7 @@ LL | #[repr(simd)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: SIMD types are experimental and possibly buggy
--> $DIR/feature-gate-repr-simd.rs:9:8
--> $DIR/feature-gate-repr-simd.rs:8:8
|
LL | #[repr(simd)]
| ^^^^
Expand All @@ -29,7 +29,7 @@ LL | #[repr(simd)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: the `repr(simd)` attribute cannot be used on unions
--> $DIR/feature-gate-repr-simd.rs:9:3
--> $DIR/feature-gate-repr-simd.rs:8:3
|
LL | #[repr(simd)]
| ^^^^^^^^^^
Expand All @@ -39,7 +39,7 @@ LL | union U {f: u32}
= help: the `repr(simd)` attribute can only be applied to structs

error[E0658]: SIMD types are experimental and possibly buggy
--> $DIR/feature-gate-repr-simd.rs:13:8
--> $DIR/feature-gate-repr-simd.rs:12:8
|
LL | #[repr(simd)]
| ^^^^
Expand All @@ -49,7 +49,7 @@ LL | #[repr(simd)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: the `repr(simd)` attribute cannot be used on enums
--> $DIR/feature-gate-repr-simd.rs:13:3
--> $DIR/feature-gate-repr-simd.rs:12:3
|
LL | #[repr(simd)]
| ^^^^^^^^^^
Expand All @@ -63,29 +63,10 @@ error[E0566]: conflicting representation hints
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(simd)]
| ^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default

error: aborting due to 7 previous errors

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
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(simd)]
| ^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default

2 changes: 0 additions & 2 deletions tests/ui/repr/conflicting-repr-enum-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
//! when there are multiple repr attributes.

#[repr(C, u8)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
enum Foo {
A,
B,
}

#[repr(C)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
#[repr(u8)]
enum Bar {
A,
Expand Down
35 changes: 1 addition & 34 deletions tests/ui/repr/conflicting-repr-enum-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,15 @@ error[E0566]: conflicting representation hints
|
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 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default

error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-enum-attrs.rs:12:8
--> $DIR/conflicting-repr-enum-attrs.rs:11:8
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(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 <https://github.com/rust-lang/rust/issues/68585>

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0566`.
Future incompatibility report: Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-enum-attrs.rs:5: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 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default

Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-enum-attrs.rs:12:8
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(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 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default

2 changes: 0 additions & 2 deletions tests/ui/repr/conflicting-repr-hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ enum B {
}

#[repr(C, u64)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
enum C {
C,
}

#[repr(u32, u64)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
enum D {
D,
}
Expand Down
Loading
Loading