Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Nov 15, 2019
1 parent cde9808 commit 694a511
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ enum Constructor<'tcx> {
ConstantValue(&'tcx ty::Const<'tcx>),
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
IntRange(IntRange<'tcx>),
/// Ranges of non-integer literal values (`2.0..=5.2`).
ConstantRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, RangeEnd),
/// Ranges of floating-point literal values (`2.0..=5.2`).
FloatRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, RangeEnd),
/// Array patterns of length `n`.
FixedLenSlice(u64),
/// Slice patterns. Captures any array constructor of `length >= i + j`.
Expand Down Expand Up @@ -632,7 +632,7 @@ impl<'tcx> Constructor<'tcx> {
fn subtract_ctors(&self, other_ctors: &Vec<Constructor<'tcx>>) -> Vec<Constructor<'tcx>> {
match self {
// Those constructors can only match themselves.
Single | Variant(_) | ConstantValue(..) | ConstantRange(..) => {
Single | Variant(_) | ConstantValue(..) | FloatRange(..) => {
if other_ctors.iter().any(|c| c == self) { vec![] } else { vec![self.clone()] }
}
&FixedLenSlice(self_len) => {
Expand Down Expand Up @@ -727,7 +727,7 @@ impl<'tcx> Constructor<'tcx> {
}
}

// Convert the ranges back into constructors
// Convert the ranges back into constructors.
remaining_ranges.into_iter().map(IntRange).collect()
}
// This constructor is never covered by anything else
Expand Down Expand Up @@ -805,7 +805,7 @@ impl<'tcx> Constructor<'tcx> {
}
_ => bug!("bad slice pattern {:?} {:?}", self, ty),
},
ConstantValue(..) | ConstantRange(..) | IntRange(..) | NonExhaustive => vec![],
ConstantValue(..) | FloatRange(..) | IntRange(..) | NonExhaustive => vec![],
}
}

Expand All @@ -830,7 +830,7 @@ impl<'tcx> Constructor<'tcx> {
},
FixedLenSlice(length) => *length,
VarLenSlice(prefix, suffix) => prefix + suffix,
ConstantValue(..) | ConstantRange(..) | IntRange(..) | NonExhaustive => 0,
ConstantValue(..) | FloatRange(..) | IntRange(..) | NonExhaustive => 0,
}
}

Expand Down Expand Up @@ -894,10 +894,8 @@ impl<'tcx> Constructor<'tcx> {
PatKind::Slice { prefix, slice: Some(wild), suffix }
}
&ConstantValue(value) => PatKind::Constant { value },
&ConstantRange(lo, hi, end) => PatKind::Range(PatRange { lo, hi, end }),
IntRange(range) => {
return range.to_pat(cx.tcx);
}
&FloatRange(lo, hi, end) => PatKind::Range(PatRange { lo, hi, end }),
IntRange(range) => return range.to_pat(cx.tcx),
NonExhaustive => PatKind::Wild,
};

Expand Down Expand Up @@ -1297,7 +1295,7 @@ impl<'tcx> IntRange<'tcx> {
let (lo, hi) = (lo ^ bias, hi ^ bias);
let offset = (*end == RangeEnd::Excluded) as u128;
if lo > hi || (lo == hi && *end == RangeEnd::Excluded) {
// This hould have been caught earlier by E0030
// This should have been caught earlier by E0030.
bug!("malformed range pattern: {}..={}", lo, (hi - offset));
}
Some(IntRange { range: lo..=(hi - offset), ty, span })
Expand Down Expand Up @@ -1692,7 +1690,7 @@ fn pat_constructor<'tcx>(
) {
Some(IntRange(int_range))
} else {
Some(ConstantRange(lo, hi, end))
Some(FloatRange(lo, hi, end))
}
}
PatKind::Array { .. } => match pat.ty.kind {
Expand Down Expand Up @@ -2091,7 +2089,7 @@ fn constructor_covered_by_range<'tcx>(
};
let (ctor_from, ctor_to, ctor_end) = match *ctor {
ConstantValue(value) => (value, value, RangeEnd::Included),
ConstantRange(from, to, ctor_end) => (from, to, ctor_end),
FloatRange(from, to, ctor_end) => (from, to, ctor_end),
_ => bug!("`constructor_covered_by_range` called with {:?}", ctor),
};
trace!("constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}", ctor, pat_from, pat_to, ty);
Expand Down

0 comments on commit 694a511

Please sign in to comment.