Skip to content

Commit eea0b79

Browse files
committed
We no longer construct any ConstantValue or ConstantRange for non-integral types
1 parent b85e4be commit eea0b79

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,7 @@ impl<'tcx> Constructor<'tcx> {
649649
match self {
650650
// Any base constructor can be used unchanged.
651651
Single | Variant(_) | ConstantValue(_) | FixedLenSlice(_) => smallvec![self],
652-
ConstantRange(..) | IntRange(..)
653-
if IntRange::should_treat_range_exhaustively(cx.tcx, ty) =>
654-
{
652+
IntRange(..) if IntRange::should_treat_range_exhaustively(cx.tcx, ty) => {
655653
// Splitting up a range naïvely would mean creating a separate constructor for
656654
// every single value in the range, which is clearly impractical. We therefore want
657655
// to keep together subranges for which the specialisation will be identical across
@@ -736,6 +734,7 @@ impl<'tcx> Constructor<'tcx> {
736734
.map(|range| IntRange::range_to_ctor(cx.tcx, ty, range))
737735
.collect()
738736
}
737+
// When not treated exhaustively, don't split ranges.
739738
ConstantRange(..) | IntRange(..) => smallvec![self],
740739
VarLenSlice(self_prefix, self_suffix) => {
741740
// A variable-length slice pattern is matched by an infinite collection of
@@ -927,12 +926,8 @@ impl<'tcx> Constructor<'tcx> {
927926
match self {
928927
// Those constructors can't intersect with a non-wildcard meta-constructor, so we're
929928
// fine just comparing for equality.
930-
Single | Variant(_) => {
931-
if used_ctors.iter().any(|c| c == &self) {
932-
smallvec![]
933-
} else {
934-
smallvec![self]
935-
}
929+
Single | Variant(_) | ConstantRange(..) | ConstantValue(..) => {
930+
if used_ctors.iter().any(|c| c == &self) { smallvec![] } else { smallvec![self] }
936931
}
937932
FixedLenSlice(self_len) => {
938933
let overlaps = |c: &Constructor<'_>| match c {
@@ -1047,7 +1042,7 @@ impl<'tcx> Constructor<'tcx> {
10471042

10481043
remaining_ctors
10491044
}
1050-
ConstantRange(..) | ConstantValue(..) | IntRange(..) => {
1045+
IntRange(..) => {
10511046
let mut remaining_ctors = smallvec![self];
10521047

10531048
// For each used ctor, subtract from the current set of constructors.
@@ -1603,16 +1598,12 @@ impl<'tcx> IntRange<'tcx> {
16031598
}
16041599

16051600
fn from_ctor(
1606-
tcx: TyCtxt<'tcx>,
1607-
param_env: ty::ParamEnv<'tcx>,
1601+
_tcx: TyCtxt<'tcx>,
1602+
_param_env: ty::ParamEnv<'tcx>,
16081603
ctor: &Constructor<'tcx>,
16091604
) -> Option<IntRange<'tcx>> {
1610-
// Floating-point ranges are permitted and we don't want
1611-
// to consider them when constructing integer ranges.
16121605
match ctor {
16131606
IntRange(range) => Some(range.clone()),
1614-
ConstantRange(lo, hi, end) => Self::from_range(tcx, param_env, lo, hi, end),
1615-
ConstantValue(val) => Self::from_const(tcx, param_env, val),
16161607
_ => None,
16171608
}
16181609
}
@@ -2001,17 +1992,6 @@ fn slice_pat_covered_by_const<'tcx>(
20011992
Ok(true)
20021993
}
20031994

2004-
// Whether a constructor is a range or constant with an integer type.
2005-
fn is_integral_range(ctor: &Constructor<'tcx>) -> bool {
2006-
let ty = match ctor {
2007-
IntRange(_) => return true,
2008-
ConstantValue(value) => value.ty,
2009-
ConstantRange(lo, _, _) => lo.ty,
2010-
_ => return false,
2011-
};
2012-
IntRange::is_integral(ty)
2013-
}
2014-
20151995
/// Checks whether there exists any shared value in either `ctor` or `pat` by intersecting them.
20161996
// This has a single call site that can be hot
20171997
#[inline(always)]
@@ -2024,21 +2004,21 @@ fn constructor_intersects_pattern<'p, 'tcx>(
20242004
trace!("constructor_intersects_pattern {:#?}, {:#?}", ctor, pat);
20252005
if let Single = ctor {
20262006
Some(PatStack::default())
2027-
} else if is_integral_range(ctor) {
2028-
let range = match *pat.kind {
2029-
PatKind::Constant { value } => ConstantValue(value),
2030-
PatKind::Range(PatRange { lo, hi, end }) => ConstantRange(lo, hi, end),
2007+
} else if let IntRange(ctor) = ctor {
2008+
let pat = match *pat.kind {
2009+
PatKind::Constant { value } => IntRange::from_const(tcx, param_env, value)?,
2010+
PatKind::Range(PatRange { lo, hi, end }) => {
2011+
IntRange::from_range(tcx, param_env, lo, hi, &end)?
2012+
}
20312013
_ => bug!("`constructor_intersects_pattern` called with {:?}", pat),
20322014
};
20332015

2034-
let pat = IntRange::from_ctor(tcx, param_env, &range)?;
2035-
let ctor = IntRange::from_ctor(tcx, param_env, ctor)?;
20362016
ctor.intersection(tcx, &pat)?;
20372017

20382018
// Constructor splitting should ensure that all intersections we encounter are actually
20392019
// inclusions.
20402020
let (pat_lo, pat_hi) = pat.range.into_inner();
2041-
let (ctor_lo, ctor_hi) = ctor.range.into_inner();
2021+
let (ctor_lo, ctor_hi) = ctor.range.clone().into_inner();
20422022
assert!(pat_lo <= ctor_lo && ctor_hi <= pat_hi);
20432023

20442024
Some(PatStack::default())

0 commit comments

Comments
 (0)