]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/unnecessary_clone.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / unnecessary_clone.rs
index 7a1d031fac4d515d92ab4203297836f86cef5065..8b1629b19a76900e9e4ab001df47bfa34d99ac54 100644 (file)
@@ -1,7 +1,7 @@
 // does not test any rustfixable lints
-
 #![warn(clippy::clone_on_ref_ptr)]
-#![allow(unused, clippy::redundant_clone)]
+#![allow(unused)]
+#![allow(clippy::redundant_clone, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
 
 use std::cell::RefCell;
 use std::rc::{self, Rc};
@@ -13,31 +13,6 @@ impl SomeTrait for SomeImpl {}
 
 fn main() {}
 
-fn is_ascii(ch: char) -> bool {
-    ch.is_ascii()
-}
-
-fn clone_on_copy() {
-    42.clone();
-
-    vec![1].clone(); // ok, not a Copy type
-    Some(vec![1]).clone(); // ok, not a Copy type
-    (&42).clone();
-
-    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() {
     let rc = Rc::new(true);
     let arc = Arc::new(true);
@@ -109,4 +84,27 @@ fn go1() {
         let _: E = a.clone();
         let _: E = *****a;
     }
+
+    fn check(mut encoded: &[u8]) {
+        let _ = &mut encoded.clone();
+        let _ = &encoded.clone();
+    }
+}
+
+mod issue2076 {
+    use std::rc::Rc;
+
+    macro_rules! try_opt {
+        ($expr: expr) => {
+            match $expr {
+                Some(value) => value,
+                None => return None,
+            }
+        };
+    }
+
+    fn func() -> Option<Rc<u8>> {
+        let rc = Rc::new(42);
+        Some(try_opt!(Some(rc)).clone())
+    }
 }