Skip to content

== after unsafe block is not correctly recognized #67347

Open
@upsuper

Description

@upsuper

Given the following code:

let mut a = std::mem::MaybeUninit::new(10);
unsafe { std::ptr::read(a.as_ptr()) } == 10;

Rust reports error:

error: expected expression, found `==`
 --> src/main.rs:3:43
  |
3 |     unsafe { std::ptr::read(a.as_ptr()) } == 10;
  |                                           ^^ expected expression

However, if I change == to +, Rust would instead mentions that a pair of parens should be added to wrap the block:

error: expected expression, found `+`
 --> src/main.rs:3:43
  |
3 |     unsafe { std::ptr::read(a.as_ptr()) } + 10;
  |     ------------------------------------- ^ expected expression
  |     |
  |     help: parentheses are required to parse this as an expression: `(unsafe { std::ptr::read(a.as_ptr()) })`

I guess the error message should probably be updated for the == case as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions