Closed
Description
In this example:
pub fn foo(a: bool, b: bool) -> u8 {
(if a { 1 } else { 0 } + if b { 1 } else { 0 })
}
rustc throws a warning:
warning: unnecessary parentheses around block return value
--> src/lib.rs:2:5
|
2 | (if a { 1 } else { 0 } + if b { 1 } else { 0 })
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
|
= note: `#[warn(unused_parens)]` on by default
Removing the parentheses as the message directs causes errors:
error: expected expression, found `+`
--> src/lib.rs:2:27
|
2 | if a { 1 } else { 0 } + if b { 1 } else { 0 }
| ^ expected expression
error[E0308]: mismatched types
--> src/lib.rs:2:12
|
2 | if a { 1 } else { 0 } + if b { 1 } else { 0 }
| -------^-------------- help: consider using a semicolon here
| | |
| | expected `()`, found integer
| expected this to be `()`
error[E0308]: mismatched types
--> src/lib.rs:2:23
|
2 | if a { 1 } else { 0 } + if b { 1 } else { 0 }
| ------------------^--- help: consider using a semicolon here
| | |
| | expected `()`, found integer
| expected this to be `()`
error: aborting due to 3 previous errors
It seems the warning is wrong, unless this is expected to compile
Meta
rustc --version --verbose
:
rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-unknown-linux-gnu
release: 1.42.0
LLVM version: 9.0
This also happens on nightly.
rustc 1.44.0-nightly (ce93331e2 2020-04-17)
binary: rustc
commit-hash: ce93331e2cf21ac4b72a53854b105955919114e7
commit-date: 2020-04-17
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0
This issue has been assigned to @mibac138 via this comment.