Skip to content

Commit 52a4946

Browse files
committed
Simplify or-patterns in MIR building
1 parent a916ac2 commit 52a4946

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/librustc_mir/build/matches/simplify.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3535
changed = true;
3636
}
3737
Err(match_pair) => {
38+
// Re-add the `match_pair` we were unable to simplify.
3839
candidate.match_pairs.push(match_pair);
3940
}
4041
}
@@ -198,7 +199,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
198199
Ok(())
199200
}
200201

201-
PatKind::Or { .. } => Err(match_pair),
202+
PatKind::Or { ref pats } => {
203+
candidate
204+
.match_pairs
205+
.extend(pats.iter().map(|pat| MatchPair::new(match_pair.place.clone(), pat)));
206+
Ok(())
207+
}
202208
}
203209
}
204210
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-pass
2+
3+
#![feature(or_patterns)]
4+
//~^ WARN the feature `or_patterns` is incomplete and may cause the compiler to crash
5+
6+
fn main() {
7+
let _ | _ = (); // ok
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
2+
--> $DIR/irrefutable-or-binding.rs:3:12
3+
|
4+
LL | #![feature(or_patterns)]
5+
| ^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+

0 commit comments

Comments
 (0)