-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
The suggestions generated by the option_if_let_else
lint for a Result
with an impure expression in the else
branch does not compile.
Reproducer
I tried this code:
#![deny(clippy::option_if_let_else)]
fn main() {
let variable: Result<u32, &str> = Ok(42);
if let Ok(binding) = variable {
println!("Ok {binding}");
} else {
println!("Err");
}
}
I expected Clippy to suggest the following fix:
variable.map_or_else(|_| {
println!("Err");
}, |binding| {
println!("Ok {binding}");
})
Instead, Clippy outputs this (notice the missing _
in the arguments to the first closure):
[...]
help: try
|
4 ~ variable.map_or_else(|| {
5 + println!("Err");
6 + }, |binding| {
7 + println!("Ok {binding}");
8 + })
|
Version
rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied