diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index d3f71e75d99..6bbf9690bf6 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -149,17 +149,15 @@ pub fn is_region(&self) -> bool { } } - pub fn expect_anon_placeholder(self) -> u32 { + pub fn expect_placeholder_index(self) -> usize { match self.kind { CanonicalVarKind::Ty(_) | CanonicalVarKind::Region(_) | CanonicalVarKind::Const(_, _) => bug!("expected placeholder: {self:?}"), - CanonicalVarKind::PlaceholderRegion(placeholder) => { - placeholder.bound.kind.expect_anon() - } - CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.bound.kind.expect_anon(), - CanonicalVarKind::PlaceholderConst(placeholder, _) => placeholder.bound.as_u32(), + CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.bound.var.as_usize(), + CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.bound.var.as_usize(), + CanonicalVarKind::PlaceholderConst(placeholder, _) => placeholder.bound.as_usize(), } } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index f6d79e94a51..76194f350f5 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -107,15 +107,6 @@ pub fn get_id(&self) -> Option { _ => None, } } - - pub fn expect_anon(&self) -> u32 { - match *self { - BoundRegionKind::BrNamed(_, _) | BoundRegionKind::BrEnv => { - bug!("expected anon region: {self:?}") - } - BoundRegionKind::BrAnon(idx, _) => idx, - } - } } pub trait Article { @@ -1537,15 +1528,6 @@ pub enum BoundTyKind { Param(DefId, Symbol), } -impl BoundTyKind { - pub fn expect_anon(self) -> u32 { - match self { - BoundTyKind::Anon(i) => i, - _ => bug!(), - } - } -} - impl From for BoundTy { fn from(var: BoundVar) -> Self { BoundTy { var, kind: BoundTyKind::Anon(var.as_u32()) } diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs index ee90488730a..714b6dfb717 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs @@ -188,7 +188,7 @@ fn compute_query_response_substitution( } else { // For placeholders which were already part of the input, we simply map this // universal bound variable back the placeholder of the input. - original_values[info.expect_anon_placeholder() as usize] + original_values[info.expect_placeholder_index()] } }, )); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index f7caf50c56a..c59e496eb0a 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -1168,13 +1168,12 @@ fn interner(&self) -> TyCtxt<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { match *t.kind() { - ty::Placeholder(ty::PlaceholderType { - universe: ty::UniverseIndex::ROOT, - bound: ty::BoundTy { kind: name, .. }, - }) => match self.params.get(&name.expect_anon()) { - Some(&ty::ParamTy { index, name }) => self.tcx.mk_ty_param(index, name), - None => t, - }, + ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, bound }) => { + match self.params.get(&bound.var.as_u32()) { + Some(&ty::ParamTy { index, name }) => self.tcx.mk_ty_param(index, name), + None => t, + } + } _ => t.super_fold_with(self), } @@ -1202,8 +1201,7 @@ impl<'tcx> TypeVisitor> for PlaceholdersCollector { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { ty::Placeholder(p) if p.universe == self.universe_index => { - self.next_ty_placeholder = - self.next_ty_placeholder.max(p.bound.kind.expect_anon() as usize + 1); + self.next_ty_placeholder = self.next_ty_placeholder.max(p.bound.var.as_usize() + 1); } _ => (),