@@ -2,7 +2,7 @@ use reexport::*;
22use rustc:: lint:: * ;
33use rustc:: hir:: def:: Def ;
44use rustc:: hir:: * ;
5- use rustc:: hir:: intravisit:: { walk_fn_decl , walk_generics , walk_ty , walk_ty_param_bound , NestedVisitorMap , Visitor } ;
5+ use rustc:: hir:: intravisit:: * ;
66use std:: collections:: { HashMap , HashSet } ;
77use syntax:: codemap:: Span ;
88use utils:: { in_external_macro, last_path_segment, span_lint} ;
@@ -101,7 +101,7 @@ fn check_fn_inner<'a, 'tcx>(
101101 }
102102
103103 let mut bounds_lts = Vec :: new ( ) ;
104- for typ in & generics. ty_params {
104+ for typ in generics. ty_params ( ) {
105105 for bound in & typ. bounds {
106106 if let TraitTyParamBound ( ref trait_ref, _) = * bound {
107107 let params = & trait_ref
@@ -122,7 +122,7 @@ fn check_fn_inner<'a, 'tcx>(
122122 }
123123 }
124124 }
125- if could_use_elision ( cx, decl, body, & generics. lifetimes , bounds_lts) {
125+ if could_use_elision ( cx, decl, body, & generics. params , bounds_lts) {
126126 span_lint (
127127 cx,
128128 NEEDLESS_LIFETIMES ,
@@ -137,7 +137,7 @@ fn could_use_elision<'a, 'tcx: 'a>(
137137 cx : & LateContext < ' a , ' tcx > ,
138138 func : & ' tcx FnDecl ,
139139 body : Option < BodyId > ,
140- named_lts : & ' tcx [ LifetimeDef ] ,
140+ named_generics : & ' tcx [ GenericParam ] ,
141141 bounds_lts : Vec < & ' tcx Lifetime > ,
142142) -> bool {
143143 // There are two scenarios where elision works:
@@ -147,7 +147,7 @@ fn could_use_elision<'a, 'tcx: 'a>(
147147 // level of the current item.
148148
149149 // check named LTs
150- let allowed_lts = allowed_lts_from ( named_lts ) ;
150+ let allowed_lts = allowed_lts_from ( named_generics ) ;
151151
152152 // these will collect all the lifetimes for references in arg/return types
153153 let mut input_visitor = RefVisitor :: new ( cx) ;
@@ -222,11 +222,13 @@ fn could_use_elision<'a, 'tcx: 'a>(
222222 }
223223}
224224
225- fn allowed_lts_from ( named_lts : & [ LifetimeDef ] ) -> HashSet < RefLt > {
225+ fn allowed_lts_from ( named_generics : & [ GenericParam ] ) -> HashSet < RefLt > {
226226 let mut allowed_lts = HashSet :: new ( ) ;
227- for lt in named_lts {
228- if lt. bounds . is_empty ( ) {
229- allowed_lts. insert ( RefLt :: Named ( lt. lifetime . name . name ( ) ) ) ;
227+ for par in named_generics. iter ( ) {
228+ if let GenericParam :: Lifetime ( ref lt) = * par {
229+ if lt. bounds . is_empty ( ) {
230+ allowed_lts. insert ( RefLt :: Named ( lt. lifetime . name . name ( ) ) ) ;
231+ }
230232 }
231233 }
232234 allowed_lts. insert ( RefLt :: Unnamed ) ;
@@ -370,7 +372,7 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
370372 return true ;
371373 }
372374 // if the bounds define new lifetimes, they are fine to occur
373- let allowed_lts = allowed_lts_from ( & pred. bound_lifetimes ) ;
375+ let allowed_lts = allowed_lts_from ( & pred. bound_generic_params ) ;
374376 // now walk the bounds
375377 for bound in pred. bounds . iter ( ) {
376378 walk_ty_param_bound ( & mut visitor, bound) ;
@@ -408,12 +410,15 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
408410 self . map . remove ( & lifetime. name . name ( ) ) ;
409411 }
410412
411- fn visit_lifetime_def ( & mut self , _ : & ' tcx LifetimeDef ) {
413+ fn visit_generic_param ( & mut self , param : & ' tcx GenericParam ) {
412414 // don't actually visit `<'a>` or `<'a: 'b>`
413415 // we've already visited the `'a` declarations and
414416 // don't want to spuriously remove them
415417 // `'b` in `'a: 'b` is useless unless used elsewhere in
416418 // a non-lifetime bound
419+ if param. is_type_param ( ) {
420+ walk_generic_param ( self , param)
421+ }
417422 }
418423 fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
419424 NestedVisitorMap :: None
@@ -422,8 +427,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
422427
423428fn report_extra_lifetimes < ' a , ' tcx : ' a > ( cx : & LateContext < ' a , ' tcx > , func : & ' tcx FnDecl , generics : & ' tcx Generics ) {
424429 let hs = generics
425- . lifetimes
426- . iter ( )
430+ . lifetimes ( )
427431 . map ( |lt| ( lt. lifetime . name . name ( ) , lt. lifetime . span ) )
428432 . collect ( ) ;
429433 let mut checker = LifetimeChecker { map : hs } ;
0 commit comments