diff options
| author | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2020-01-08 13:59:58 +0900 |
|---|---|---|
| committer | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2020-01-08 14:18:00 +0900 |
| commit | 99eec3f54fb3c77db580699a40dc428e56942b40 (patch) | |
| tree | 7c6133d6543a055e497f14d5e88532b0072f6723 | |
| parent | c09206899656f5730f8007dbc86385122c34a9ca (diff) | |
| download | rust-99eec3f54fb3c77db580699a40dc428e56942b40.tar.gz rust-99eec3f54fb3c77db580699a40dc428e56942b40.zip | |
Fix `redundant_clone`
| -rw-r--r-- | clippy_lints/src/redundant_clone.rs | 7 | ||||
| -rw-r--r-- | tests/ui/redundant_clone.fixed | 4 | ||||
| -rw-r--r-- | tests/ui/redundant_clone.stderr | 26 |
3 files changed, 34 insertions, 3 deletions
diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 12c99bc8f9b..2b475efbd76 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -307,6 +307,13 @@ fn find_stmt_assigns_to<'tcx>( (true, mir::Rvalue::Ref(_, _, place)) | (false, mir::Rvalue::Use(mir::Operand::Copy(place))) => { base_local_and_movability(cx, mir, place) }, + (false, mir::Rvalue::Ref(_, _, place)) => { + if let [mir::ProjectionElem::Deref] = place.as_ref().projection { + base_local_and_movability(cx, mir, place) + } else { + None + } + }, _ => None, } } diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index e5e706e8483..84931f66fa8 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -18,11 +18,11 @@ fn main() { let _s = Path::new("/a/b/").join("c"); - let _s = Path::new("/a/b/").join("c").to_path_buf(); + let _s = Path::new("/a/b/").join("c"); let _s = OsString::new(); - let _s = OsString::new().to_os_string(); + let _s = OsString::new(); // Check that lint level works #[allow(clippy::redundant_clone)] diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 62f4ce7645e..0f185cda019 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -60,6 +60,18 @@ LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone + --> $DIR/redundant_clone.rs:21:42 + | +LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); + | ^^^^^^^^^^^^^^ help: remove this + | +note: this value is dropped without further use + --> $DIR/redundant_clone.rs:21:14 + | +LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: redundant clone --> $DIR/redundant_clone.rs:23:29 | LL | let _s = OsString::new().to_owned(); @@ -72,6 +84,18 @@ LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ error: redundant clone + --> $DIR/redundant_clone.rs:25:29 + | +LL | let _s = OsString::new().to_os_string(); + | ^^^^^^^^^^^^^^^ help: remove this + | +note: this value is dropped without further use + --> $DIR/redundant_clone.rs:25:14 + | +LL | let _s = OsString::new().to_os_string(); + | ^^^^^^^^^^^^^^^ + +error: redundant clone --> $DIR/redundant_clone.rs:32:19 | LL | let _t = tup.0.clone(); @@ -131,5 +155,5 @@ note: this value is dropped without further use LL | let _f = f.clone(); | ^ -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors |
