@@ -236,10 +236,9 @@ impl<'s> LintLevelsBuilder<'s> {
236
236
Some ( lvl) => lvl,
237
237
} ;
238
238
239
- let meta = unwrap_or ! ( attr. meta( ) , continue ) ;
240
239
self . sess . mark_attr_used ( attr) ;
241
240
242
- let mut metas = unwrap_or ! ( meta . meta_item_list( ) , continue ) ;
241
+ let mut metas = unwrap_or ! ( attr . meta_item_list( ) , continue ) ;
243
242
244
243
if metas. is_empty ( ) {
245
244
// FIXME (#55112): issue unused-attributes lint for `#[level()]`
@@ -255,8 +254,6 @@ impl<'s> LintLevelsBuilder<'s> {
255
254
ast:: MetaItemKind :: Word => { } // actual lint names handled later
256
255
ast:: MetaItemKind :: NameValue ( ref name_value) => {
257
256
if item. path == sym:: reason {
258
- // found reason, reslice meta list to exclude it
259
- metas = & metas[ 0 ..metas. len ( ) - 1 ] ;
260
257
// FIXME (#55112): issue unused-attributes lint if we thereby
261
258
// don't have any lint names (`#[level(reason = "foo")]`)
262
259
if let ast:: LitKind :: Str ( rationale, _) = name_value. kind {
@@ -275,6 +272,8 @@ impl<'s> LintLevelsBuilder<'s> {
275
272
. span_label ( name_value. span , "reason must be a string literal" )
276
273
. emit ( ) ;
277
274
}
275
+ // found reason, reslice meta list to exclude it
276
+ metas. pop ( ) . unwrap ( ) ;
278
277
} else {
279
278
bad_attr ( item. span )
280
279
. span_label ( item. span , "bad attribute argument" )
@@ -288,10 +287,10 @@ impl<'s> LintLevelsBuilder<'s> {
288
287
}
289
288
290
289
for li in metas {
291
- let meta_item = match li. meta_item ( ) {
292
- Some ( meta_item) if meta_item. is_word ( ) => meta_item,
290
+ let sp = li. span ( ) ;
291
+ let mut meta_item = match li {
292
+ ast:: NestedMetaItem :: MetaItem ( meta_item) if meta_item. is_word ( ) => meta_item,
293
293
_ => {
294
- let sp = li. span ( ) ;
295
294
let mut err = bad_attr ( sp) ;
296
295
let mut add_label = true ;
297
296
if let Some ( item) = li. meta_item ( ) {
@@ -330,15 +329,19 @@ impl<'s> LintLevelsBuilder<'s> {
330
329
continue ;
331
330
}
332
331
333
- Some ( tool_ident . name )
332
+ Some ( meta_item . path . segments . remove ( 0 ) . ident . name )
334
333
} else {
335
334
None
336
335
} ;
337
- let name = meta_item. path . segments . last ( ) . expect ( "empty lint name" ) . ident . name ;
338
- let lint_result = store. check_lint_name ( & name. as_str ( ) , tool_name) ;
336
+ let name = pprust :: path_to_string ( & meta_item. path ) ;
337
+ let lint_result = store. check_lint_name ( & name, tool_name) ;
339
338
match & lint_result {
340
339
CheckLintNameResult :: Ok ( ids) => {
341
- let src = LintLevelSource :: Node ( name, li. span ( ) , reason) ;
340
+ let src = LintLevelSource :: Node (
341
+ meta_item. path . segments . last ( ) . expect ( "empty lint name" ) . ident . name ,
342
+ sp,
343
+ reason,
344
+ ) ;
342
345
for & id in * ids {
343
346
self . check_gated_lint ( id, attr. span ) ;
344
347
self . insert_spec ( & mut specs, id, ( level, src) ) ;
@@ -351,7 +354,7 @@ impl<'s> LintLevelsBuilder<'s> {
351
354
let complete_name = & format ! ( "{}::{}" , tool_name. unwrap( ) , name) ;
352
355
let src = LintLevelSource :: Node (
353
356
Symbol :: intern ( complete_name) ,
354
- li . span ( ) ,
357
+ sp ,
355
358
reason,
356
359
) ;
357
360
for id in ids {
@@ -367,7 +370,7 @@ impl<'s> LintLevelsBuilder<'s> {
367
370
lint,
368
371
lvl,
369
372
src,
370
- Some ( li . span ( ) . into ( ) ) ,
373
+ Some ( sp . into ( ) ) ,
371
374
|lint| {
372
375
let msg = format ! (
373
376
"lint name `{}` is deprecated \
@@ -376,7 +379,7 @@ impl<'s> LintLevelsBuilder<'s> {
376
379
) ;
377
380
lint. build ( & msg)
378
381
. span_suggestion (
379
- li . span ( ) ,
382
+ sp ,
380
383
"change it to" ,
381
384
new_lint_name. to_string ( ) ,
382
385
Applicability :: MachineApplicable ,
@@ -387,7 +390,7 @@ impl<'s> LintLevelsBuilder<'s> {
387
390
388
391
let src = LintLevelSource :: Node (
389
392
Symbol :: intern ( & new_lint_name) ,
390
- li . span ( ) ,
393
+ sp ,
391
394
reason,
392
395
) ;
393
396
for id in ids {
@@ -414,12 +417,12 @@ impl<'s> LintLevelsBuilder<'s> {
414
417
lint,
415
418
renamed_lint_level,
416
419
src,
417
- Some ( li . span ( ) . into ( ) ) ,
420
+ Some ( sp . into ( ) ) ,
418
421
|lint| {
419
422
let mut err = lint. build ( & msg) ;
420
423
if let Some ( new_name) = & renamed {
421
424
err. span_suggestion (
422
- li . span ( ) ,
425
+ sp ,
423
426
"use the new name" ,
424
427
new_name. to_string ( ) ,
425
428
Applicability :: MachineApplicable ,
@@ -433,30 +436,23 @@ impl<'s> LintLevelsBuilder<'s> {
433
436
let lint = builtin:: UNKNOWN_LINTS ;
434
437
let ( level, src) =
435
438
self . sets . get_lint_level ( lint, self . cur , Some ( & specs) , self . sess ) ;
436
- struct_lint_level (
437
- self . sess ,
438
- lint,
439
- level,
440
- src,
441
- Some ( li. span ( ) . into ( ) ) ,
442
- |lint| {
443
- let name = if let Some ( tool_name) = tool_name {
444
- format ! ( "{}::{}" , tool_name, name)
445
- } else {
446
- name. to_string ( )
447
- } ;
448
- let mut db = lint. build ( & format ! ( "unknown lint: `{}`" , name) ) ;
449
- if let Some ( suggestion) = suggestion {
450
- db. span_suggestion (
451
- li. span ( ) ,
452
- "did you mean" ,
453
- suggestion. to_string ( ) ,
454
- Applicability :: MachineApplicable ,
455
- ) ;
456
- }
457
- db. emit ( ) ;
458
- } ,
459
- ) ;
439
+ struct_lint_level ( self . sess , lint, level, src, Some ( sp. into ( ) ) , |lint| {
440
+ let name = if let Some ( tool_name) = tool_name {
441
+ format ! ( "{}::{}" , tool_name, name)
442
+ } else {
443
+ name. to_string ( )
444
+ } ;
445
+ let mut db = lint. build ( & format ! ( "unknown lint: `{}`" , name) ) ;
446
+ if let Some ( suggestion) = suggestion {
447
+ db. span_suggestion (
448
+ sp,
449
+ "did you mean" ,
450
+ suggestion. to_string ( ) ,
451
+ Applicability :: MachineApplicable ,
452
+ ) ;
453
+ }
454
+ db. emit ( ) ;
455
+ } ) ;
460
456
}
461
457
}
462
458
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
@@ -466,8 +462,7 @@ impl<'s> LintLevelsBuilder<'s> {
466
462
// Ignore any errors or warnings that happen because the new name is inaccurate
467
463
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
468
464
if let CheckLintNameResult :: Ok ( ids) = store. check_lint_name ( & new_name, None ) {
469
- let src =
470
- LintLevelSource :: Node ( Symbol :: intern ( & new_name) , li. span ( ) , reason) ;
465
+ let src = LintLevelSource :: Node ( Symbol :: intern ( & new_name) , sp, reason) ;
471
466
for & id in ids {
472
467
self . check_gated_lint ( id, attr. span ) ;
473
468
self . insert_spec ( & mut specs, id, ( level, src) ) ;
0 commit comments