Skip to content

Commit a6cbf7a

Browse files
committed
Separate pattern lowering from pattern type lowering
1 parent c9d886e commit a6cbf7a

File tree

1 file changed

+28
-24
lines changed
  • compiler/rustc_hir_analysis/src/hir_ty_lowering

1 file changed

+28
-24
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -2698,30 +2698,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26982698
hir::TyKind::Pat(ty, pat) => {
26992699
let ty_span = ty.span;
27002700
let ty = self.lower_ty(ty);
2701-
let pat_ty = match pat.kind {
2702-
hir::TyPatKind::Range(start, end) => {
2703-
let (ty, start, end) = match ty.kind() {
2704-
// Keep this list of types in sync with the list of types that
2705-
// the `RangePattern` trait is implemented for.
2706-
ty::Int(_) | ty::Uint(_) | ty::Char => {
2707-
let start = self.lower_const_arg(start, FeedConstTy::No);
2708-
let end = self.lower_const_arg(end, FeedConstTy::No);
2709-
(ty, start, end)
2710-
}
2711-
_ => {
2712-
let guar = self.dcx().span_delayed_bug(
2713-
ty_span,
2714-
"invalid base type for range pattern",
2715-
);
2716-
let errc = ty::Const::new_error(tcx, guar);
2717-
(Ty::new_error(tcx, guar), errc, errc)
2718-
}
2719-
};
2720-
2721-
let pat = tcx.mk_pat(ty::PatternKind::Range { start, end });
2722-
Ty::new_pat(tcx, ty, pat)
2723-
}
2724-
hir::TyPatKind::Err(e) => Ty::new_error(tcx, e),
2701+
let pat_ty = match self.lower_pat_ty_pat(ty, ty_span, pat) {
2702+
Ok(kind) => Ty::new_pat(tcx, ty, tcx.mk_pat(kind)),
2703+
Err(guar) => Ty::new_error(tcx, guar),
27252704
};
27262705
self.record_ty(pat.hir_id, ty, pat.span);
27272706
pat_ty
@@ -2733,6 +2712,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27332712
result_ty
27342713
}
27352714

2715+
fn lower_pat_ty_pat(
2716+
&self,
2717+
ty: Ty<'tcx>,
2718+
ty_span: Span,
2719+
pat: &hir::TyPat<'tcx>,
2720+
) -> Result<ty::PatternKind<'tcx>, ErrorGuaranteed> {
2721+
match pat.kind {
2722+
hir::TyPatKind::Range(start, end) => {
2723+
match ty.kind() {
2724+
// Keep this list of types in sync with the list of types that
2725+
// the `RangePattern` trait is implemented for.
2726+
ty::Int(_) | ty::Uint(_) | ty::Char => {
2727+
let start = self.lower_const_arg(start, FeedConstTy::No);
2728+
let end = self.lower_const_arg(end, FeedConstTy::No);
2729+
Ok(ty::PatternKind::Range { start, end })
2730+
}
2731+
_ => Err(self
2732+
.dcx()
2733+
.span_delayed_bug(ty_span, "invalid base type for range pattern")),
2734+
}
2735+
}
2736+
hir::TyPatKind::Err(e) => Err(e),
2737+
}
2738+
}
2739+
27362740
/// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
27372741
#[instrument(level = "debug", skip(self), ret)]
27382742
fn lower_opaque_ty(&self, def_id: LocalDefId, in_trait: bool) -> Ty<'tcx> {

0 commit comments

Comments
 (0)