Suggest adding a => after match guard#94932
Suggest adding a => after match guard#94932TaKO8Ki wants to merge 2 commits intorust-lang:masterfrom
=> after match guard#94932Conversation
|
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
| } | ||
|
|
||
| fn parse_match_guard_cond(&mut self) -> PResult<'a, P<Expr>> { | ||
| let snapshot = self.clone(); |
There was a problem hiding this comment.
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.
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