-
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-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
The fix in #15017 is incomplete and only handles the particular issue that was reported. The problem is that brackets are needed in the general case to create a scope which will restrict the lifetime of created values.
Reproducer
I tried this code:
fn main() {
let a = 10;
match 11 {
a => { println!("a = {a}"); }
}
println!("a = {a}");
}
Before autofix, this code prints:
a = 11
a = 10
After autofix, the code prints:
a = 11
a = 11
because the autofix, even with #15017 applied, reads:
fn main() {
let a = 10;
let a = 11;
{ println!("a = {a}"); }
println!("a = {a}");
}
Version
Clippy master as of 9e7782b8
Additional Labels
@rustbot label +I-suggestion-causes-bug
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way