- Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
When running clippy on this code
fn foo() -> Option<usize> { todo!() } fn main() { loop { let x = match foo() { Some(n) => n, None => break, }; println!("{}", x); } }
it (rightly) suggests that while let
could be used instead. However, the suggested fix is try: 'while let Some(n) = foo() { .. }'
(playground link), taking the n
from the pattern inside the match
instead of the x
from let x
. Carrying out this replacement introduces compilation errors, as x
is now undefined.
Expected behaviour:
Suggest trying while let Some(x)
, taking the variable name that binds the result of the match
expression.
Meta
cargo clippy -V
:clippy 0.1.52 (9bc8c42b 2021-05-09)
rustc -Vv
:rustc 1.52.1 (9bc8c42bb 2021-05-09) binary: rustc commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53 commit-date: 2021-05-09 host: x86_64-pc-windows-msvc release: 1.52.1 LLVM version: 12.0.0
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing