Repository navigation
Conversation
|
r? @TaKO8Ki rustbot has assigned @TaKO8Ki. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
||
| Assign(_, ref value, _) | AssignOp(.., ref value) => { | ||
| Assign(ref lhs, ref value, _) => { | ||
| let ctx = if expr_contains_underscore(lhs) { |
There was a problem hiding this comment.
I think this lint should not be triggered in some other cases like (..) = { e } [..] = { e }. Can we address them here as well?
#![deny(unused_braces)]
struct D(&'static str);
impl Drop for D {
fn drop(&mut self) {
println!("drop {}", self.0);
}
}
fn main() {
let e = (D("a"), D("b"));
(..) = { e };
}
This comment has been minimized.
This comment has been minimized.
a8f5835 to
b14a543
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
| && (ctx != UnusedDelimsCtx::AnonConst | ||
| || (matches!(expr.kind, ast::ExprKind::Lit(_)) | ||
| && !expr.span.from_expansion())) | ||
| && ctx != UnusedDelimsCtx::AssignedValueWithWildcard |
There was a problem hiding this comment.
That's too coarse. Consider:
fn main() {
let e = String::new();
_ = { (e,) };
}The braces are indeed unnecessary because the tuple construction (_,) already moves/drops e regardless of whether there are any { }. But now under your PR we no longer lint here.
The tuple construction is just an example.
Should at least be a FIXME. Not sure if it's worth blocking this PR on fixing this new class of false negatives...
Fixes #116536.
The
unused_braceslint could suggest removing braces from wildcard assignments like:producing:
_ = e;These are not equivalent:
_ = { e };moves/dropse, while_ = e;does not. This PR suppressesunused_bracesfor assignment RHS blocks when the assignment LHS contains_.ui regression test covers both the simple wildcard assignment case and a tuple destructuring assignment case