Skip to content

Missing "parentheses are required to parse this as an expression" hint with multiple unsafe blocks #102171

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

Closed
jruderman opened this issue Sep 23, 2022 · 0 comments · Fixed by #105223
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

Given the following code:

unsafe fn id(x: u32) -> u32 {
    x
}

fn main() {
    let y = unsafe {
        unsafe { id(3) } + unsafe { id(4) }
    };
    println!("{}", y);
}

The current output is:

error: expected expression, found `+`
 --> src/main.rs:7:26
  |
7 |         unsafe { id(3) } + unsafe { id(4) }
  |                          ^ expected expression

error[E0308]: mismatched types
 --> src/main.rs:7:18
  |
7 |         unsafe { id(3) } + unsafe { id(4) }
  |                  ^^^^^- help: consider using a semicolon here: `;`
  |                  |
  |                  expected `()`, found `u32`

For more information about this error, try `rustc --explain E0308`.

Ideally the output should look like:

error: expected expression, found `+`
 --> src/main.rs:7:26
  |
7 |         unsafe { id(3) } + unsafe { id(4) }
  |                          ^ expected expression
  |
help: parentheses are required to parse this as an expression
  |
7 |         (unsafe { id(3) }) + unsafe { id(4) }
  |         +                +

Related to #67347

@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 23, 2022
@inquisitivecrystal inquisitivecrystal added C-enhancement Category: An issue proposing an enhancement or a PR with one. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Sep 23, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 5, 2022
…ochenkov

suggest parenthesis around ExprWithBlock BinOp ExprWithBlock

fix rust-lang#105179
fix rust-lang#102171
@bors bors closed this as completed in 66a4cb5 Dec 6, 2022
RalfJung pushed a commit to RalfJung/miri that referenced this issue Dec 9, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants