-
Notifications
You must be signed in to change notification settings - Fork 13.3k
unused_parens false positive on addition of blocks? #71290
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think this may apply to any binary op where the left-hand side is an expression that can be a statement without a semicolon, per: rust/src/librustc_ast/util/classify.rs Lines 14 to 25 in 45d050c
For example, adding with block expressions also reports unused parens: pub fn foo(a: bool, b: bool) -> u8 {
({ u8::from(a) } + { u8::from(b) })
}
but removing those gets an error:
As a workaround, it doesn't trigger pub fn foo(a: bool, b: bool) -> u8 {
(if a { 1 } else { 0 }) + (if b { 1 } else { 0 })
} or pub fn foo(a: bool, b: bool) -> u8 {
({ u8::from(a) }) + ({ u8::from(b) })
} |
@rustbot claim |
Fix unused_parens false positive when using binary operations Fixes rust-lang#71290 r? @cuviper who provided instructions
Fix unused_parens false positive when using binary operations Fixes rust-lang#71290 r? @cuviper who provided instructions
Fix unused_parens false positive when using binary operations Fixes rust-lang#71290 r? @cuviper who provided instructions
Fix unused_parens false positive when using binary operations Fixes rust-lang#71290 r? @cuviper who provided instructions
In this example:
rustc throws a warning:
Removing the parentheses as the message directs causes errors:
It seems the warning is wrong, unless this is expected to compile
Meta
rustc --version --verbose
:This also happens on nightly.
This issue has been assigned to @mibac138 via this comment.
The text was updated successfully, but these errors were encountered: