You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Indeed, with +: let b = 0 as u32 + 0 as u32 parses correctly,
However, with <: let b = 0 as u32 < 0 as u32 gives a syntax error.
I suspect this is due to a conflict in the grammar that looks ahead at the token < and sees the beginning of a type application (in types), but if I'm reading just https://doc.rust-lang.org/reference/expressions.html#r-expr.precedence there's not enough information for me to write a correct Rust syntax printer.
The text was updated successfully, but these errors were encountered:
Generally, though it is not fully documented, the productions are greedy in a sense that they will attempt to parse the longest possible set of tokens for a rule (even if that would lead to an error). So, this isn't exactly an operator precedence issue. It is TypePath is greedily taking tokens like <0 and giving up at some point (probably the as) with an error.
ehuss
changed the title
Incorrect documentation regarding operator precedence (because of a conflict in the grammar)
Clarify longest match behavior of the grammar
May 8, 2025
And maybe explain that the grammar won't backtrack (past N tokens, I presume) -- with backtracking one could possibly parse this expression, but it would be expensive.
https://doc.rust-lang.org/reference/expressions.html claims
as
binds tighter than than+
or<
Indeed, with
+
:let b = 0 as u32 + 0 as u32
parses correctly,However, with
<
:let b = 0 as u32 < 0 as u32
gives a syntax error.I suspect this is due to a conflict in the grammar that looks ahead at the token
<
and sees the beginning of a type application (in types), but if I'm reading just https://doc.rust-lang.org/reference/expressions.html#r-expr.precedence there's not enough information for me to write a correct Rust syntax printer.The text was updated successfully, but these errors were encountered: