Skip to content

Commit cb2be6f

Browse files
committed
needless-lifetime / pr remarks
1 parent aa2ac38 commit cb2be6f

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

clippy_lints/src/lifetimes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
383383
let mut sub_visitor = RefVisitor::new(self.cx);
384384
sub_visitor.visit_fn_decl(decl);
385385
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
386+
return;
386387
},
387388
TyKind::TraitObject(bounds, ref lt) => {
388389
if !lt.is_elided() {

tests/ui/needless_lifetimes.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,25 @@ mod nested_elision_sites {
336336
|i| i
337337
}
338338
// lint
339-
fn pointer_fn_elidable<'a>(f: fn(&i32) -> &i32, i: &'a i32) -> &'a i32 {
339+
fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
340340
f(i)
341341
}
342+
343+
// don't lint
344+
fn nested_fn_pointer_1<'a>(_: &'a i32) -> fn(fn(&'a i32) -> &'a i32) -> i32 {
345+
|f| 42
346+
}
347+
fn nested_fn_pointer_2<'a>(_: &'a i32) -> impl Fn(fn(&'a i32)) {
348+
|f| ()
349+
}
350+
351+
// lint
352+
fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
353+
|f| 42
354+
}
355+
fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
356+
|f| ()
357+
}
342358
}
343359

344360
fn main() {}

tests/ui/needless_lifetimes.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,23 @@ error: explicit lifetimes given in parameter types where they could be elided (o
132132
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
133133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134134

135-
error: aborting due to 22 previous errors
135+
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
136+
--> $DIR/needless_lifetimes.rs:339:5
137+
|
138+
LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140+
141+
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
142+
--> $DIR/needless_lifetimes.rs:352:5
143+
|
144+
LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
145+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146+
147+
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
148+
--> $DIR/needless_lifetimes.rs:355:5
149+
|
150+
LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
151+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152+
153+
error: aborting due to 25 previous errors
136154

0 commit comments

Comments
 (0)