]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/redundant_clone.rs
iterate List by value
[rust.git] / tests / ui / redundant_clone.rs
index aee6855eea94bd3bf633e51d4bc55d9581d7f9a1..839747b131d77da22c7d559d0133f7006bd2d246 100644 (file)
@@ -51,6 +51,7 @@ fn main() {
     cannot_move_from_type_with_drop();
     borrower_propagation();
     not_consumed();
+    issue_5405();
 }
 
 #[derive(Clone)]
@@ -150,4 +151,22 @@ fn not_consumed() {
     s.clone().push_str("foo"); // OK, removing this `clone()` will change the behavior.
     s.push_str("bar");
     assert_eq!(s, "bar");
+
+    let t = Some(s);
+    // OK
+    if let Some(x) = t.clone() {
+        println!("{}", x);
+    }
+    if let Some(x) = t {
+        println!("{}", x);
+    }
+}
+
+#[allow(clippy::clone_on_copy)]
+fn issue_5405() {
+    let a: [String; 1] = [String::from("foo")];
+    let _b: String = a[0].clone();
+
+    let c: [usize; 2] = [2, 3];
+    let _d: usize = c[1].clone();
 }