]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/clone_on_copy.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / clone_on_copy.rs
index ca39a654b4fce21c6fe1e57a81377152ae8beba0..03e210ebad98c302819ab8b8ed9c5426fa9a6a34 100644 (file)
@@ -5,7 +5,10 @@
     clippy::redundant_clone,
     clippy::deref_addrof,
     clippy::no_effect,
-    clippy::unnecessary_operation
+    clippy::unnecessary_operation,
+    clippy::vec_init_then_push,
+    clippy::toplevel_ref_arg,
+    clippy::needless_borrow
 )]
 
 use std::cell::RefCell;
@@ -18,7 +21,7 @@ fn is_ascii(ch: char) -> bool {
     ch.is_ascii()
 }
 
-fn clone_on_copy() {
+fn clone_on_copy() -> Option<(i32)> {
     42.clone();
 
     vec![1].clone(); // ok, not a Copy type
@@ -28,6 +31,37 @@ fn clone_on_copy() {
     let rc = RefCell::new(0);
     rc.borrow().clone();
 
+    let x = 0u32;
+    x.clone().rotate_left(1);
+
+    #[derive(Clone, Copy)]
+    struct Foo;
+    impl Foo {
+        fn clone(&self) -> u32 {
+            0
+        }
+    }
+    Foo.clone(); // ok, this is not the clone trait
+
+    macro_rules! m {
+        ($e:expr) => {{ $e }};
+    }
+    m!(42).clone();
+
+    struct Wrap([u32; 2]);
+    impl core::ops::Deref for Wrap {
+        type Target = [u32; 2];
+        fn deref(&self) -> &[u32; 2] {
+            &self.0
+        }
+    }
+    let x = Wrap([0, 0]);
+    x.clone()[0];
+
+    let x = 42;
+    let ref y = x.clone(); // ok, binds by reference
+    let ref mut y = x.clone(); // ok, binds by reference
+
     // Issue #4348
     let mut x = 43;
     let _ = &x.clone(); // ok, getting a ref
@@ -37,4 +71,9 @@ fn clone_on_copy() {
     // Issue #5436
     let mut vec = Vec::new();
     vec.push(42.clone());
+
+    //  Issue #9277
+    let opt: &Option<i32> = &None;
+    let value = opt.clone()?; // operator precedence needed (*opt)?
+    None
 }