Skip to content

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

Merged
bors merged 5 commits into
masterfrom
unknown repository
Apr 15, 2017
Merged

Do not desugar if-let-else to match arm guards#41316
bors merged 5 commits into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Apr 15, 2017

Copy link
Copy Markdown

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
Copy Markdown
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

ghost commented Apr 15, 2017

Copy link
Copy Markdown
Author

r? @eddyb

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

Copy link
Copy Markdown
Contributor

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.

Comment thread 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 */

Copy link
Copy Markdown
Contributor

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

eddyb commented Apr 15, 2017

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Apr 15, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 5649b37 has been approved by eddyb

@bors

bors commented Apr 15, 2017

Copy link
Copy Markdown
Collaborator

⌛ 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

bors commented Apr 15, 2017

Copy link
Copy Markdown
Collaborator

☀️ 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