Skip to content

Commit

Permalink
Fix redundant_clone
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Jan 8, 2020
1 parent c092068 commit a9d44be
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions clippy_lints/src/redundant_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 place.local_or_deref_local().is_some() {
base_local_and_movability(cx, mir, place)
} else {
None
}
},
_ => None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/redundant_clone.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
26 changes: 25 additions & 1 deletion tests/ui/redundant_clone.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ note: this value is dropped without further use
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
|
Expand All @@ -71,6 +83,18 @@ note: this value is dropped without further use
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
|
Expand Down Expand Up @@ -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

0 comments on commit a9d44be

Please sign in to comment.