]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/eta.fixed
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / eta.fixed
index 618f80cdcf84923d9ca035b35e177c9cc22079e4..a9cc80aaaf623c81f85c79be05c1c8b93b6b6ecf 100644 (file)
@@ -1,14 +1,14 @@
 // run-rustfix
-
+#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
+#![allow(unused)]
 #![allow(
-    unused,
-    clippy::no_effect,
-    clippy::redundant_closure_call,
+    clippy::needless_borrow,
     clippy::needless_pass_by_value,
+    clippy::no_effect,
     clippy::option_map_unit_fn,
-    clippy::needless_borrow
+    clippy::redundant_closure_call,
+    clippy::uninlined_format_args
 )]
-#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
 
 use std::path::{Path, PathBuf};
 
@@ -37,7 +37,7 @@ fn main() {
     }
 
     // See #815
-    let e = Some(1u8).map(divergent);
+    let e = Some(1u8).map(|a| divergent(a));
     let e = Some(1u8).map(generic);
     let e = Some(1u8).map(generic);
     // See #515
@@ -211,6 +211,10 @@ fn mutable_closure_in_loop() {
     let mut closure = |n| value += n;
     for _ in 0..5 {
         Some(1).map(&mut closure);
+
+        let mut value = 0;
+        let mut in_loop = |n| value += n;
+        Some(1).map(in_loop);
     }
 }
 
@@ -229,7 +233,7 @@ fn late_bound_lifetimes() {
     {
     }
     map_str(|s| take_asref_path(s));
-    map_str_to_path(std::convert::AsRef::as_ref);
+    map_str_to_path(|s| s.as_ref());
 }
 
 mod type_param_bound {
@@ -256,3 +260,59 @@ fn arc_fp() {
     (0..5).map(|n| arc(n));
     Some(4).map(|n| ref_arc(n));
 }
+
+// #8460 Don't replace closures with params bounded as `ref`
+mod bind_by_ref {
+    struct A;
+    struct B;
+
+    impl From<&A> for B {
+        fn from(A: &A) -> Self {
+            B
+        }
+    }
+
+    fn test() {
+        // should not lint
+        Some(A).map(|a| B::from(&a));
+        // should not lint
+        Some(A).map(|ref a| B::from(a));
+    }
+}
+
+// #7812 False positive on coerced closure
+fn coerced_closure() {
+    fn function_returning_unit<F: FnMut(i32)>(f: F) {}
+    function_returning_unit(|x| std::process::exit(x));
+
+    fn arr() -> &'static [u8; 0] {
+        &[]
+    }
+    fn slice_fn(_: impl FnOnce() -> &'static [u8]) {}
+    slice_fn(|| arr());
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/7861
+fn box_dyn() {
+    fn f(_: impl Fn(usize) -> Box<dyn std::any::Any>) {}
+    f(|x| Box::new(x));
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/5939
+fn not_general_enough() {
+    fn f(_: impl FnMut(&Path) -> std::io::Result<()>) {}
+    f(|path| std::fs::remove_file(path));
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/9369
+pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() {
+    fn takes_fn_mut(_: impl FnMut()) {}
+    takes_fn_mut(&mut f);
+
+    fn takes_fn_once(_: impl FnOnce()) {}
+    takes_fn_once(&mut f);
+
+    f();
+
+    move || takes_fn_mut(&mut f_used_once)
+}