@@ -59,7 +59,7 @@ impl LintPass for LifetimePass {
5959
6060impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for LifetimePass {
6161 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 {
6363 check_fn_inner ( cx, decl, Some ( id) , generics, item. span ) ;
6464 }
6565 }
@@ -101,23 +101,31 @@ fn check_fn_inner<'a, 'tcx>(
101101 }
102102
103103 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 {
105109 for bound in & typ. bounds {
106110 let mut visitor = RefVisitor :: new ( cx) ;
107- walk_ty_param_bound ( & mut visitor, bound) ;
111+ walk_param_bound ( & mut visitor, bound) ;
108112 if visitor. lts . iter ( ) . any ( |lt| matches ! ( lt, RefLt :: Named ( _) ) ) {
109113 return ;
110114 }
111- if let TraitTyParamBound ( ref trait_ref, _) = * bound {
115+ if let GenericBound :: Trait ( ref trait_ref, _) = * bound {
112116 let params = & trait_ref
113117 . trait_ref
114118 . path
115119 . segments
116120 . last ( )
117121 . expect ( "a path must have at least one segment" )
118- . parameters ;
122+ . args ;
119123 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 {
121129 if bound. name . name ( ) != "'static" && !bound. is_elided ( ) {
122130 return ;
123131 }
@@ -230,9 +238,9 @@ fn could_use_elision<'a, 'tcx: 'a>(
230238fn allowed_lts_from ( named_generics : & [ GenericParam ] ) -> HashSet < RefLt > {
231239 let mut allowed_lts = HashSet :: new ( ) ;
232240 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 ( ) ) ) ;
236244 }
237245 }
238246 }
@@ -295,8 +303,12 @@ impl<'v, 't> RefVisitor<'v, 't> {
295303 }
296304
297305 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+ } ) {
300312 let hir_id = self . cx . tcx . hir . node_to_hir_id ( ty. id ) ;
301313 match self . cx . tables . qpath_def ( qpath, hir_id) {
302314 Def :: TyAlias ( def_id) | Def :: Struct ( def_id) => {
@@ -335,7 +347,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
335347 TyImplTraitExistential ( exist_ty_id, _, _) => {
336348 if let ItemExistential ( ref exist_ty) = self . cx . tcx . hir . expect_item ( exist_ty_id. id ) . node {
337349 for bound in & exist_ty. bounds {
338- if let RegionTyParamBound ( _) = * bound {
350+ if let GenericBound :: Outlives ( _) = * bound {
339351 self . record ( & None ) ;
340352 }
341353 }
@@ -377,7 +389,7 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
377389 let allowed_lts = allowed_lts_from ( & pred. bound_generic_params ) ;
378390 // now walk the bounds
379391 for bound in pred. bounds . iter ( ) {
380- walk_ty_param_bound ( & mut visitor, bound) ;
392+ walk_param_bound ( & mut visitor, bound) ;
381393 }
382394 // and check that all lifetimes are allowed
383395 match visitor. into_vec ( ) {
@@ -418,7 +430,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
418430 // don't want to spuriously remove them
419431 // `'b` in `'a: 'b` is useless unless used elsewhere in
420432 // a non-lifetime bound
421- if param. is_type_param ( ) {
433+ if let GenericParamKind :: Type { .. } = param. kind {
422434 walk_generic_param ( self , param)
423435 }
424436 }
@@ -428,9 +440,11 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
428440}
429441
430442fn 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+ } )
434448 . collect ( ) ;
435449 let mut checker = LifetimeChecker { map : hs } ;
436450
0 commit comments