]> git.lizzy.rs Git - rust.git/commitdiff
needless-lifetime / pr remarks
authorTim Nielens <tim.nielens@gmail.com>
Tue, 29 Sep 2020 22:33:46 +0000 (00:33 +0200)
committerTim Nielens <tim.nielens@gmail.com>
Tue, 29 Sep 2020 22:33:46 +0000 (00:33 +0200)
clippy_lints/src/lifetimes.rs
tests/ui/needless_lifetimes.rs
tests/ui/needless_lifetimes.stderr

index 530968c191f9643dbff3612d4a5c344ac781cb5c..d7043e7bd8f713ce010fc84c48ef2f70fb48ace2 100644 (file)
@@ -383,6 +383,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
                 let mut sub_visitor = RefVisitor::new(self.cx);
                 sub_visitor.visit_fn_decl(decl);
                 self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
+                return;
             },
             TyKind::TraitObject(bounds, ref lt) => {
                 if !lt.is_elided() {
index 548c5929c6120d464380da6034bb1b000454191b..d482d466e44990df8f0fdcb19d4d4f6fbafc0bbf 100644 (file)
@@ -336,9 +336,25 @@ fn pointer_fn_in_output_position<'a>(_: &'a i32) -> fn(&'a i32) -> &'a i32 {
         |i| i
     }
     // lint
-    fn pointer_fn_elidable<'a>(f: fn(&i32) -> &i32, i: &'a i32) -> &'a i32 {
+    fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
         f(i)
     }
+
+    // don't lint
+    fn nested_fn_pointer_1<'a>(_: &'a i32) -> fn(fn(&'a i32) -> &'a i32) -> i32 {
+        |f| 42
+    }
+    fn nested_fn_pointer_2<'a>(_: &'a i32) -> impl Fn(fn(&'a i32)) {
+        |f| ()
+    }
+
+    // lint
+    fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
+        |f| 42
+    }
+    fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
+        |f| ()
+    }
 }
 
 fn main() {}
index ac38ab8effd2e35a05d0a6a09312c926384edf6b..c8a2e8b81c019a22908b931687725b5f8c3b15e1 100644 (file)
@@ -132,5 +132,23 @@ error: explicit lifetimes given in parameter types where they could be elided (o
 LL |     fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 22 previous errors
+error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+  --> $DIR/needless_lifetimes.rs:339:5
+   |
+LL |     fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+  --> $DIR/needless_lifetimes.rs:352:5
+   |
+LL |     fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+  --> $DIR/needless_lifetimes.rs:355:5
+   |
+LL |     fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 25 previous errors