Skip to content

Do not desugar if-let-else to match arm guards #41316

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

Merged
merged 5 commits into from Apr 15, 2017
Merged

Do not desugar if-let-else to match arm guards #41316

merged 5 commits into from Apr 15, 2017

Conversation

ghost
Copy link

@ghost ghost commented Apr 15, 2017

Fixes #41272
Changed the desugaring code

Before

match <sub_expr> {
     <pat> => <body>,
     [_ if <else_opt_if_cond> => <else_opt_if_body>,]
     _ => [<else_opt> | ()]
}

After

match <sub_expr> {
    <pat> => <body>,
     _       => [<else_opt> | ()]
}

With this fix, it doesn't cause E0301

@rust-highfive
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented Apr 15, 2017

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned arielb1 Apr 15, 2017
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the else branche below it should be indented one time (4 spaces) to the left.

fn bar(&mut self) -> bool { true }
}

/* This causes E0301. By fixing issue #41272 this problem should vanish */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ghost ghost changed the title Issue 41272 - problem with desugaring if let expression Change in desugaring if let expression Apr 15, 2017
@ghost ghost changed the title Change in desugaring if let expression Do not desugar if-let-else to match arm guards Apr 15, 2017
@eddyb
Copy link
Member

eddyb commented Apr 15, 2017

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 15, 2017

📌 Commit 5649b37 has been approved by eddyb

@bors
Copy link
Collaborator

bors commented Apr 15, 2017

⌛ Testing commit 5649b37 with merge c67cf5f...

bors added a commit that referenced this pull request Apr 15, 2017
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
@bors
Copy link
Collaborator

bors commented Apr 15, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing c67cf5f to master...

@bors bors merged commit 5649b37 into rust-lang:master Apr 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if clauses following an if let are compiled to match guards
5 participants