2 // rustfix-only-machine-applicable
3 use std::ffi::OsString;
7 let _s = ["lorem", "ipsum"].join(" ").to_string();
9 let s = String::from("foo");
12 let s = String::from("foo");
13 let _s = s.to_string();
15 let s = String::from("foo");
16 let _s = s.to_owned();
18 let _s = Path::new("/a/b/").join("c").to_owned();
20 let _s = Path::new("/a/b/").join("c").to_path_buf();
22 let _s = OsString::new().to_owned();
24 let _s = OsString::new().to_os_string();
26 // Check that lint level works
27 #[allow(clippy::redundant_clone)]
28 let _s = String::new().to_string();
30 let tup = (String::from("foo"),);
31 let _t = 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 = 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`
48 with_branch(Alpha, true);
49 cannot_move_from_type_with_drop();
50 borrower_propagation();
55 fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
57 (a.clone(), a.clone())
67 impl Drop for TypeWithDrop {
71 fn cannot_move_from_type_with_drop() -> String {
72 let s = TypeWithDrop { x: String::new() };
73 s.x.clone() // removing this `clone()` summons E0509
76 fn borrower_propagation() {
77 let s = String::new();
78 let t = String::new();
84 let _u = if b() { &s } else { &t };
86 // ok; `s` and `t` are possibly borrowed
94 let _s = s.clone(); // ok
95 let _t = t.clone(); // ok
101 let _ = s.clone(); // ok
104 let _s = s.clone(); // ok
108 use std::convert::identity as id;
110 let _s = s.clone(); // ok, `u` borrows `s`
122 let f = Foo { x: 123 };
128 let f = Foo { x: 123 };
130 let _f = f.clone(); // ok