diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2019-11-09 12:01:47 +0000 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2019-11-15 16:42:08 +0000 |
| commit | 6b8bfefa0014bc091acc433f15aa98d37b52e0ba (patch) | |
| tree | 06c1b4ac6957145605c2b120e7785df3c38368f9 | |
| parent | 4232816be9d9075e139bd372ab80d17301b6ada7 (diff) | |
| download | rust-6b8bfefa0014bc091acc433f15aa98d37b52e0ba.tar.gz rust-6b8bfefa0014bc091acc433f15aa98d37b52e0ba.zip | |
Add `IntRange::to_pat` and use it instead of custom `display()`
| -rw-r--r-- | src/librustc_mir/hair/pattern/_match.rs | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index b35e9abd2a4..c59f053f59d 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -956,8 +956,7 @@ impl<'tcx> Constructor<'tcx> { end, }), IntRange(range) => { - // TODO: do it more directly - return range.clone().into_ctor(cx.tcx).apply(cx, ty, None.into_iter()); + return range.to_pat(cx.tcx); } NonExhaustive => PatKind::Wild, }; @@ -1398,19 +1397,6 @@ impl<'tcx> IntRange<'tcx> { } } - /// Converts an `IntRange` to a `ConstantValue` or inclusive `ConstantRange`. - /// TODO: Deprecated - fn into_ctor(self, tcx: TyCtxt<'tcx>) -> Constructor<'tcx> { - let bias = IntRange::signed_bias(tcx, self.ty); - let (lo, hi) = self.range.into_inner(); - if lo == hi { - let ty = ty::ParamEnv::empty().and(self.ty); - ConstantValue(ty::Const::from_bits(tcx, lo ^ bias, ty), self.span) - } else { - ConstantRange(lo ^ bias, hi ^ bias, self.ty, RangeEnd::Included, self.span) - } - } - /// Returns a collection of ranges that spans the values covered by `ranges`, subtracted /// by the values covered by `self`: i.e., `ranges \ self` (in set notation). fn subtract_from(self, ranges: Vec<IntRange<'tcx>>) -> Vec<IntRange<'tcx>> { @@ -1474,7 +1460,7 @@ impl<'tcx> IntRange<'tcx> { (lo == other_hi || hi == other_lo) } - fn display(&self, tcx: TyCtxt<'tcx>) -> String { + fn to_pat(&self, tcx: TyCtxt<'tcx>) -> Pat<'tcx> { let (lo, hi) = (self.range.start(), self.range.end()); let bias = IntRange::signed_bias(tcx, self.ty); @@ -1484,11 +1470,14 @@ impl<'tcx> IntRange<'tcx> { let lo_const = ty::Const::from_bits(tcx, lo, ty); let hi_const = ty::Const::from_bits(tcx, hi, ty); - if lo == hi { - format!("{}", lo_const) + let kind = if lo == hi { + PatKind::Constant { value: lo_const } } else { - format!("{}{}{}", lo_const, RangeEnd::Included, hi_const) - } + PatKind::Range(PatRange { lo: lo_const, hi: hi_const, end: RangeEnd::Included }) + }; + + // This is a brand new pattern, so we don't reuse `self.span`. + Pat { ty: self.ty, span: DUMMY_SP, kind: Box::new(kind) } } } @@ -2137,7 +2126,7 @@ fn lint_overlapping_patterns( int_range.span, &format!( "this range overlaps on `{}`", - IntRange { range: int_range.range, ty, span: DUMMY_SP }.display(tcx), + IntRange { range: int_range.range, ty, span: DUMMY_SP }.to_pat(tcx), ), ); } |
