]> git.proxmox.com Git - rustc.git/blobdiff - src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / unnecessary_lazy_eval.fixed
index eed817968832193aa2d7588043480134c3e04d13..ce4a82e021745d45e532710d2c93cd82be091988 100644 (file)
@@ -1,9 +1,13 @@
 // run-rustfix
+// aux-build: proc_macro_with_span.rs
 #![warn(clippy::unnecessary_lazy_evaluations)]
 #![allow(clippy::redundant_closure)]
 #![allow(clippy::bind_instead_of_map)]
 #![allow(clippy::map_identity)]
 
+extern crate proc_macro_with_span;
+use proc_macro_with_span::with_span;
+
 struct Deep(Option<usize>);
 
 #[derive(Copy, Clone)]
@@ -21,6 +25,14 @@ fn some_call<T: Default>() -> T {
     T::default()
 }
 
+struct Issue9427(i32);
+
+impl Drop for Issue9427 {
+    fn drop(&mut self) {
+        println!("{}", self.0);
+    }
+}
+
 fn main() {
     let astronomers_pi = 10;
     let ext_arr: [usize; 1] = [2];
@@ -73,6 +85,9 @@ fn main() {
     let _ = deep.0.or_else(|| some_call());
     let _ = opt.ok_or_else(|| ext_arr[0]);
 
+    // Should not lint - bool
+    let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
+
     // should not lint, bind_instead_of_map takes priority
     let _ = Some(10).and_then(|idx| Some(ext_arr[idx]));
     let _ = Some(10).and_then(|idx| Some(idx));
@@ -130,3 +145,9 @@ fn main() {
     let _: Result<usize, usize> = res.and_then(|x| Err(x));
     let _: Result<usize, usize> = res.or_else(|err| Ok(err));
 }
+
+#[allow(unused)]
+fn issue9485() {
+    // should not lint, is in proc macro
+    with_span!(span Some(42).unwrap_or_else(|| 2););
+}