]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/redundant_clone.fixed
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / redundant_clone.fixed
index f5da703cd1dea5e9d524f8c2950ec629525faec2..00b427450935d5077a7ff947a78da65c5221ef2b 100644 (file)
@@ -1,7 +1,8 @@
 // run-rustfix
 // rustfix-only-machine-applicable
+#![feature(lint_reasons)]
+#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
 
-#![allow(clippy::implicit_clone)]
 use std::ffi::OsString;
 use std::path::Path;
 
@@ -29,6 +30,10 @@ fn main() {
     #[allow(clippy::redundant_clone)]
     let _s = String::new().to_string();
 
+    // Check that lint level works
+    #[expect(clippy::redundant_clone)]
+    let _s = String::new().to_string();
+
     let tup = (String::from("foo"),);
     let _t = tup.0;
 
@@ -55,6 +60,8 @@ fn main() {
     issue_5405();
     manually_drop();
     clone_then_move_cloned();
+    hashmap_neg();
+    false_negative_5707();
 }
 
 #[derive(Clone)]
@@ -194,7 +201,7 @@ fn clone_then_move_cloned() {
     fn foo<F: Fn()>(_: &Alpha, _: F) {}
     let x = Alpha;
     // ok, data is moved while the clone is in use.
-    foo(&x.clone(), move || {
+    foo(&x, move || {
         let _ = x;
     });
 
@@ -206,3 +213,29 @@ fn clone_then_move_cloned() {
     let mut x = S(String::new());
     x.0.clone().chars().for_each(|_| x.m());
 }
+
+fn hashmap_neg() {
+    // issue 5707
+    use std::collections::HashMap;
+    use std::path::PathBuf;
+
+    let p = PathBuf::from("/");
+
+    let mut h: HashMap<&str, &str> = HashMap::new();
+    h.insert("orig-p", p.to_str().unwrap());
+
+    let mut q = p.clone();
+    q.push("foo");
+
+    println!("{:?} {}", h, q.display());
+}
+
+fn false_negative_5707() {
+    fn foo(_x: &Alpha, _y: &mut Alpha) {}
+
+    let x = Alpha;
+    let mut y = Alpha;
+    foo(&x, &mut y);
+    let _z = x.clone(); // pr 7346 can't lint on `x`
+    drop(y);
+}