@@ -89,29 +89,31 @@ enum RefLt {
89
89
Named ( Name ) ,
90
90
}
91
91
92
- fn bound_lifetimes ( bound : & TyParamBound ) -> HirVec < & Lifetime > {
93
- if let TraitTyParamBound ( ref trait_ref, _) = * bound {
94
- trait_ref. trait_ref
95
- . path
96
- . segments
97
- . last ( )
98
- . expect ( "a path must have at least one segment" )
99
- . parameters
100
- . lifetimes ( )
101
- } else {
102
- HirVec :: new ( )
103
- }
104
- }
105
-
106
92
fn check_fn_inner < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , decl : & ' tcx FnDecl , body : Option < BodyId > , generics : & ' tcx Generics , span : Span ) {
107
93
if in_external_macro ( cx, span) || has_where_lifetimes ( cx, & generics. where_clause ) {
108
94
return ;
109
95
}
110
96
111
- let bounds_lts = generics. ty_params
112
- . iter ( )
113
- . flat_map ( |typ| typ. bounds . iter ( ) . flat_map ( bound_lifetimes) ) ;
114
-
97
+ let mut bounds_lts = Vec :: new ( ) ;
98
+ for typ in & generics. ty_params {
99
+ for bound in & typ. bounds {
100
+ if let TraitTyParamBound ( ref trait_ref, _) = * bound {
101
+ let bounds = trait_ref. trait_ref
102
+ . path
103
+ . segments
104
+ . last ( )
105
+ . expect ( "a path must have at least one segment" )
106
+ . parameters
107
+ . lifetimes ( ) ;
108
+ for bound in bounds {
109
+ if bound. name != "'static" && !bound. is_elided ( ) {
110
+ return ;
111
+ }
112
+ bounds_lts. push ( bound) ;
113
+ }
114
+ }
115
+ }
116
+ }
115
117
if could_use_elision ( cx, decl, body, & generics. lifetimes , bounds_lts) {
116
118
span_lint ( cx,
117
119
NEEDLESS_LIFETIMES ,
@@ -121,12 +123,12 @@ fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body
121
123
report_extra_lifetimes ( cx, decl, generics) ;
122
124
}
123
125
124
- fn could_use_elision < ' a , ' tcx : ' a , T : Iterator < Item = & ' tcx Lifetime > > (
126
+ fn could_use_elision < ' a , ' tcx : ' a > (
125
127
cx : & LateContext < ' a , ' tcx > ,
126
128
func : & ' tcx FnDecl ,
127
129
body : Option < BodyId > ,
128
130
named_lts : & ' tcx [ LifetimeDef ] ,
129
- bounds_lts : T
131
+ bounds_lts : Vec < & ' tcx Lifetime > ,
130
132
) -> bool {
131
133
// There are two scenarios where elision works:
132
134
// * no output references, all input references have different LT
@@ -151,7 +153,7 @@ fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(
151
153
}
152
154
153
155
let input_lts = match input_visitor. into_vec ( ) {
154
- Some ( lts) => lts_from_bounds ( lts, bounds_lts) ,
156
+ Some ( lts) => lts_from_bounds ( lts, bounds_lts. into_iter ( ) ) ,
155
157
None => return false ,
156
158
} ;
157
159
let output_lts = match output_visitor. into_vec ( ) {
0 commit comments