-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Expect pipe symbol after closure parameter list #44332
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (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. |
Does your patch fix the ICE even if there is a curly bracket mismatch: struct MyStruct;
impl MyStruct {
fn f() {|x, y} |
It doesn't ICE. It seems that the ICE was caused by the untracked consuming of
|
@@ -4699,7 +4699,7 @@ impl<'a> Parser<'a> { | |||
SeqSep::trailing_allowed(token::Comma), | |||
|p| p.parse_fn_block_arg() | |||
); | |||
self.bump(); | |||
self.expect(&token::BinOp(token::Or))?; |
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.
Hmm, token::OrOr
should be possible here as well in theory, e.g.
#![allow(unused)]
fn main() {
let x = |x, y| |a, b| 0; // Legal
x(1, 2)(3, 4);
}
, but |x, y||a, b| 0
(without space) doesn't parse on stable/beta/nightly already.
Worth fixing as well!
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 trying to fix this. Should I work on this double-closure parsing bug in a new PR?
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.
Yes, this can be done separately to avoid blocking this PR.
@tirr-c |
@bors r+ |
📌 Commit 258ec30 has been approved by |
@bors rollup |
Expect pipe symbol after closure parameter list Fixes rust-lang#44021. --- Originally, the parser just called `bump` to discard following token after parsing closure parameter list, because it assumes `|` is following. However, the following code breaks the assumption: ```rust struct MyStruct; impl MyStruct { fn f() {|x, y} } ``` Here, the parameter list is `x, y` and the following token is `}`. The parser discards `}`, and then we have a curly bracket mismatch. Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE. ``` error: expected expression, found `}` --> 44021.rs:4:1 | 4 | } | ^ error: internal compiler error: unexpected panic ``` Even worse, on current stable(1.20.0), the compiler falls into an infinite loop. This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE. ``` error: expected one of `:`, `@`, or `|`, found `}` --> 44021.rs:3:20 | 3 | fn foo() {|x, y} | ^ expected one of `:`, `@`, or `|` here ```
Expect pipe symbol after closure parameter list Fixes rust-lang#44021. --- Originally, the parser just called `bump` to discard following token after parsing closure parameter list, because it assumes `|` is following. However, the following code breaks the assumption: ```rust struct MyStruct; impl MyStruct { fn f() {|x, y} } ``` Here, the parameter list is `x, y` and the following token is `}`. The parser discards `}`, and then we have a curly bracket mismatch. Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE. ``` error: expected expression, found `}` --> 44021.rs:4:1 | 4 | } | ^ error: internal compiler error: unexpected panic ``` Even worse, on current stable(1.20.0), the compiler falls into an infinite loop. This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE. ``` error: expected one of `:`, `@`, or `|`, found `}` --> 44021.rs:3:20 | 3 | fn foo() {|x, y} | ^ expected one of `:`, `@`, or `|` here ```
Expect pipe symbol after closure parameter list Fixes rust-lang#44021. --- Originally, the parser just called `bump` to discard following token after parsing closure parameter list, because it assumes `|` is following. However, the following code breaks the assumption: ```rust struct MyStruct; impl MyStruct { fn f() {|x, y} } ``` Here, the parameter list is `x, y` and the following token is `}`. The parser discards `}`, and then we have a curly bracket mismatch. Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE. ``` error: expected expression, found `}` --> 44021.rs:4:1 | 4 | } | ^ error: internal compiler error: unexpected panic ``` Even worse, on current stable(1.20.0), the compiler falls into an infinite loop. This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE. ``` error: expected one of `:`, `@`, or `|`, found `}` --> 44021.rs:3:20 | 3 | fn foo() {|x, y} | ^ expected one of `:`, `@`, or `|` here ```
Parse nested closure with two consecutive parameter lists properly This is a followup of #44332. --- Currently, in nightly, this does not compile: ```rust fn main() { let f = |_||x, y| x+y; println!("{}", f(())(1, 2)); // should print 3 } ``` `|_||x, y| x+y` should be parsed as `|_| (|x, y| x+y)`, but the parser didn't accept `||` between `_` and `x`. This patch fixes the problem. r? @petrochenkov
Fixes #44021.
Originally, the parser just called
bump
to discard following token after parsing closure parameter list, because it assumes|
is following. However, the following code breaks the assumption:Here, the parameter list is
x, y
and the following token is}
. The parser discards}
, and then we have a curly bracket mismatch.Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE.
Even worse, on current stable(1.20.0), the compiler falls into an infinite loop.
This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE.