]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/eta.fixed
Auto merge of #7460 - camsteffen:run-from-source, r=Manishearth
[rust.git] / tests / ui / eta.fixed
index 5d62a6d9b01efe8926a4de38f7b683ab7cf27f28..91b837f9a85884d19cc74471d262c1016987cf79 100644 (file)
@@ -6,8 +6,7 @@
     clippy::redundant_closure_call,
     clippy::many_single_char_names,
     clippy::needless_pass_by_value,
-    clippy::option_map_unit_fn,
-    clippy::trivially_copy_pass_by_ref
+    clippy::option_map_unit_fn
 )]
 #![warn(
     clippy::redundant_closure,
 
 use std::path::PathBuf;
 
+macro_rules! mac {
+    () => {
+        foobar()
+    };
+}
+
+macro_rules! closure_mac {
+    () => {
+        |n| foo(n)
+    };
+}
+
 fn main() {
     let a = Some(1u8).map(foo);
     meta(foo);
     let c = Some(1u8).map(|a| {1+2; foo}(a));
+    true.then(|| mac!()); // don't lint function in macro expansion
+    Some(1).map(closure_mac!()); // don't lint closure in macro expansion
+    let _: Option<Vec<u8>> = true.then(std::vec::Vec::new); // special case vec!
     let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
     all(&[1, 2, 3], &2, |x, y| below(x, y)); //is adjusted
     unsafe {
@@ -34,6 +48,9 @@ fn main() {
     // See #515
     let a: Option<Box<dyn (::std::ops::Deref<Target = [i32]>)>> =
         Some(vec![1i32, 2]).map(|v| -> Box<dyn (::std::ops::Deref<Target = [i32]>)> { Box::new(v) });
+
+    // issue #7224
+    let _: Option<Vec<u32>> = Some(0).map(|_| vec![]);
 }
 
 trait TestTrait {
@@ -203,3 +220,19 @@ impl std::ops::Deref for Bar {
 fn test_deref_with_trait_method() {
     let _ = [Bar].iter().map(|s| s.to_string()).collect::<Vec<_>>();
 }
+
+fn mutable_closure_used_again(x: Vec<i32>, y: Vec<i32>, z: Vec<i32>) {
+    let mut res = Vec::new();
+    let mut add_to_res = |n| res.push(n);
+    x.into_iter().for_each(&mut add_to_res);
+    y.into_iter().for_each(&mut add_to_res);
+    z.into_iter().for_each(add_to_res);
+}
+
+fn mutable_closure_in_loop() {
+    let mut value = 0;
+    let mut closure = |n| value += n;
+    for _ in 0..5 {
+        Some(1).map(&mut closure);
+    }
+}