1
Fork 0

Move logic from push_wild_constructor to apply_constructor

This commit is contained in:
varkor 2018-08-12 20:39:53 +01:00
parent 4aa929cf8b
commit 5959a358e4

View file

@ -351,38 +351,15 @@ impl<'tcx> Witness<'tcx> {
ty: Ty<'tcx>) ty: Ty<'tcx>)
-> Self -> Self
{ {
// If we've been trying to exhaustively match over the domain of values for a type, let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
// then we can construct witnesses directly corresponding to the missing ranges of values, self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
// giving far more precise diagnostics. Pattern {
// `ConstantValue` and `ConstantRange` only occur in practice when doing exhaustive value ty,
// matching (exhaustive_integer_patterns). span: DUMMY_SP,
match ctor { kind: box PatternKind::Wild,
ConstantValue(value) => {
Witness(vec![Pattern {
ty,
span: DUMMY_SP,
kind: box PatternKind::Constant { value },
}])
} }
ConstantRange(lo, hi, end) => { }));
Witness(vec![Pattern { self.apply_constructor(cx, ctor, ty)
ty,
span: DUMMY_SP,
kind: box PatternKind::Range { lo, hi, end: *end },
}])
}
_ => {
let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
Pattern {
ty,
span: DUMMY_SP,
kind: box PatternKind::Wild,
}
}));
self.apply_constructor(cx, ctor, ty)
}
}
} }
@ -409,7 +386,7 @@ impl<'tcx> Witness<'tcx> {
let arity = constructor_arity(cx, ctor, ty); let arity = constructor_arity(cx, ctor, ty);
let pat = { let pat = {
let len = self.0.len() as u64; let len = self.0.len() as u64;
let mut pats = self.0.drain((len-arity) as usize..).rev(); let mut pats = self.0.drain((len - arity) as usize..).rev();
match ty.sty { match ty.sty {
ty::TyAdt(..) | ty::TyAdt(..) |
@ -452,6 +429,7 @@ impl<'tcx> Witness<'tcx> {
_ => { _ => {
match *ctor { match *ctor {
ConstantValue(value) => PatternKind::Constant { value }, ConstantValue(value) => PatternKind::Constant { value },
ConstantRange(lo, hi, end) => PatternKind::Range { lo, hi, end },
_ => PatternKind::Wild, _ => PatternKind::Wild,
} }
} }