1 #![warn(clippy::redundant_clone)]
3 use std::ffi::OsString;
7 let _ = ["lorem", "ipsum"].join(" ").to_string();
9 let s = String::from("foo");
12 let s = String::from("foo");
13 let _ = s.to_string();
15 let s = String::from("foo");
18 let _ = Path::new("/a/b/").join("c").to_owned();
20 let _ = Path::new("/a/b/").join("c").to_path_buf();
22 let _ = OsString::new().to_owned();
24 let _ = OsString::new().to_os_string();
26 // Check that lint level works
27 #[allow(clippy::redundant_clone)]
28 let _ = String::new().to_string();
30 let tup = (String::from("foo"),);
31 let _ = tup.0.clone();
33 let tup_ref = &(String::from("foo"),);
34 let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed
37 let x = String::new();
40 let _ = x.clone(); // ok; `x` is borrowed by `y`
45 let x = (String::new(),);
46 let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x`
51 fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
53 (a.clone(), a.clone())
63 impl Drop for TypeWithDrop {
67 fn cannot_move_from_type_with_drop() -> String {
68 let s = TypeWithDrop { x: String::new() };
69 s.x.clone() // removing this `clone()` summons E0509
72 fn borrower_propagation() {
73 let s = String::new();
74 let t = String::new();
80 let u = if b() { &s } else { &t };
82 // ok; `s` and `t` are possibly borrowed
90 let _ = s.clone(); // ok
91 let _ = t.clone(); // ok
97 let _ = s.clone(); // ok
100 let _ = s.clone(); // ok
104 use std::convert::identity as id;
106 let _ = s.clone(); // ok, `u` borrows `s`
118 let f = Foo { x: 123 };
124 let f = Foo { x: 123 };
126 let _f = f.clone(); // ok