@@ -1397,47 +1397,45 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1397
1397
Some ( LifetimeUseSet :: One ( _) ) => {
1398
1398
let node_id = self . tcx . hir . as_local_node_id ( def_id) . unwrap ( ) ;
1399
1399
debug ! ( "node id first={:?}" , node_id) ;
1400
- if let hir:: map:: NodeLifetime ( hir_lifetime) = self . tcx . hir . get ( node_id) {
1401
- let span = hir_lifetime. span ;
1402
- let id = hir_lifetime. id ;
1403
- debug ! (
1404
- "id ={:?} span = {:?} hir_lifetime = {:?}" ,
1405
- node_id, span, hir_lifetime
1406
- ) ;
1407
-
1408
- self . tcx
1409
- . struct_span_lint_node (
1410
- lint:: builtin:: SINGLE_USE_LIFETIMES ,
1411
- id,
1412
- span,
1413
- & format ! (
1414
- "lifetime parameter `{}` only used once" ,
1415
- hir_lifetime. name. name( )
1416
- ) ,
1417
- )
1418
- . emit ( ) ;
1400
+ if let Some ( ( id, span, name) ) = match self . tcx . hir . get ( node_id) {
1401
+ hir:: map:: NodeLifetime ( hir_lifetime) => {
1402
+ Some ( ( hir_lifetime. id , hir_lifetime. span , hir_lifetime. name . name ( ) ) )
1403
+ }
1404
+ hir:: map:: NodeGenericParam ( param) => {
1405
+ Some ( ( param. id , param. span , param. name ) )
1406
+ }
1407
+ _ => None ,
1408
+ } {
1409
+ debug ! ( "id = {:?} span = {:?} name = {:?}" , node_id, span, name) ;
1410
+ self . tcx . struct_span_lint_node (
1411
+ lint:: builtin:: SINGLE_USE_LIFETIMES ,
1412
+ id,
1413
+ span,
1414
+ & format ! ( "lifetime parameter `{}` only used once" , name) ,
1415
+ ) . emit ( ) ;
1419
1416
}
1420
1417
}
1421
1418
Some ( LifetimeUseSet :: Many ) => {
1422
1419
debug ! ( "Not one use lifetime" ) ;
1423
1420
}
1424
1421
None => {
1425
1422
let node_id = self . tcx . hir . as_local_node_id ( def_id) . unwrap ( ) ;
1426
- if let hir:: map:: NodeLifetime ( hir_lifetime) = self . tcx . hir . get ( node_id) {
1427
- let span = hir_lifetime. span ;
1428
- let id = hir_lifetime. id ;
1429
-
1430
- self . tcx
1431
- . struct_span_lint_node (
1432
- lint:: builtin:: UNUSED_LIFETIMES ,
1433
- id,
1434
- span,
1435
- & format ! (
1436
- "lifetime parameter `{}` never used" ,
1437
- hir_lifetime. name. name( )
1438
- ) ,
1439
- )
1440
- . emit ( ) ;
1423
+ if let Some ( ( id, span, name) ) = match self . tcx . hir . get ( node_id) {
1424
+ hir:: map:: NodeLifetime ( hir_lifetime) => {
1425
+ Some ( ( hir_lifetime. id , hir_lifetime. span , hir_lifetime. name . name ( ) ) )
1426
+ }
1427
+ hir:: map:: NodeGenericParam ( param) => {
1428
+ Some ( ( param. id , param. span , param. name ) )
1429
+ }
1430
+ _ => None ,
1431
+ } {
1432
+ debug ! ( "id ={:?} span = {:?} name = {:?}" , node_id, span, name) ;
1433
+ self . tcx . struct_span_lint_node (
1434
+ lint:: builtin:: UNUSED_LIFETIMES ,
1435
+ id,
1436
+ span,
1437
+ & format ! ( "lifetime parameter `{}` never used" , name)
1438
+ ) . emit ( ) ;
1441
1439
}
1442
1440
}
1443
1441
}
0 commit comments