diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2023-10-17 03:06:52 +0200 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2023-10-18 17:25:23 +0200 |
| commit | d0b99e3efe62b5acc107da9c84331eae6cbe5a0d (patch) | |
| tree | 0df7c46c96b502132851483bb9ba66e8820e5a98 /compiler | |
| parent | 1bc0463b183392ad4e0ae9c5f7a76630d487230d (diff) | |
| download | rust-d0b99e3efe62b5acc107da9c84331eae6cbe5a0d.tar.gz rust-d0b99e3efe62b5acc107da9c84331eae6cbe5a0d.zip | |
Make `#[repr(Rust)]` and `#[repr(C)]` incompatible with one another
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 9 |
2 files changed, 18 insertions, 4 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 9a7564cb213..d92923e78ff 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1767,6 +1767,7 @@ impl CheckAttrVisitor<'_> { .collect(); let mut int_reprs = 0; + let mut is_explicit_rust = false; let mut is_c = false; let mut is_simd = false; let mut is_transparent = false; @@ -1778,7 +1779,9 @@ impl CheckAttrVisitor<'_> { } match hint.name_or_empty() { - sym::Rust => {} + sym::Rust => { + is_explicit_rust = true; + } sym::C => { is_c = true; match target { @@ -1888,12 +1891,16 @@ impl CheckAttrVisitor<'_> { // Error on repr(transparent, <anything else>). if is_transparent && hints.len() > 1 { - let hint_spans: Vec<_> = hint_spans.clone().collect(); + let hint_spans = hint_spans.clone().collect(); self.tcx.sess.emit_err(errors::TransparentIncompatible { hint_spans, target: target.to_string(), }); } + if is_explicit_rust && (int_reprs > 0 || is_c || is_simd) { + let hint_spans = hint_spans.clone().collect(); + self.tcx.sess.emit_err(errors::ReprConflicting { hint_spans }); + } // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8) if (int_reprs > 1) || (is_simd && is_c) @@ -1910,7 +1917,7 @@ impl CheckAttrVisitor<'_> { CONFLICTING_REPR_HINTS, hir_id, hint_spans.collect::<Vec<Span>>(), - errors::ReprConflicting, + errors::ReprConflictingLint, ); } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index bcf5abbfe7d..f4a6bf017d6 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -558,9 +558,16 @@ pub struct ReprIdent { pub span: Span, } +#[derive(Diagnostic)] +#[diag(passes_repr_conflicting, code = "E0566")] +pub struct ReprConflicting { + #[primary_span] + pub hint_spans: Vec<Span>, +} + #[derive(LintDiagnostic)] #[diag(passes_repr_conflicting, code = "E0566")] -pub struct ReprConflicting; +pub struct ReprConflictingLint; #[derive(Diagnostic)] #[diag(passes_used_static)] |
