Skip to content

Commit 86013e6

Browse files
committed
continue to check attr if meet empty repr for adt
1 parent 91a0e16 commit 86013e6

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19981998
// catch `repr()` with no arguments, applied to an item (i.e. not `#![repr()]`)
19991999
if item.is_some() {
20002000
match target {
2001-
Target::Struct | Target::Union | Target::Enum => {}
2001+
Target::Struct | Target::Union | Target::Enum => continue,
20022002
Target::Fn | Target::Method(_) => {
20032003
feature_err(
20042004
&self.tcx.sess,

tests/ui/repr/repr-empty-packed.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ compile-flags: --crate-type=lib
2+
#![deny(unused_attributes)]
3+
4+
#[repr()] //~ ERROR unused attribute
5+
#[repr(packed)] //~ ERROR attribute should be applied to a struct or union
6+
pub enum Foo {
7+
Bar,
8+
Baz(i32),
9+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: unused attribute
2+
--> $DIR/repr-empty-packed.rs:4:1
3+
|
4+
LL | #[repr()]
5+
| ^^^^^^^^^ help: remove this attribute
6+
|
7+
= note: attribute `repr` with an empty list has no effect
8+
note: the lint level is defined here
9+
--> $DIR/repr-empty-packed.rs:2:9
10+
|
11+
LL | #![deny(unused_attributes)]
12+
| ^^^^^^^^^^^^^^^^^
13+
14+
error[E0517]: attribute should be applied to a struct or union
15+
--> $DIR/repr-empty-packed.rs:5:8
16+
|
17+
LL | #[repr(packed)]
18+
| ^^^^^^
19+
LL | / pub enum Foo {
20+
LL | | Bar,
21+
LL | | Baz(i32),
22+
LL | | }
23+
| |_- not a struct or union
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0517`.

0 commit comments

Comments
 (0)