Rollup merge of #121376 - Nadrieril:mir-half-ranges, r=pnkfelix
Skip unnecessary comparison with half-open range patterns This is the last remaining detail in the implementation of half-open range patterns. Until now, a half-open range pattern like `10..` was converted to `10..T::MAX` before lowering to MIR, which generated an extra pointless comparison. With this PR we don't generate it.
This commit is contained in:
commit
2e0a26a32a
2 changed files with 33 additions and 39 deletions
|
@ -815,7 +815,9 @@ pub enum PatKind<'tcx> {
|
|||
/// The boundaries must be of the same type and that type must be numeric.
|
||||
#[derive(Clone, Debug, PartialEq, HashStable, TypeVisitable)]
|
||||
pub struct PatRange<'tcx> {
|
||||
/// Must not be `PosInfinity`.
|
||||
pub lo: PatRangeBoundary<'tcx>,
|
||||
/// Must not be `NegInfinity`.
|
||||
pub hi: PatRangeBoundary<'tcx>,
|
||||
#[type_visitable(ignore)]
|
||||
pub end: RangeEnd,
|
||||
|
@ -958,22 +960,6 @@ impl<'tcx> PatRangeBoundary<'tcx> {
|
|||
Self::NegInfinity | Self::PosInfinity => None,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn to_const(self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> mir::Const<'tcx> {
|
||||
match self {
|
||||
Self::Finite(value) => value,
|
||||
Self::NegInfinity => {
|
||||
// Unwrap is ok because the type is known to be numeric.
|
||||
let c = ty.numeric_min_val(tcx).unwrap();
|
||||
mir::Const::from_ty_const(c, tcx)
|
||||
}
|
||||
Self::PosInfinity => {
|
||||
// Unwrap is ok because the type is known to be numeric.
|
||||
let c = ty.numeric_max_val(tcx).unwrap();
|
||||
mir::Const::from_ty_const(c, tcx)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn eval_bits(self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> u128 {
|
||||
match self {
|
||||
Self::Finite(value) => value.eval_bits(tcx, param_env),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue