Skip to content

Commit 3e5aadc

Browse files
committed
Remove unnecessary data from ConstantValue/ConstantRange
1 parent f674f89 commit 3e5aadc

File tree

1 file changed

+14
-38
lines changed

1 file changed

+14
-38
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -582,19 +582,19 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
582582
}
583583
}
584584

585-
#[derive(Clone, Debug)]
585+
#[derive(Clone, Debug, PartialEq)]
586586
enum Constructor<'tcx> {
587587
/// The constructor of all patterns that don't vary by constructor,
588588
/// e.g., struct patterns and fixed-length arrays.
589589
Single,
590590
/// Enum variants.
591591
Variant(DefId),
592592
/// Literal values.
593-
ConstantValue(&'tcx ty::Const<'tcx>, Span),
593+
ConstantValue(&'tcx ty::Const<'tcx>),
594594
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
595595
IntRange(IntRange<'tcx>),
596596
/// Ranges of non-integer literal values (`2.0..=5.2`).
597-
ConstantRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, Ty<'tcx>, RangeEnd, Span),
597+
ConstantRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, RangeEnd),
598598
/// Array patterns of length `n`.
599599
FixedLenSlice(u64),
600600
/// Slice patterns. Captures any array constructor of `length >= i + j`.
@@ -603,29 +603,6 @@ enum Constructor<'tcx> {
603603
NonExhaustive,
604604
}
605605

606-
// Ignore spans when comparing, they don't carry semantic information as they are only for lints.
607-
impl<'tcx> std::cmp::PartialEq for Constructor<'tcx> {
608-
fn eq(&self, other: &Self) -> bool {
609-
match (self, other) {
610-
(Constructor::Single, Constructor::Single) => true,
611-
(Constructor::NonExhaustive, Constructor::NonExhaustive) => true,
612-
(Constructor::Variant(a), Constructor::Variant(b)) => a == b,
613-
(Constructor::ConstantValue(a, _), Constructor::ConstantValue(b, _)) => a == b,
614-
(
615-
Constructor::ConstantRange(a_start, a_end, a_ty, a_range_end, _),
616-
Constructor::ConstantRange(b_start, b_end, b_ty, b_range_end, _),
617-
) => a_start == b_start && a_end == b_end && a_ty == b_ty && a_range_end == b_range_end,
618-
(Constructor::IntRange(a), Constructor::IntRange(b)) => a == b,
619-
(Constructor::FixedLenSlice(a), Constructor::FixedLenSlice(b)) => a == b,
620-
(
621-
Constructor::VarLenSlice(a_prefix, a_suffix),
622-
Constructor::VarLenSlice(b_prefix, b_suffix),
623-
) => a_prefix == b_prefix && a_suffix == b_suffix,
624-
_ => false,
625-
}
626-
}
627-
}
628-
629606
impl<'tcx> Constructor<'tcx> {
630607
fn is_slice(&self) -> bool {
631608
match self {
@@ -652,7 +629,7 @@ impl<'tcx> Constructor<'tcx> {
652629
assert!(!adt.is_enum());
653630
VariantIdx::new(0)
654631
}
655-
ConstantValue(c, _) => crate::const_eval::const_variant_index(cx.tcx, cx.param_env, c),
632+
ConstantValue(c) => crate::const_eval::const_variant_index(cx.tcx, cx.param_env, c),
656633
_ => bug!("bad constructor {:?} for adt {:?}", self, adt),
657634
}
658635
}
@@ -938,8 +915,8 @@ impl<'tcx> Constructor<'tcx> {
938915
let wild = Pat::wildcard_from_ty(ty);
939916
PatKind::Slice { prefix, slice: Some(wild), suffix }
940917
}
941-
&ConstantValue(value, _) => PatKind::Constant { value },
942-
&ConstantRange(lo, hi, _, end, _) => PatKind::Range(PatRange { lo, hi, end }),
918+
&ConstantValue(value) => PatKind::Constant { value },
919+
&ConstantRange(lo, hi, end) => PatKind::Range(PatRange { lo, hi, end }),
943920
IntRange(range) => {
944921
return range.to_pat(cx.tcx);
945922
}
@@ -1148,10 +1125,9 @@ fn all_constructors<'a, 'tcx>(
11481125
)
11491126
};
11501127
match pcx.ty.kind {
1151-
ty::Bool => [true, false]
1152-
.iter()
1153-
.map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b), pcx.span))
1154-
.collect(),
1128+
ty::Bool => {
1129+
[true, false].iter().map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b))).collect()
1130+
}
11551131
ty::Array(ref sub_ty, len) if len.try_eval_usize(cx.tcx, cx.param_env).is_some() => {
11561132
let len = len.eval_usize(cx.tcx, cx.param_env);
11571133
if len != 0 && cx.is_uninhabited(sub_ty) { vec![] } else { vec![FixedLenSlice(len)] }
@@ -1721,7 +1697,7 @@ fn pat_constructor<'tcx>(
17211697
if let Some(int_range) = IntRange::from_const(tcx, param_env, value, pat.span) {
17221698
Some(IntRange(int_range))
17231699
} else {
1724-
Some(ConstantValue(value, pat.span))
1700+
Some(ConstantValue(value))
17251701
}
17261702
}
17271703
PatKind::Range(PatRange { lo, hi, end }) => {
@@ -1736,7 +1712,7 @@ fn pat_constructor<'tcx>(
17361712
) {
17371713
Some(IntRange(int_range))
17381714
} else {
1739-
Some(ConstantRange(lo, hi, ty, end, pat.span))
1715+
Some(ConstantRange(lo, hi, end))
17401716
}
17411717
}
17421718
PatKind::Array { .. } => match pat.ty.kind {
@@ -2134,8 +2110,8 @@ fn constructor_covered_by_range<'tcx>(
21342110
_ => bug!("`constructor_covered_by_range` called with {:?}", pat),
21352111
};
21362112
let (ctor_from, ctor_to, ctor_end) = match *ctor {
2137-
ConstantValue(value, _) => (value, value, RangeEnd::Included),
2138-
ConstantRange(from, to, _, ctor_end, _) => (from, to, ctor_end),
2113+
ConstantValue(value) => (value, value, RangeEnd::Included),
2114+
ConstantRange(from, to, ctor_end) => (from, to, ctor_end),
21392115
_ => bug!("`constructor_covered_by_range` called with {:?}", ctor),
21402116
};
21412117
trace!("constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}", ctor, pat_from, pat_to, ty);
@@ -2331,7 +2307,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
23312307
None
23322308
}
23332309
}
2334-
ConstantValue(cv, _) => {
2310+
ConstantValue(cv) => {
23352311
match slice_pat_covered_by_const(
23362312
cx.tcx,
23372313
pat.span,

0 commit comments

Comments
 (0)