@@ -46,19 +46,19 @@ impl LintPass for LifetimePass {
46
46
impl LateLintPass for LifetimePass {
47
47
fn check_item ( & mut self , cx : & LateContext , item : & Item ) {
48
48
if let ItemFn ( ref decl, _, _, _, ref generics, _) = item. node {
49
- check_fn_inner ( cx, decl, None , generics, item. span ) ;
49
+ check_fn_inner ( cx, decl, generics, item. span ) ;
50
50
}
51
51
}
52
52
53
53
fn check_impl_item ( & mut self , cx : & LateContext , item : & ImplItem ) {
54
54
if let ImplItemKind :: Method ( ref sig, _) = item. node {
55
- check_fn_inner ( cx, & sig. decl , Some ( & sig . explicit_self ) , & sig. generics , item. span ) ;
55
+ check_fn_inner ( cx, & sig. decl , & sig. generics , item. span ) ;
56
56
}
57
57
}
58
58
59
59
fn check_trait_item ( & mut self , cx : & LateContext , item : & TraitItem ) {
60
60
if let MethodTraitItem ( ref sig, _) = item. node {
61
- check_fn_inner ( cx, & sig. decl , Some ( & sig . explicit_self ) , & sig. generics , item. span ) ;
61
+ check_fn_inner ( cx, & sig. decl , & sig. generics , item. span ) ;
62
62
}
63
63
}
64
64
}
@@ -87,7 +87,7 @@ fn bound_lifetimes(bound: &TyParamBound) -> Option<HirVec<&Lifetime>> {
87
87
}
88
88
}
89
89
90
- fn check_fn_inner ( cx : & LateContext , decl : & FnDecl , slf : Option < & ExplicitSelf > , generics : & Generics , span : Span ) {
90
+ fn check_fn_inner ( cx : & LateContext , decl : & FnDecl , generics : & Generics , span : Span ) {
91
91
if in_external_macro ( cx, span) || has_where_lifetimes ( cx, & generics. where_clause ) {
92
92
return ;
93
93
}
@@ -96,16 +96,16 @@ fn check_fn_inner(cx: &LateContext, decl: &FnDecl, slf: Option<&ExplicitSelf>, g
96
96
. iter ( )
97
97
. flat_map ( |ref typ| typ. bounds . iter ( ) . filter_map ( bound_lifetimes) . flat_map ( |lts| lts) ) ;
98
98
99
- if could_use_elision ( cx, decl, slf , & generics. lifetimes , bounds_lts) {
99
+ if could_use_elision ( cx, decl, & generics. lifetimes , bounds_lts) {
100
100
span_lint ( cx,
101
101
NEEDLESS_LIFETIMES ,
102
102
span,
103
103
"explicit lifetimes given in parameter types where they could be elided" ) ;
104
104
}
105
- report_extra_lifetimes ( cx, decl, generics, slf ) ;
105
+ report_extra_lifetimes ( cx, decl, generics) ;
106
106
}
107
107
108
- fn could_use_elision < ' a , T : Iterator < Item = & ' a Lifetime > > ( cx : & LateContext , func : & FnDecl , slf : Option < & ExplicitSelf > ,
108
+ fn could_use_elision < ' a , T : Iterator < Item = & ' a Lifetime > > ( cx : & LateContext , func : & FnDecl ,
109
109
named_lts : & [ LifetimeDef ] , bounds_lts : T )
110
110
-> bool {
111
111
// There are two scenarios where elision works:
@@ -121,15 +121,6 @@ fn could_use_elision<'a, T: Iterator<Item = &'a Lifetime>>(cx: &LateContext, fun
121
121
let mut input_visitor = RefVisitor :: new ( cx) ;
122
122
let mut output_visitor = RefVisitor :: new ( cx) ;
123
123
124
- // extract lifetime in "self" argument for methods (there is a "self" argument
125
- // in func.inputs, but its type is TyInfer)
126
- if let Some ( slf) = slf {
127
- match slf. node {
128
- SelfRegion ( ref opt_lt, _, _) => input_visitor. record ( opt_lt) ,
129
- SelfExplicit ( ref ty, _) => walk_ty ( & mut input_visitor, ty) ,
130
- _ => ( ) ,
131
- }
132
- }
133
124
// extract lifetimes in input argument types
134
125
for arg in & func. inputs {
135
126
input_visitor. visit_ty ( & arg. ty ) ;
@@ -340,7 +331,7 @@ impl<'v> Visitor<'v> for LifetimeChecker {
340
331
}
341
332
}
342
333
343
- fn report_extra_lifetimes ( cx : & LateContext , func : & FnDecl , generics : & Generics , slf : Option < & ExplicitSelf > ) {
334
+ fn report_extra_lifetimes ( cx : & LateContext , func : & FnDecl , generics : & Generics ) {
344
335
let hs = generics. lifetimes
345
336
. iter ( )
346
337
. map ( |lt| ( lt. lifetime . name , lt. lifetime . span ) )
@@ -350,14 +341,6 @@ fn report_extra_lifetimes(cx: &LateContext, func: &FnDecl, generics: &Generics,
350
341
walk_generics ( & mut checker, generics) ;
351
342
walk_fn_decl ( & mut checker, func) ;
352
343
353
- if let Some ( slf) = slf {
354
- match slf. node {
355
- SelfRegion ( Some ( ref lt) , _, _) => checker. visit_lifetime ( lt) ,
356
- SelfExplicit ( ref t, _) => walk_ty ( & mut checker, t) ,
357
- _ => ( ) ,
358
- }
359
- }
360
-
361
344
for & v in checker. 0 . values ( ) {
362
345
span_lint ( cx, UNUSED_LIFETIMES , v, "this lifetime isn't used in the function definition" ) ;
363
346
}
0 commit comments