Skip to content

Misleading error message with precedence issue involving "as" #36367

Closed
@joshtriplett

Description

@joshtriplett

Consider the following code:

if mmap_size as usize < std::mem::size_of::<run>() {
    ...
}

This code has a precedence issue: as binds looser than <, so I think this attempts to parse what comes after the as as a type, usize<std::mem::size_of ..., parsing the < as a generic. That results in the following error message:

error: expected identifier, found `<`
   --> src/main.rs:202:48
    |
202 |     if mmap_size as usize < std::mem::size_of::<run>() {
    |                                                ^

This leads the user down the wrong path. Ideally, rustc should provide an error that hints at the precedence issue instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions