Do not desugar if-let-else to match arm guards#41316
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (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. |
|
r? @eddyb |
src/librustc/hir/lowering.rs
Outdated
| let wildcard_arm: Option<&Expr> = else_opt.as_ref().map(|p| &**p); | ||
| let wildcard_pattern = self.pat_wild(e.span); | ||
| let body = if let Some(else_expr) = wildcard_arm { | ||
| P(self.lower_expr(else_expr)) |
There was a problem hiding this comment.
This and the else branche below it should be indented one time (4 spaces) to the left.
src/test/run-pass/issue-41272.rs
Outdated
| fn bar(&mut self) -> bool { true } | ||
| } | ||
|
|
||
| /* This causes E0301. By fixing issue #41272 this problem should vanish */ |
There was a problem hiding this comment.
We don't use block comments, nor is this comment necessary here. FWIW error codes are also kind of useless since they say nothing about the actual error.
|
@bors r+ |
|
📌 Commit 5649b37 has been approved by |
Do not desugar if-let-else to match arm guards Fixes #41272 Changed the desugaring code **Before** ```rust match <sub_expr> { <pat> => <body>, [_ if <else_opt_if_cond> => <else_opt_if_body>,] _ => [<else_opt> | ()] } ``` **After** ```rust match <sub_expr> { <pat> => <body>, _ => [<else_opt> | ()] } ``` With this fix, it doesn't cause E0301
|
☀️ Test successful - status-appveyor, status-travis |
Fixes #41272
Changed the desugaring code
Before
After
With this fix, it doesn't cause E0301