]> git.lizzy.rs Git - rust.git/commitdiff
don't ignore expression after first not matched method call in PtrCloneVisitor
authorAleksei Latyshev <alex_700_95@mail.ru>
Sun, 27 Dec 2020 22:09:04 +0000 (01:09 +0300)
committerAleksei Latyshev <alex_700_95@mail.ru>
Sun, 27 Dec 2020 22:09:04 +0000 (01:09 +0300)
clippy_lints/src/utils/ptr.rs
tests/ui/ptr_arg.rs
tests/ui/ptr_arg.stderr

index bd2c619f00028167c4b730a3966cc3a31130aed9..b330f3d890e9cc6e4a3823629e30a0cb2f04d942 100644 (file)
@@ -72,7 +72,6 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
                     }
                 }
             }
-            return;
         }
         walk_expr(self, expr);
     }
index e8854fb73d966672bb8a0de0645053527f68215d..06370dfce65188899dda939fb0dbee8e561c7170 100644 (file)
@@ -136,3 +136,22 @@ fn allowed(
         }
     }
 }
+
+mod issue6509 {
+    use std::path::PathBuf;
+
+    fn foo_vec(vec: &Vec<u8>) {
+        let _ = vec.clone().pop();
+        let _ = vec.clone().clone();
+    }
+
+    fn foo_path(path: &PathBuf) {
+        let _ = path.clone().pop();
+        let _ = path.clone().clone();
+    }
+
+    fn foo_str(str: &PathBuf) {
+        let _ = str.clone().pop();
+        let _ = str.clone().clone();
+    }
+}
index 70d1b2f5258eb5055239b81d5a817c8f89b9d7c9..708318bbe295c410f4dd20370842f9c2ce95e648 100644 (file)
@@ -114,5 +114,62 @@ error: using a reference to `Cow` is not recommended.
 LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
    |                         ^^^^^^^^^^^ help: change this to: `&[i32]`
 
-error: aborting due to 9 previous errors
+error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
+  --> $DIR/ptr_arg.rs:143:21
+   |
+LL |     fn foo_vec(vec: &Vec<u8>) {
+   |                     ^^^^^^^^
+   |
+help: change this to
+   |
+LL |     fn foo_vec(vec: &[u8]) {
+   |                     ^^^^^
+help: change `vec.clone()` to
+   |
+LL |         let _ = vec.to_owned().pop();
+   |                 ^^^^^^^^^^^^^^
+help: change `vec.clone()` to
+   |
+LL |         let _ = vec.to_owned().clone();
+   |                 ^^^^^^^^^^^^^^
+
+error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
+  --> $DIR/ptr_arg.rs:148:23
+   |
+LL |     fn foo_path(path: &PathBuf) {
+   |                       ^^^^^^^^
+   |
+help: change this to
+   |
+LL |     fn foo_path(path: &Path) {
+   |                       ^^^^^
+help: change `path.clone()` to
+   |
+LL |         let _ = path.to_path_buf().pop();
+   |                 ^^^^^^^^^^^^^^^^^^
+help: change `path.clone()` to
+   |
+LL |         let _ = path.to_path_buf().clone();
+   |                 ^^^^^^^^^^^^^^^^^^
+
+error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
+  --> $DIR/ptr_arg.rs:153:21
+   |
+LL |     fn foo_str(str: &PathBuf) {
+   |                     ^^^^^^^^
+   |
+help: change this to
+   |
+LL |     fn foo_str(str: &Path) {
+   |                     ^^^^^
+help: change `str.clone()` to
+   |
+LL |         let _ = str.to_path_buf().pop();
+   |                 ^^^^^^^^^^^^^^^^^
+help: change `str.clone()` to
+   |
+LL |         let _ = str.to_path_buf().clone();
+   |                 ^^^^^^^^^^^^^^^^^
+
+error: aborting due to 12 previous errors