-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
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 lint will emit an invalid suggestion when the binding name in the pattern differs from the name used in the let statement.
Reproducer
I tried this code:
#![warn(clippy::manual_let_else)]
fn main() {
let foo = Some(1);
let value = match foo {
Some(v) => v,
_ => return,
};
println!("We have a value of: {value}");
}
I expected to see this happen:
#![warn(clippy::manual_let_else)]
fn main() {
let foo = Some(1);
let Some(value) = foo else { return };
println!("We have a value of: {value}");
}
This is the suggestion it should emit, reusing the name value
.
Instead, this happened:
#![warn(clippy::manual_let_else)]
fn main() {
let foo = Some(1);
// It reuses the name `v`, which is not expected later on
let Some(v) = foo else { return };
println!("We have a value of: {value}");
}
This suggestion causes an error:
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `value` in this scope
--> src/main.rs:8:36
|
8 | println!("We have a value of: {value}");
| ^^^^^ not found in this scope
Version
rustc 1.67.0-nightly (70f8737b2 2022-11-23)
binary: rustc
commit-hash: 70f8737b2f5d3bf7d6b784fad00b663b7ff9feda
commit-date: 2022-11-23
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
@rustbot label +I-suggestion-causes-error
andersk and KisaragiEffective
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