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
593: Support RangeFrom ([x..]) and RangeFromTo ([x..y]) in the parser r=philberty a=dkm
Parsing the .. (DOT_DOT) operator to get a range had two
issues. Trying to compile:
let block = [1,2,3,4,5];
let _rf = &block[1..];
let _rt = &block[..3];
let _rft = &block[2..4];
range.rs:4:23: error: found unexpected token ‘]’ in null denotation
4 | let _rf = &block[1..];
| ^
range.rs:4:24: error: expecting ‘]’ but ‘;’ found
4 | let _rf = &block[1..];
| ^
Since .. can represent either a range from or a range from-to it can
be followed by an expression or not. We do have a hack in our
pratt-parser so that it is allowed to return a nullptr. But even in
that case it will have swallowed the next token. Add another hack to
the pratt-parser so that if the next token is one that cannot start an
expression and the caller allows a nullptr return then don't skip the
token and return immediately.
After this patch we can parse the above range expressions, but we
still don't handle them fully:
range.rs:4:20: fatal error: Failed to lower expr: [1..]
4 | let _rf = &block[1..];
| ^
Ranges are actually syntactic sugar for std::ops::Range[From|To].
Co-authored-by: Mark Wielaard <[email protected]>
0 commit comments