-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add error for ...
in expressions
#45773
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I'm sad every time I have to @bors r+ this |
📌 Commit 0419a3b has been approved by |
@@ -106,7 +106,8 @@ impl AssocOp { | |||
Token::OrOr => Some(LOr), | |||
Token::DotDot => Some(DotDot), | |||
Token::DotDotEq => Some(DotDotEq), | |||
Token::DotDotDot => Some(DotDotEq), // remove this after SNAP | |||
// DotDotDot is no longer supported, but we need some way to display the error | |||
Token::DotDotDot => Some(DotDotEq), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main concern is that in order to show the error we need to parse the expression, so here I'm parsing Token::DotDotDot
as AssocOp::DotDotEq
, and in src/libsyntax/parse/parser.rs I check for Token::DotDotDot
and AssocOp::DotDotEq
to show the error. An alternative would be returning None
here but then the expression would be incomplete (adding the generic "expected one of" error).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm parsing
Token::DotDotDot
asAssocOp::DotDotEq
That's exactly what is needed for good error recovery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
⌛ Testing commit 0419a3b697be90d36efed6d91bee5c371e29f0a6 with merge c48637001106cd9eb78d037fb77aa7602d28f83c... |
💔 Test failed - status-travis |
Several run-pass/range_inclusive.rs
run-pass/range_inclusive_gate.rs
|
I'm confused. The error says that line 20 of range_inclusive.rs is rust/src/test/run-pass/range_inclusive.rs Line 20 in 54bbd56
|
@Badel2 Could you also add a test checking that if |
I have added a parse-fail test, but I can't find the pretty-printing code. The closest I got is the code for ranges in patterns, but I can't find the one for expressions. rust/src/librustc/hir/print.rs Line 1821 in 19402f1
|
@Badel2 rust/src/libsyntax/print/pprust.rs Line 2207 in 19402f1
|
@petrochenkov Thanks! I hope it's fixed now. |
@bors r+ |
📌 Commit c0addf6 has been approved by |
That's strange, in my machine I run |
I see why only the first error is detected, the test is missing
, but it should fail locally as well. ( |
@petrochenkov Same result, it fails on travis but it works on my machine. I haven't run |
src/libsyntax/parse/parser.rs
Outdated
self.err_dotdotdot_syntax(self.span); | ||
} | ||
|
||
debug_assert!([token::DotDot, token::DotDotEq].contains(&self.token), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this debug_assert
may be firing on CI.
IIRC, these kinds of asserts are enabled on PR merge, but disabled by default for local builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, for some reason I thought the code would stop executing after the err.emit(). Now it all makes sense. Thank you very much!
@bors r+ |
📌 Commit b81a7b3 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
Follow-up to #44709
Tracking issue: #28237
...
in expressions was a warning, now it's an error..
or..=
instead, and explains the difference...
to..=
r? petrochenkov