Skip to content
New issue

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

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

Closed
rprichard opened this issue Sep 11, 2015 · 5 comments
Closed
Labels
A-grammar Area: The grammar of Rust C-bug Category: This is a bug. P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@rprichard
Copy link
Contributor

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.)

@steveklabnik steveklabnik added the A-grammar Area: The grammar of Rust label Sep 28, 2015
@brson
Copy link
Contributor

brson commented Mar 23, 2017

Current output:

rustc 1.16.0 (30cf806ef 2017-03-10)
error: expected one of `!`, `(`, `::`, `;`, `<`, or `}`, found `.`
 --> <anon>:4:11
  |
4 |     s as S.f;
  |           ^

error[E0308]: mismatched types
 --> <anon>:4:5
  |
4 |     s as S.f;
  |     ^^^^^^ expected (), found struct `S`
  |
  = note: expected type `()`
             found type `S`

error: aborting due to previous error

@brson brson added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 23, 2017
@nikomatsakis
Copy link
Contributor

Seems clear that parser-lalr is wrong here.

@nikomatsakis
Copy link
Contributor

However, I can see why it arises. foo.bar is not a valid type, after all.

@brson brson added P-medium Medium priority I-wrong labels Mar 23, 2017
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. and removed I-wrong labels Jul 24, 2017
@steveklabnik
Copy link
Member

Triage; is parser-lalr still a thing? is this issue relevant?

@Mark-Simulacrum
Copy link
Member

I don't think we currently maintain any separate grammar - see #64896.

@Mark-Simulacrum Mark-Simulacrum closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust C-bug Category: This is a bug. P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants