Remove expect_anon and expect_anon_placeholder in favor of var

This commit is contained in:
Jack Huey 2023-04-06 21:26:38 -04:00
parent 4646b3df6a
commit 167b70692b
4 changed files with 12 additions and 34 deletions

View File

@ -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(),
}
}
}

View File

@ -107,15 +107,6 @@ pub fn get_id(&self) -> Option<DefId> {
_ => 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<BoundVar> for BoundTy {
fn from(var: BoundVar) -> Self {
BoundTy { var, kind: BoundTyKind::Anon(var.as_u32()) }

View File

@ -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()]
}
},
));

View File

@ -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<TyCtxt<'tcx>> for PlaceholdersCollector {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
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);
}
_ => (),