-
Notifications
You must be signed in to change notification settings - Fork 13k
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
range syntax doesn't work with non-literal endpoints in for statements #20241
Comments
It should work with explicit disambiguation via parens This seems like it may be something that crops up often so it's probably worth at least improving the diagnostics. |
@huonw I don't understand why the parens are necessary, surely that's not our plan for 1.0. Why can't the parser unambiguously detect that |
Especially since we've already gone out of our way to prevent other ambiguities. |
@bstrie it is detecting that |
Fixes rust-lang#20811 and rust-lang#20241. Note: this changes the semantics of parse_more_binops() to parse binops with precedence >= min_prec. Previously, it would parse binops with precedence > min_prec.
Grammar changes: * allow 'for _ in 1..i {}' (fixes rust-lang#20241) * allow 'for _ in 1.. {}' as infinite loop * prevent use of range notation in contexts where only operators of high precedence are expected (fixes rust-lang#20811) Parser code cleanup: * remove RESTRICTION_NO_DOTS * make AS_PREC const and follow naming convention * make min_prec inclusive
This PR is intended as alternative to #20958. It fixes the same grammar inconsistencies, but does not increase the operator precedence of `..`, leaving it at the same level as the assignment operator. For previous discussion, see #20811 and #20958. Grammar changes: * allow `for _ in 1..i {}` (fixes #20241) * allow `for _ in 1.. {}` as infinite loop * prevent use of range notation in contexts where only operators of high precedence are expected (fixes #20811) Parser code cleanup: * remove `RESTRICTION_NO_DOTS` * make `AS_PREC` const and follow naming convention * make `min_prec` inclusive r? nikomatsakis
Grammar changes: * allow 'for _ in 1..i {}' (fixes rust-lang#20241) * allow 'for _ in 1.. {}' as infinite loop * prevent use of range notation in contexts where only operators of high precedence are expected (fixes rust-lang#20811) Parser code cleanup: * remove RESTRICTION_NO_DOTS * make AS_PREC const and follow naming convention * make min_prec inclusive
Range syntax doesn't work with non-literal endpoints. It seems that the parser tries to parse a structure definition or instantiation.
I don't know if this is known and just not completely implemented yet, but I figured I'd give the heads up.
playpen
The text was updated successfully, but these errors were encountered: