1
Fork 0

Remove the Option part of range ends in the HIR

This commit is contained in:
Oli Scherer 2025-02-05 15:22:10 +00:00
parent 0e7b283573
commit e8f7a382be
32 changed files with 400 additions and 269 deletions

View file

@ -220,7 +220,7 @@ impl FlagComputation {
&ty::Pat(ty, pat) => {
self.add_ty(ty);
match *pat {
ty::PatternKind::Range { start, end, include_end: _ } => {
ty::PatternKind::Range { start, end } => {
self.add_const(start);
self.add_const(end);
}

View file

@ -1,7 +1,6 @@
use std::fmt;
use rustc_data_structures::intern::Interned;
use rustc_hir::RangeEnd;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use crate::ty;
@ -27,8 +26,8 @@ impl<'tcx> fmt::Debug for Pattern<'tcx> {
impl<'tcx> fmt::Debug for PatternKind<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
PatternKind::Range { start, end, include_end } => {
write!(f, "{start}{include_end}{end}")
PatternKind::Range { start, end } => {
write!(f, "{start}..={end}")
}
}
}
@ -37,5 +36,5 @@ impl<'tcx> fmt::Debug for PatternKind<'tcx> {
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
pub enum PatternKind<'tcx> {
Range { start: ty::Const<'tcx>, end: ty::Const<'tcx>, include_end: RangeEnd },
Range { start: ty::Const<'tcx>, end: ty::Const<'tcx> },
}

View file

@ -51,21 +51,12 @@ impl<'tcx> Relate<TyCtxt<'tcx>> for ty::Pattern<'tcx> {
) -> RelateResult<'tcx, Self> {
match (&*a, &*b) {
(
&ty::PatternKind::Range { start: start_a, end: end_a, include_end: inc_a },
&ty::PatternKind::Range { start: start_b, end: end_b, include_end: inc_b },
&ty::PatternKind::Range { start: start_a, end: end_a },
&ty::PatternKind::Range { start: start_b, end: end_b },
) => {
let start = relation.relate(start_a, start_b)?;
// FIXME(pattern_types): make equal patterns equal (`0..5` is the same as `0..=6`).
let end = relation.relate(end_a, end_b)?;
if inc_a == inc_b {
Ok(relation.cx().mk_pat(ty::PatternKind::Range {
start,
end,
include_end: inc_a,
}))
} else {
Err(TypeError::Mismatch)
}
Ok(relation.cx().mk_pat(ty::PatternKind::Range { start, end }))
}
}
}

View file

@ -137,7 +137,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
ty::Pat(ty, pat) => {
match *pat {
ty::PatternKind::Range { start, end, include_end: _ } => {
ty::PatternKind::Range { start, end } => {
stack.push(end.into());
stack.push(start.into());
}