-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Suggest adding a =>
after match guard
#94932
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
Suggest adding a =>
after match guard
#94932
Conversation
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Does the following still parse after your change? fn main() {
let x = Some(It { a: 1 });
match x {
Some(x) if x == It { a: 0 } => {}
_ => {}
}
}
#[derive(PartialEq, Eq)]
struct It { a: i32 } |
=>
after match guard=>
after match guard
=>
after match guard=>
after match guard
@@ -2617,6 +2626,26 @@ impl<'a> Parser<'a> { | |||
} | |||
} | |||
|
|||
fn parse_match_guard_cond(&mut self) -> PResult<'a, P<Expr>> { | |||
let snapshot = self.clone(); |
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.
The only issue I'm seeing here is that this pessimises the parsing of every match arm. In this case I think it is reasonable to instead catch the problem in line 2499 and only in the error arm try to conditionally parse the match arm body. Probably also do that for the substitution cases handled right below.
let (is_lhs_struct, is_rhs_struct) = match cond.kind { | ||
ExprKind::Binary(_, ref lhs, ref rhs) => { | ||
(matches!(lhs.kind, ExprKind::Struct(..)), matches!(rhs.kind, ExprKind::Struct(..))) | ||
} | ||
_ => (false, false), | ||
}; |
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.
As you recognize here, we might want to also detect when a struct literal was parsed that instead was supposed to be an ident and the match arm body, but that is not as critical, I think.
☔ The latest upstream changes (presumably #98545) made this pull request unmergeable. Please resolve the merge conflicts. |
@TaKO8Ki any updates on this? |
Closing this as inactive |
closes #78585