Skip to content

Commit 5959a35

Browse files
committed
Move logic from push_wild_constructor to apply_constructor
1 parent 4aa929c commit 5959a35

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -351,38 +351,15 @@ impl<'tcx> Witness<'tcx> {
351351
ty: Ty<'tcx>)
352352
-> Self
353353
{
354-
// If we've been trying to exhaustively match over the domain of values for a type,
355-
// then we can construct witnesses directly corresponding to the missing ranges of values,
356-
// giving far more precise diagnostics.
357-
// `ConstantValue` and `ConstantRange` only occur in practice when doing exhaustive value
358-
// matching (exhaustive_integer_patterns).
359-
match ctor {
360-
ConstantValue(value) => {
361-
Witness(vec![Pattern {
362-
ty,
363-
span: DUMMY_SP,
364-
kind: box PatternKind::Constant { value },
365-
}])
366-
}
367-
ConstantRange(lo, hi, end) => {
368-
Witness(vec![Pattern {
369-
ty,
370-
span: DUMMY_SP,
371-
kind: box PatternKind::Range { lo, hi, end: *end },
372-
}])
354+
let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
355+
self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
356+
Pattern {
357+
ty,
358+
span: DUMMY_SP,
359+
kind: box PatternKind::Wild,
373360
}
374-
_ => {
375-
let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
376-
self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
377-
Pattern {
378-
ty,
379-
span: DUMMY_SP,
380-
kind: box PatternKind::Wild,
381-
}
382-
}));
383-
self.apply_constructor(cx, ctor, ty)
384-
}
385-
}
361+
}));
362+
self.apply_constructor(cx, ctor, ty)
386363
}
387364

388365

@@ -409,7 +386,7 @@ impl<'tcx> Witness<'tcx> {
409386
let arity = constructor_arity(cx, ctor, ty);
410387
let pat = {
411388
let len = self.0.len() as u64;
412-
let mut pats = self.0.drain((len-arity) as usize..).rev();
389+
let mut pats = self.0.drain((len - arity) as usize..).rev();
413390

414391
match ty.sty {
415392
ty::TyAdt(..) |
@@ -452,6 +429,7 @@ impl<'tcx> Witness<'tcx> {
452429
_ => {
453430
match *ctor {
454431
ConstantValue(value) => PatternKind::Constant { value },
432+
ConstantRange(lo, hi, end) => PatternKind::Range { lo, hi, end },
455433
_ => PatternKind::Wild,
456434
}
457435
}

0 commit comments

Comments
 (0)