Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upField access of block: discrepancy between parser-lalr and rustc #28379
Comments
steveklabnik
added
the
A-docs
label
Sep 28, 2015
This comment has been minimized.
This comment has been minimized.
|
/cc @rust-lang/lang , is this grammar correct or just incidental? (tagging with lang until I know what they want, and I'll document that.) |
steveklabnik
added
A-lang
and removed
A-docs
labels
Sep 30, 2015
This comment has been minimized.
This comment has been minimized.
|
Hmm, interesting question! I think the reference grammar is correct here, and rustc is not working properly. The rule is that "statement-like" expressions cannot take part in binary expressions; I think that should include the For example, this fails to compile: fn foo(x: u32) { }
fn main() {
let f = foo;
{ f } (22)
}but the error it gives me is surprising:
|
This comment has been minimized.
This comment has been minimized.
|
If fn main() {
1 == {1};
1 == ({1} + {1});
}As the LALR grammar describes it, a semicolon-terminated expression statement is a Both parsers reject this: fn main() {
{1} == 1;
}I discovered an interesting case, though: fn main() {
let x = { 1 + {2} * {3} };
println!("{}", x);
}This code parses and compiles, but the two parsers disagree on what it should output.
If I remove the unnecessary block around the expression, fn main() {
let x = 1 + {2} * {3}; // removed the unnecessary block here
println!("{}", x);
} |
This comment has been minimized.
This comment has been minimized.
|
I split off the operator precedence issue to #28777. |
This comment has been minimized.
This comment has been minimized.
|
Let me be more precise. It cannot START a binary operator, when in On Wed, Sep 30, 2015 at 4:45 PM, Ryan Prichard notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
|
In any case, this all feels like good motivation for me to try and get some On Wed, Sep 30, 2015 at 5:05 PM, Nicholas Matsakis nmatsakis@mozilla.com
|
nikomatsakis
added
the
I-nominated
label
Oct 1, 2015
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion. Related to #28785 |
This comment has been minimized.
This comment has been minimized.
|
I just realized why that example I gave of |
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium This is a backwards incompat issue, but feels like an edge case. Nonetheless we should definitely fix it! |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Oct 1, 2015
rprichard
referenced this issue
Nov 5, 2015
Open
Range expressions: discrepancies between rustc and parser-lalr #28785
This comment has been minimized.
This comment has been minimized.
|
I discovered another quirk involving the LALR grammar -- it accepts this: fn main() {
struct S { f: i32 };
let z = S { f: 0 };
match 0 { _ => &z }.f // <-- note the lack of semicolon
match 0 { _ => &z }.f // <-- note the lack of semicolon
()
}A rustc also accepts the code, but only if the semicolons are added after the two This quirk only applies to non-basic block expressions. |
This comment has been minimized.
This comment has been minimized.
This statement is not completely true, which reveals another LALR bug. It should accept this: fn main() {
{ ([0],) }.0[0];
{ ((|| {}),) }.0();
}
Edit: I'm slightly off still. |
rprichard commentedSep 12, 2015
The grammar in src/grammar/parser-lalr.y should probably be relaxed to accept the first example.
AFAIK, Rust could allow the other two cases (and others), because there are no statements or expressions that begin with
asor==.