| //@ edition: 2021 |
| #![warn(clippy::block_scrutinee)] |
| #![allow(clippy::blocks_in_conditions)] |
| |
| fn my_function() -> Option<i32> { |
| Some(1) |
| } |
| |
| fn main() { |
| let res = my_function(); |
| if let Some(x) = res { |
| //~^ ERROR: this scrutinee is wrapped in a block |
| let _ = x; |
| } |
| |
| let res = my_function(); |
| match res { |
| //~^ ERROR: this scrutinee is wrapped in a block |
| Some(1) => println!("one"), |
| Some(_) => println!("other"), |
| None => println!("none"), |
| } |
| |
| let mut v = vec![1, 2, 3]; |
| let res = v.pop(); |
| while let Some(x) = res { |
| //~^ ERROR: this scrutinee is wrapped in a block |
| let _ = x; |
| } |
| |
| if let Some(x) = my_function() { |
| let _ = x; |
| } |
| |
| if let Some(x) = { |
| let _y = 2; |
| my_function() |
| } { |
| let _ = x; |
| } |
| |
| //~v ERROR: this scrutinee is wrapped in a block |
| let res = v.pop(); |
| if let Some(x) = res { |
| let _ = x; |
| } |
| |
| macro_rules! get_val { |
| () => {{ my_function() }}; |
| } |
| if let Some(x) = get_val!() { |
| let _ = x; |
| } |
| |
| // Test that `unsafe` blocks are ignored |
| unsafe fn my_unsafe_fn() -> Option<i32> { |
| Some(1) |
| } |
| |
| if let Some(x) = unsafe { my_unsafe_fn() } { |
| let _ = x; |
| } |
| } |