Skip to content

Field access of cast expression: discrepancy between parser-lalr and rustc #28362

Closed as not planned
@rprichard

Description

@rprichard

It's not clear to me whether this code is valid syntax. It looks wrong, so maybe it ought to be rejected. rustc rejects it, but parser-lalr accepts it:

struct S { f: i32 }
fn main() {
    let s = S { f: 42 };
    s as S.f;
}

It looks like it should parse as s as (S.f), and that wouldn't parse. parser-lalr parses it as (s as S).f

test.rs:4:11: 4:12 error: expected one of `!`, `(`, `::`, `;`, `<`, `}`, or an operator, found `.`
test.rs:4     s as S.f;
                    ^

(To test the LALR grammar, build the check-grammar target, then run grammar/parser-lalr -v.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustC-bugCategory: This is a bug.P-mediumMedium priorityT-langRelevant to the language 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