@@ -20,7 +20,7 @@ use super::{list_contains_name, mark_used, MetaItemKind};
20
20
21
21
enum AttrError {
22
22
MultipleItem ( Name ) ,
23
- UnknownMetaItem ( Name ) ,
23
+ UnknownMetaItem ( Name , & ' static [ & ' static str ] ) ,
24
24
MissingSince ,
25
25
MissingFeature ,
26
26
MultipleStabilityLevels ,
@@ -31,8 +31,15 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) {
31
31
match error {
32
32
AttrError :: MultipleItem ( item) => span_err ! ( diag, span, E0538 ,
33
33
"multiple '{}' items" , item) ,
34
- AttrError :: UnknownMetaItem ( item) => span_err ! ( diag, span, E0541 ,
35
- "unknown meta item '{}'" , item) ,
34
+ AttrError :: UnknownMetaItem ( item, expected) => {
35
+ let expected = expected
36
+ . iter ( )
37
+ . map ( |name| format ! ( "`{}`" , name) )
38
+ . collect :: < Vec < _ > > ( ) ;
39
+ struct_span_err ! ( diag, span, E0541 , "unknown meta item '{}'" , item)
40
+ . span_label ( span, format ! ( "expected one of {}" , expected. join( ", " ) ) )
41
+ . emit ( ) ;
42
+ }
36
43
AttrError :: MissingSince => span_err ! ( diag, span, E0542 , "missing 'since'" ) ,
37
44
AttrError :: MissingFeature => span_err ! ( diag, span, E0546 , "missing 'feature'" ) ,
38
45
AttrError :: MultipleStabilityLevels => span_err ! ( diag, span, E0544 ,
@@ -213,8 +220,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
213
220
=> if !get( mi, & mut $name) { continue ' outer } ,
214
221
) +
215
222
_ => {
216
- handle_errors( diagnostic, mi. span,
217
- AttrError :: UnknownMetaItem ( mi. name( ) ) ) ;
223
+ let expected = & [ $( stringify!( $name) ) ,+ ] ;
224
+ handle_errors(
225
+ diagnostic,
226
+ mi. span,
227
+ AttrError :: UnknownMetaItem ( mi. name( ) , expected) ) ;
218
228
continue ' outer
219
229
}
220
230
}
@@ -286,8 +296,14 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
286
296
"reason" => if !get ( mi, & mut reason) { continue ' outer } ,
287
297
"issue" => if !get ( mi, & mut issue) { continue ' outer } ,
288
298
_ => {
289
- handle_errors ( diagnostic, meta. span ,
290
- AttrError :: UnknownMetaItem ( mi. name ( ) ) ) ;
299
+ handle_errors (
300
+ diagnostic,
301
+ meta. span ,
302
+ AttrError :: UnknownMetaItem (
303
+ mi. name ( ) ,
304
+ & [ "feature" , "reason" , "issue" ]
305
+ ) ,
306
+ ) ;
291
307
continue ' outer
292
308
}
293
309
}
@@ -341,8 +357,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
341
357
"feature" => if !get ( mi, & mut feature) { continue ' outer } ,
342
358
"since" => if !get ( mi, & mut since) { continue ' outer } ,
343
359
_ => {
344
- handle_errors ( diagnostic, meta. span ,
345
- AttrError :: UnknownMetaItem ( mi. name ( ) ) ) ;
360
+ handle_errors (
361
+ diagnostic,
362
+ meta. span ,
363
+ AttrError :: UnknownMetaItem ( mi. name ( ) , & [ "since" , "note" ] ) ,
364
+ ) ;
346
365
continue ' outer
347
366
}
348
367
}
@@ -520,8 +539,11 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
520
539
"since" => if !get ( mi, & mut since) { continue ' outer } ,
521
540
"note" => if !get ( mi, & mut note) { continue ' outer } ,
522
541
_ => {
523
- handle_errors ( diagnostic, meta. span ,
524
- AttrError :: UnknownMetaItem ( mi. name ( ) ) ) ;
542
+ handle_errors (
543
+ diagnostic,
544
+ meta. span ,
545
+ AttrError :: UnknownMetaItem ( mi. name ( ) , & [ "since" , "note" ] ) ,
546
+ ) ;
525
547
continue ' outer
526
548
}
527
549
}
0 commit comments