Skip to content

Commit d48cd48

Browse files
committed
Remove unnecessary data from ConstantValue/ConstantRange
1 parent b123415 commit d48cd48

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

src/librustc_mir/hair/pattern/_match.rs

+14-37
Original file line numberDiff line numberDiff line change
@@ -575,47 +575,25 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
575575
}
576576
}
577577

578-
#[derive(Clone, Debug)]
578+
#[derive(Clone, Debug, PartialEq)]
579579
enum Constructor<'tcx> {
580580
/// The constructor of all patterns that don't vary by constructor,
581581
/// e.g., struct patterns and fixed-length arrays.
582582
Single,
583583
/// Enum variants.
584584
Variant(DefId),
585585
/// Literal values.
586-
ConstantValue(&'tcx ty::Const<'tcx>, Span),
586+
ConstantValue(&'tcx ty::Const<'tcx>),
587587
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
588588
IntRange(IntRange<'tcx>),
589589
/// Ranges of non-integer literal values (`2.0..=5.2`).
590-
ConstantRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, Ty<'tcx>, RangeEnd, Span),
590+
ConstantRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, RangeEnd),
591591
/// Array patterns of length `n`.
592592
FixedLenSlice(u64),
593593
/// Slice patterns. Captures any array constructor of `length >= i + j`.
594594
VarLenSlice(u64, u64),
595595
}
596596

597-
// Ignore spans when comparing, they don't carry semantic information as they are only for lints.
598-
impl<'tcx> std::cmp::PartialEq for Constructor<'tcx> {
599-
fn eq(&self, other: &Self) -> bool {
600-
match (self, other) {
601-
(Constructor::Single, Constructor::Single) => true,
602-
(Constructor::Variant(a), Constructor::Variant(b)) => a == b,
603-
(Constructor::ConstantValue(a, _), Constructor::ConstantValue(b, _)) => a == b,
604-
(
605-
Constructor::ConstantRange(a_start, a_end, a_ty, a_range_end, _),
606-
Constructor::ConstantRange(b_start, b_end, b_ty, b_range_end, _),
607-
) => a_start == b_start && a_end == b_end && a_ty == b_ty && a_range_end == b_range_end,
608-
(Constructor::IntRange(a), Constructor::IntRange(b)) => a == b,
609-
(Constructor::FixedLenSlice(a), Constructor::FixedLenSlice(b)) => a == b,
610-
(
611-
Constructor::VarLenSlice(a_prefix, a_suffix),
612-
Constructor::VarLenSlice(b_prefix, b_suffix),
613-
) => a_prefix == b_prefix && a_suffix == b_suffix,
614-
_ => false,
615-
}
616-
}
617-
}
618-
619597
impl<'tcx> Constructor<'tcx> {
620598
fn is_slice(&self) -> bool {
621599
match self {
@@ -642,7 +620,7 @@ impl<'tcx> Constructor<'tcx> {
642620
assert!(!adt.is_enum());
643621
VariantIdx::new(0)
644622
}
645-
ConstantValue(c, _) => crate::const_eval::const_variant_index(cx.tcx, cx.param_env, c),
623+
ConstantValue(c) => crate::const_eval::const_variant_index(cx.tcx, cx.param_env, c),
646624
_ => bug!("bad constructor {:?} for adt {:?}", self, adt),
647625
}
648626
}
@@ -925,8 +903,8 @@ impl<'tcx> Constructor<'tcx> {
925903
},
926904

927905
_ => match *self {
928-
ConstantValue(value, _) => PatKind::Constant { value },
929-
ConstantRange(lo, hi, _, end, _) => PatKind::Range(PatRange { lo, hi, end }),
906+
ConstantValue(value) => PatKind::Constant { value },
907+
ConstantRange(lo, hi, end) => PatKind::Range(PatRange { lo, hi, end }),
930908
IntRange(ref range) => {
931909
return range.to_pat(cx.tcx);
932910
}
@@ -1136,10 +1114,9 @@ fn all_constructors<'a, 'tcx>(
11361114
)
11371115
};
11381116
let ctors = match pcx.ty.kind {
1139-
ty::Bool => [true, false]
1140-
.iter()
1141-
.map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b), pcx.span))
1142-
.collect(),
1117+
ty::Bool => {
1118+
[true, false].iter().map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b))).collect()
1119+
}
11431120
ty::Array(ref sub_ty, len) if len.try_eval_usize(cx.tcx, cx.param_env).is_some() => {
11441121
let len = len.eval_usize(cx.tcx, cx.param_env);
11451122
if len != 0 && cx.is_uninhabited(sub_ty) { vec![] } else { vec![FixedLenSlice(len)] }
@@ -1710,7 +1687,7 @@ fn pat_constructor<'tcx>(
17101687
if let Some(int_range) = IntRange::from_const(tcx, param_env, value, pat.span) {
17111688
Some(IntRange(int_range))
17121689
} else {
1713-
Some(ConstantValue(value, pat.span))
1690+
Some(ConstantValue(value))
17141691
}
17151692
}
17161693
PatKind::Range(PatRange { lo, hi, end }) => {
@@ -1725,7 +1702,7 @@ fn pat_constructor<'tcx>(
17251702
) {
17261703
Some(IntRange(int_range))
17271704
} else {
1728-
Some(ConstantRange(lo, hi, ty, end, pat.span))
1705+
Some(ConstantRange(lo, hi, end))
17291706
}
17301707
}
17311708
PatKind::Array { .. } => match pat.ty.kind {
@@ -2110,8 +2087,8 @@ fn constructor_covered_by_range<'tcx>(
21102087
_ => bug!("`constructor_covered_by_range` called with {:?}", pat),
21112088
};
21122089
let (ctor_from, ctor_to, ctor_end) = match *ctor {
2113-
ConstantValue(value, _) => (value, value, RangeEnd::Included),
2114-
ConstantRange(from, to, _, ctor_end, _) => (from, to, ctor_end),
2090+
ConstantValue(value) => (value, value, RangeEnd::Included),
2091+
ConstantRange(from, to, ctor_end) => (from, to, ctor_end),
21152092
_ => bug!("`constructor_covered_by_range` called with {:?}", ctor),
21162093
};
21172094
trace!("constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}", ctor, pat_from, pat_to, ty);
@@ -2300,7 +2277,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
23002277
None
23012278
}
23022279
}
2303-
ConstantValue(cv, _) => {
2280+
ConstantValue(cv) => {
23042281
match slice_pat_covered_by_const(
23052282
cx.tcx,
23062283
pat.span,

0 commit comments

Comments
 (0)