@@ -59,7 +59,7 @@ impl LintPass for LifetimePass {
59
59
60
60
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for LifetimePass {
61
61
fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item ) {
62
- if let ItemFn ( ref decl, _, _ , _ , ref generics, id) = item. node {
62
+ if let ItemFn ( ref decl, _, ref generics, id) = item. node {
63
63
check_fn_inner ( cx, decl, Some ( id) , generics, item. span ) ;
64
64
}
65
65
}
@@ -101,23 +101,31 @@ fn check_fn_inner<'a, 'tcx>(
101
101
}
102
102
103
103
let mut bounds_lts = Vec :: new ( ) ;
104
- for typ in generics. ty_params ( ) {
104
+ let types = generics. params . iter ( ) . filter_map ( |param| match param. kind {
105
+ GenericParamKind :: Type { .. } => Some ( param) ,
106
+ GenericParamKind :: Lifetime { .. } => None ,
107
+ } ) ;
108
+ for typ in types {
105
109
for bound in & typ. bounds {
106
110
let mut visitor = RefVisitor :: new ( cx) ;
107
- walk_ty_param_bound ( & mut visitor, bound) ;
111
+ walk_param_bound ( & mut visitor, bound) ;
108
112
if visitor. lts . iter ( ) . any ( |lt| matches ! ( lt, RefLt :: Named ( _) ) ) {
109
113
return ;
110
114
}
111
- if let TraitTyParamBound ( ref trait_ref, _) = * bound {
115
+ if let GenericBound :: Trait ( ref trait_ref, _) = * bound {
112
116
let params = & trait_ref
113
117
. trait_ref
114
118
. path
115
119
. segments
116
120
. last ( )
117
121
. expect ( "a path must have at least one segment" )
118
- . parameters ;
122
+ . args ;
119
123
if let Some ( ref params) = * params {
120
- for bound in & params. lifetimes {
124
+ let lifetimes = params. args . iter ( ) . filter_map ( |arg| match arg {
125
+ GenericArg :: Lifetime ( lt) => Some ( lt) ,
126
+ GenericArg :: Type ( _) => None ,
127
+ } ) ;
128
+ for bound in lifetimes {
121
129
if bound. name . name ( ) != "'static" && !bound. is_elided ( ) {
122
130
return ;
123
131
}
@@ -230,9 +238,9 @@ fn could_use_elision<'a, 'tcx: 'a>(
230
238
fn allowed_lts_from ( named_generics : & [ GenericParam ] ) -> HashSet < RefLt > {
231
239
let mut allowed_lts = HashSet :: new ( ) ;
232
240
for par in named_generics. iter ( ) {
233
- if let GenericParam :: Lifetime ( ref lt ) = * par {
234
- if lt . bounds . is_empty ( ) {
235
- allowed_lts. insert ( RefLt :: Named ( lt . lifetime . name . name ( ) ) ) ;
241
+ if let GenericParamKind :: Lifetime { .. } = par. kind {
242
+ if par . bounds . is_empty ( ) {
243
+ allowed_lts. insert ( RefLt :: Named ( par . name . name ( ) ) ) ;
236
244
}
237
245
}
238
246
}
@@ -295,8 +303,12 @@ impl<'v, 't> RefVisitor<'v, 't> {
295
303
}
296
304
297
305
fn collect_anonymous_lifetimes ( & mut self , qpath : & QPath , ty : & Ty ) {
298
- if let Some ( ref last_path_segment) = last_path_segment ( qpath) . parameters {
299
- if !last_path_segment. parenthesized && last_path_segment. lifetimes . is_empty ( ) {
306
+ if let Some ( ref last_path_segment) = last_path_segment ( qpath) . args {
307
+ if !last_path_segment. parenthesized
308
+ && !last_path_segment. args . iter ( ) . any ( |arg| match arg {
309
+ GenericArg :: Lifetime ( _) => true ,
310
+ GenericArg :: Type ( _) => false ,
311
+ } ) {
300
312
let hir_id = self . cx . tcx . hir . node_to_hir_id ( ty. id ) ;
301
313
match self . cx . tables . qpath_def ( qpath, hir_id) {
302
314
Def :: TyAlias ( def_id) | Def :: Struct ( def_id) => {
@@ -335,7 +347,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
335
347
TyImplTraitExistential ( exist_ty_id, _, _) => {
336
348
if let ItemExistential ( ref exist_ty) = self . cx . tcx . hir . expect_item ( exist_ty_id. id ) . node {
337
349
for bound in & exist_ty. bounds {
338
- if let RegionTyParamBound ( _) = * bound {
350
+ if let GenericBound :: Outlives ( _) = * bound {
339
351
self . record ( & None ) ;
340
352
}
341
353
}
@@ -377,7 +389,7 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
377
389
let allowed_lts = allowed_lts_from ( & pred. bound_generic_params ) ;
378
390
// now walk the bounds
379
391
for bound in pred. bounds . iter ( ) {
380
- walk_ty_param_bound ( & mut visitor, bound) ;
392
+ walk_param_bound ( & mut visitor, bound) ;
381
393
}
382
394
// and check that all lifetimes are allowed
383
395
match visitor. into_vec ( ) {
@@ -418,7 +430,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
418
430
// don't want to spuriously remove them
419
431
// `'b` in `'a: 'b` is useless unless used elsewhere in
420
432
// a non-lifetime bound
421
- if param. is_type_param ( ) {
433
+ if let GenericParamKind :: Type { .. } = param. kind {
422
434
walk_generic_param ( self , param)
423
435
}
424
436
}
@@ -428,9 +440,11 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
428
440
}
429
441
430
442
fn report_extra_lifetimes < ' a , ' tcx : ' a > ( cx : & LateContext < ' a , ' tcx > , func : & ' tcx FnDecl , generics : & ' tcx Generics ) {
431
- let hs = generics
432
- . lifetimes ( )
433
- . map ( |lt| ( lt. lifetime . name . name ( ) , lt. lifetime . span ) )
443
+ let hs = generics. params . iter ( )
444
+ . filter_map ( |par| match par. kind {
445
+ GenericParamKind :: Lifetime { .. } => Some ( ( par. name . name ( ) , par. span ) ) ,
446
+ _ => None ,
447
+ } )
434
448
. collect ( ) ;
435
449
let mut checker = LifetimeChecker { map : hs } ;
436
450
0 commit comments