@@ -42,7 +42,9 @@ struct CheckAttrVisitor<'a> {
42
42
impl < ' a > CheckAttrVisitor < ' a > {
43
43
fn check_inline ( & self , attr : & ast:: Attribute , target : Target ) {
44
44
if target != Target :: Fn {
45
- span_err ! ( self . sess, attr. span, E0518 , "attribute should be applied to function" ) ;
45
+ struct_span_err ! ( self . sess, attr. span, E0518 , "attribute should be applied to function" )
46
+ . span_label ( attr. span , & format ! ( "requires a function" ) )
47
+ . emit ( ) ;
46
48
}
47
49
}
48
50
@@ -56,18 +58,20 @@ impl<'a> CheckAttrVisitor<'a> {
56
58
57
59
let mut conflicting_reprs = 0 ;
58
60
for word in words {
61
+
59
62
let name = match word. name ( ) {
60
63
Some ( word) => word,
61
64
None => continue ,
62
65
} ;
63
66
64
- let message = match & * name {
67
+ let ( message, label ) = match & * name {
65
68
"C" => {
66
69
conflicting_reprs += 1 ;
67
70
if target != Target :: Struct &&
68
71
target != Target :: Union &&
69
72
target != Target :: Enum {
70
- "attribute should be applied to struct, enum or union"
73
+ ( "attribute should be applied to struct, enum or union" ,
74
+ "a struct, enum or union" )
71
75
} else {
72
76
continue
73
77
}
@@ -77,15 +81,17 @@ impl<'a> CheckAttrVisitor<'a> {
77
81
// can be used to modify another repr hint
78
82
if target != Target :: Struct &&
79
83
target != Target :: Union {
80
- "attribute should be applied to struct or union"
84
+ ( "attribute should be applied to struct or union" ,
85
+ "a struct or union" )
81
86
} else {
82
87
continue
83
88
}
84
89
}
85
90
"simd" => {
86
91
conflicting_reprs += 1 ;
87
92
if target != Target :: Struct {
88
- "attribute should be applied to struct"
93
+ ( "attribute should be applied to struct" ,
94
+ "a struct" )
89
95
} else {
90
96
continue
91
97
}
@@ -95,15 +101,17 @@ impl<'a> CheckAttrVisitor<'a> {
95
101
"isize" | "usize" => {
96
102
conflicting_reprs += 1 ;
97
103
if target != Target :: Enum {
98
- "attribute should be applied to enum"
104
+ ( "attribute should be applied to enum" ,
105
+ "an enum" )
99
106
} else {
100
107
continue
101
108
}
102
109
}
103
110
_ => continue ,
104
111
} ;
105
-
106
- span_err ! ( self . sess, attr. span, E0517 , "{}" , message) ;
112
+ struct_span_err ! ( self . sess, attr. span, E0517 , "{}" , message)
113
+ . span_label ( attr. span , & format ! ( "requires {}" , label) )
114
+ . emit ( ) ;
107
115
}
108
116
if conflicting_reprs > 1 {
109
117
span_warn ! ( self . sess, attr. span, E0566 ,
0 commit comments