]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/unnecessary_clone.rs
iterate List by value
[rust.git] / tests / ui / unnecessary_clone.rs
index 2e0fc122778191ccacd46317f734755d4ba236a3..f1cc5b564c1dca66329e21bf9b3c02cc22c7ce4d 100644 (file)
@@ -1,9 +1,9 @@
+// does not test any rustfixable lints
+
 #![warn(clippy::clone_on_ref_ptr)]
-#![allow(unused)]
+#![allow(unused, clippy::redundant_clone)]
 
 use std::cell::RefCell;
-use std::collections::HashSet;
-use std::collections::VecDeque;
 use std::rc::{self, Rc};
 use std::sync::{self, Arc};
 
@@ -13,6 +13,10 @@ impl SomeTrait for SomeImpl {}
 
 fn main() {}
 
+fn is_ascii(ch: char) -> bool {
+    ch.is_ascii()
+}
+
 fn clone_on_copy() {
     42.clone();
 
@@ -22,6 +26,16 @@ fn clone_on_copy() {
 
     let rc = RefCell::new(0);
     rc.borrow().clone();
+
+    // Issue #4348
+    let mut x = 43;
+    let _ = &x.clone(); // ok, getting a ref
+    'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate
+    is_ascii('z'.clone());
+
+    // Issue #5436
+    let mut vec = Vec::new();
+    vec.push(42.clone());
 }
 
 fn clone_on_ref_ptr() {
@@ -61,25 +75,6 @@ fn clone_on_double_ref() {
     println!("{:p} {:p}", *y, z);
 }
 
-fn iter_clone_collect() {
-    let v = [1, 2, 3, 4, 5];
-    let v2: Vec<isize> = v.iter().cloned().collect();
-    let v3: HashSet<isize> = v.iter().cloned().collect();
-    let v4: VecDeque<isize> = v.iter().cloned().collect();
-
-    // Handle macro expansion in suggestion
-    let _: Vec<isize> = vec![1, 2, 3].iter().cloned().collect();
-
-    // Issue #3704
-    unsafe {
-        let _: Vec<u8> = std::ffi::CStr::from_ptr(std::ptr::null())
-            .to_bytes()
-            .iter()
-            .cloned()
-            .collect();
-    }
-}
-
 mod many_derefs {
     struct A;
     struct B;
@@ -114,4 +109,9 @@ fn go1() {
         let _: E = a.clone();
         let _: E = *****a;
     }
+
+    fn check(mut encoded: &[u8]) {
+        let _ = &mut encoded.clone();
+        let _ = &encoded.clone();
+    }
 }