diff options
| author | Alex Macleod <alex@macleod.io> | 2025-09-02 13:57:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-02 13:57:35 +0000 |
| commit | 059cf0e3bbc44d6634e291ffc1a0daedec730fd5 (patch) | |
| tree | b5c15644f7bfd625484febad2f7ab971b8d22f84 /tests | |
| parent | d97640c8a4e3b9ee1d4e80770fefbc7c77c4dd0a (diff) | |
| parent | a527e9f67f4fa9cb0748b7c0073d91a07d392ac6 (diff) | |
| download | rust-059cf0e3bbc44d6634e291ffc1a0daedec730fd5.tar.gz rust-059cf0e3bbc44d6634e291ffc1a0daedec730fd5.zip | |
Preserve `unsafe` blocks in `option_map_unit` suggestion (#15570)
changelog: [`option_map_unit`]: preserve `unsafe` blocks Fixes rust-lang/rust-clippy#15568
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/option_map_unit_fn_fixable.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/option_map_unit_fn_fixable.rs | 9 | ||||
| -rw-r--r-- | tests/ui/option_map_unit_fn_fixable.stderr | 18 |
3 files changed, 35 insertions, 1 deletions
diff --git a/tests/ui/option_map_unit_fn_fixable.fixed b/tests/ui/option_map_unit_fn_fixable.fixed index 55c1b8f110c..340be7c7e93 100644 --- a/tests/ui/option_map_unit_fn_fixable.fixed +++ b/tests/ui/option_map_unit_fn_fixable.fixed @@ -102,4 +102,13 @@ fn option_map_unit_fn() { //~^ option_map_unit_fn } +fn issue15568() { + unsafe fn f(_: u32) {} + let x = Some(3); + if let Some(x) = x { unsafe { f(x) } } + //~^ option_map_unit_fn + if let Some(x) = x { unsafe { f(x) } } + //~^ option_map_unit_fn +} + fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.rs b/tests/ui/option_map_unit_fn_fixable.rs index 5ed47e4c60b..d902c87379b 100644 --- a/tests/ui/option_map_unit_fn_fixable.rs +++ b/tests/ui/option_map_unit_fn_fixable.rs @@ -102,4 +102,13 @@ fn option_map_unit_fn() { //~^ option_map_unit_fn } +fn issue15568() { + unsafe fn f(_: u32) {} + let x = Some(3); + x.map(|x| unsafe { f(x) }); + //~^ option_map_unit_fn + x.map(|x| unsafe { { f(x) } }); + //~^ option_map_unit_fn +} + fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 3f7abae34ee..2405aa9a7cc 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -153,5 +153,21 @@ LL | option().map(|value| println!("{:?}", value)); | | | help: try: `if let Some(value) = option() { println!("{:?}", value) }` -error: aborting due to 19 previous errors +error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` + --> tests/ui/option_map_unit_fn_fixable.rs:108:5 + | +LL | x.map(|x| unsafe { f(x) }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: try: `if let Some(x) = x { unsafe { f(x) } }` + +error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` + --> tests/ui/option_map_unit_fn_fixable.rs:110:5 + | +LL | x.map(|x| unsafe { { f(x) } }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: try: `if let Some(x) = x { unsafe { f(x) } }` + +error: aborting due to 21 previous errors |
