Gate repr(Rust) correctly on non-ADT items

This commit is contained in:
Michael Goulet 2024-08-22 14:22:19 -04:00
parent 0f6e1ae678
commit 363addc79c
3 changed files with 73 additions and 1 deletions

View File

@ -1791,6 +1791,15 @@ fn check_repr(
match hint.name_or_empty() { match hint.name_or_empty() {
sym::Rust => { sym::Rust => {
is_explicit_rust = true; is_explicit_rust = true;
match target {
Target::Struct | Target::Union | Target::Enum => continue,
_ => {
self.dcx().emit_err(errors::AttrApplication::StructEnumUnion {
hint_span: hint.span(),
span,
});
}
}
} }
sym::C => { sym::C => {
is_c = true; is_c = true;

View File

@ -164,4 +164,28 @@ mod inner { #![repr(C)] }
//~| NOTE not a struct, enum, or union //~| NOTE not a struct, enum, or union
} }
#[repr(Rust)]
//~^ ERROR: attribute should be applied to a struct, enum, or union
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
#[repr(Rust)] fn f() { }
//~^ ERROR: attribute should be applied to a struct, enum, or union
//~| NOTE not a struct, enum, or union
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
#[repr(Rust)] impl S { }
//~^ ERROR: attribute should be applied to a struct, enum, or union
//~| NOTE not a struct, enum, or union
}
fn main() {} fn main() {}

View File

@ -107,6 +107,21 @@ LL | |
LL | | } LL | | }
| |_- not a struct, enum, or union | |_- 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:168:8
|
LL | #[repr(Rust)]
| ^^^^
LL |
LL | / mod repr_rust {
LL | |
LL | | mod inner { #![repr(Rust)] }
LL | |
... |
LL | |
LL | | }
| |_- not a struct, enum, or union
error: attribute should be applied to an `extern crate` item error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:26:1 --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:26:1
| |
@ -329,7 +344,31 @@ error[E0517]: attribute should be applied to a struct, enum, or union
LL | #[repr(C)] impl S { } LL | #[repr(C)] impl S { }
| ^ ---------- not a struct, enum, or union | ^ ---------- not a struct, enum, or union
error: aborting due to 39 previous errors error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:172:25
|
LL | mod inner { #![repr(Rust)] }
| --------------------^^^^---- 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:176:12
|
LL | #[repr(Rust)] fn f() { }
| ^^^^ ---------- 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:182:12
|
LL | #[repr(Rust)] type T = S;
| ^^^^ ----------- 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:186:12
|
LL | #[repr(Rust)] impl S { }
| ^^^^ ---------- not a struct, enum, or union
error: aborting due to 44 previous errors
Some errors have detailed explanations: E0517, E0518, E0658. Some errors have detailed explanations: E0517, E0518, E0658.
For more information about an error, try `rustc --explain E0517`. For more information about an error, try `rustc --explain E0517`.