]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/redundant_clone.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / redundant_clone.rs
index 5fd7ffae71b3885b6c975255b1acfe39b95de2cb..09d4d392725ef6a0697158a17e50a02e545fe041 100644 (file)
@@ -9,8 +9,8 @@
 
 #![warn(clippy::redundant_clone)]
 
-use std::path::Path;
 use std::ffi::OsString;
+use std::path::Path;
 
 fn main() {
     let _ = ["lorem", "ipsum"].join(" ").to_string();
@@ -31,14 +31,37 @@ fn main() {
     let _ = OsString::new().to_owned();
 
     let _ = OsString::new().to_os_string();
+
+    // Check that lint level works
+    #[allow(clippy::redundant_clone)]
+    let _ = String::new().to_string();
+
+    let tup = (String::from("foo"),);
+    let _ = tup.0.clone();
+
+    let tup_ref = &(String::from("foo"),);
+    let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed
 }
 
 #[derive(Clone)]
 struct Alpha;
-fn double(a: Alpha) -> (Alpha, Alpha) {
-    if true {
+fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
+    if b {
         (a.clone(), a.clone())
     } else {
         (Alpha, a)
     }
 }
+
+struct TypeWithDrop {
+    x: String,
+}
+
+impl Drop for TypeWithDrop {
+    fn drop(&mut self) {}
+}
+
+fn cannot_move_from_type_with_drop() -> String {
+    let s = TypeWithDrop { x: String::new() };
+    s.x.clone() // removing this `clone()` summons E0509
+}