We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I tried this code:
fn foo() -> i32 { 1 } fn bar() -> bool { { foo() } == 1 }
I expected to see this happen: The code should compile, as the block expression should return value returned by the function.
Instead, this happened: The compilation fails. However, when assigning the value first or using the return keyword, the code successfully compiles.
return
fn bar() -> bool { // both of the compile let val = { foo() } == 1; val return { foo() } == 1; }
rustc --version --verbose:
rustc --version --verbose
rustc 1.82.0 (f6e511eec 2024-10-15) binary: rustc commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14 commit-date: 2024-10-15 host: x86_64-unknown-linux-gnu release: 1.82.0 LLVM version: 19.1.1
error: expected expression, found `==` --> src/lib.rs:6:15 | 6 | { foo() } == 1 | ^^ expected expression warning: unnecessary braces around block return value --> src/lib.rs:6:5 | 6 | { foo() } == 1 | ^^ ^^ | = note: `#[warn(unused_braces)]` on by default help: remove these braces | 6 - { foo() } == 1 6 + foo() == 1 | error[E0308]: mismatched types --> src/lib.rs:6:7 | 6 | { foo() } == 1 | ^^^^^- help: consider using a semicolon here: `;` | | | expected `()`, found `i32` For more information about this error, try `rustc --explain E0308`.
The text was updated successfully, but these errors were encountered:
Notably, 1 == { 1 } compiles as expected, but { 1 } == 1 fails.
1 == { 1 }
{ 1 } == 1
Sorry, something went wrong.
This is known and documented: https://doc.rust-lang.org/stable/reference/statements.html#expression-statements.
@rustbot label -C-bug +C-discussion
This specific case is also known way back in like #28379 and friends.
This is very much intentional. Thank you for the report.
No branches or pull requests
I tried this code:
I expected to see this happen: The code should compile, as the block expression should return value returned by the function.
Instead, this happened: The compilation fails. However, when assigning the value first or using the
return
keyword, the code successfully compiles.Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: