@@ -52,6 +52,7 @@ impl<'a> CheckAttrVisitor<'a> {
52
52
}
53
53
} ;
54
54
55
+ let mut conflicting_reprs = 0 ;
55
56
for word in words {
56
57
let name = match word. name ( ) {
57
58
Some ( word) => word,
@@ -60,13 +61,24 @@ impl<'a> CheckAttrVisitor<'a> {
60
61
61
62
let message = match & * name {
62
63
"C" => {
64
+ conflicting_reprs += 1 ;
63
65
if target != Target :: Struct && target != Target :: Enum {
64
66
"attribute should be applied to struct or enum"
65
67
} else {
66
68
continue
67
69
}
68
70
}
69
- "packed" | "simd" => {
71
+ "packed" => {
72
+ // Do not increment conflicting_reprs here, because "packed"
73
+ // can be used to modify another repr hint
74
+ if target != Target :: Struct {
75
+ "attribute should be applied to struct"
76
+ } else {
77
+ continue
78
+ }
79
+ }
80
+ "simd" => {
81
+ conflicting_reprs += 1 ;
70
82
if target != Target :: Struct {
71
83
"attribute should be applied to struct"
72
84
} else {
@@ -76,6 +88,7 @@ impl<'a> CheckAttrVisitor<'a> {
76
88
"i8" | "u8" | "i16" | "u16" |
77
89
"i32" | "u32" | "i64" | "u64" |
78
90
"isize" | "usize" => {
91
+ conflicting_reprs += 1 ;
79
92
if target != Target :: Enum {
80
93
"attribute should be applied to enum"
81
94
} else {
@@ -87,6 +100,10 @@ impl<'a> CheckAttrVisitor<'a> {
87
100
88
101
span_err ! ( self . sess, attr. span, E0517 , "{}" , message) ;
89
102
}
103
+ if conflicting_reprs > 1 {
104
+ span_warn ! ( self . sess, attr. span, E0566 ,
105
+ "conflicting representation hints" ) ;
106
+ }
90
107
}
91
108
92
109
fn check_attribute ( & self , attr : & ast:: Attribute , target : Target ) {
0 commit comments