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
9 changes: 9 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match hint.name_or_empty() {
sym::Rust => {
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 => {
is_c = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,28 @@ mod repr {
//~| 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() {}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ LL | |
LL | | }
| |_- 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
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:26:1
|
Expand Down Expand Up @@ -329,7 +344,31 @@ error[E0517]: attribute should be applied to a struct, enum, or union
LL | #[repr(C)] impl S { }
| ^ ---------- 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.
For more information about an error, try `rustc --explain E0517`.
Loading