-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.L-unused_bracesLint: unused_bracesLint: unused_bracesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This code:
fn main() {
let e = std::iter::empty::<()>();
_ = { e };
// for _ in e {} // uncomment to verify that e was dropped
}
Gives this warning:
warning: unnecessary braces around assigned value
--> src/main.rs:3:9
|
3 | _ = { e };
| ^^ ^^
|
= note: `#[warn(unused_braces)]` on by default
help: remove these braces
|
3 - _ = { e };
3 + _ = e;
|
However, the braces are not unnecessary. _ = { e };
does the same thing as drop(e);
, but _ = e;
doesn't do anything (not even move e
).
You also can't just write { e };
, that would trigger a unused_must_use
warning.
I think the lint shouldn't trigger here.
There are also more complicated examples like this:
use std::fmt::Error;
fn main() {
let e = (std::iter::empty::<()>(), Error);
(_, Error) = { e };
// for _ in e.0 {} // uncomment to verify that e was dropped
}
Where it isn't even possible to tell if the braces are unnecessary just based on the AST. But surely no-one writes code like that :)
Version
rustc 1.75.0-nightly (2023-10-07)
@rustbot label: T-compiler A-lint
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.L-unused_bracesLint: unused_bracesLint: unused_bracesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.