Fix #1476: Add support for exclusive pattern matches.

This commit is contained in:
Tom Prince 2017-01-26 15:32:34 -07:00
parent 4ea0f72a15
commit 3e03b5d1a7
3 changed files with 8 additions and 4 deletions

View file

@ -361,7 +361,7 @@ fn all_ranges(cx: &LateContext, arms: &[Arm]) -> Vec<SpannedRange<ConstVal>> {
}
.filter_map(|pat| {
if_let_chain! {[
let PatKind::Range(ref lhs, ref rhs) = pat.node,
let PatKind::Range(ref lhs, ref rhs, _) = pat.node,
let Ok(lhs) = constcx.eval(lhs, ExprTypeChecked),
let Ok(rhs) = constcx.eval(rhs, ExprTypeChecked)
], {

View file

@ -160,8 +160,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
(&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => {
ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
},
(&PatKind::Range(ref ls, ref le), &PatKind::Range(ref rs, ref re)) => {
self.eq_expr(ls, rs) && self.eq_expr(le, re)
(&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => {
self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri)
},
(&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
(&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {

View file

@ -475,10 +475,14 @@ fn print_pat(cx: &LateContext, pat: &hir::Pat, indent: usize) {
println!("{}Lit", ind);
print_expr(cx, e, indent + 1);
},
hir::PatKind::Range(ref l, ref r) => {
hir::PatKind::Range(ref l, ref r, ref range_end) => {
println!("{}Range", ind);
print_expr(cx, l, indent + 1);
print_expr(cx, r, indent + 1);
match *range_end {
hir::RangeEnd::Included => println!("{} end included", ind),
hir::RangeEnd::Excluded => println!("{} end excluded", ind),
}
},
hir::PatKind::Slice(ref first_pats, ref range, ref last_pats) => {
println!("{}Slice [a, b, ..i, y, z]", ind);