Remove u32 on BoundTyKind::Anon

This commit is contained in:
Jack Huey 2023-04-06 22:32:09 -04:00
parent f0edcc8a6f
commit b15195a304
7 changed files with 17 additions and 23 deletions

View file

@ -2139,7 +2139,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
universe: ty::UniverseIndex::ROOT,
bound: ty::BoundTy {
var: ty::BoundVar::from_u32(idx),
kind: ty::BoundTyKind::Anon(idx),
kind: ty::BoundTyKind::Anon,
},
})
} else {

View file

@ -389,9 +389,7 @@ fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
let index = entry.index();
let var = ty::BoundVar::from_usize(index);
let kind = entry
.or_insert_with(|| {
ty::BoundVariableKind::Ty(ty::BoundTyKind::Anon(index as u32))
})
.or_insert_with(|| ty::BoundVariableKind::Ty(ty::BoundTyKind::Anon))
.expect_ty();
self.tcx.mk_bound(ty::INNERMOST, BoundTy { var, kind })
}

View file

@ -701,9 +701,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
ty::Error(_) => p!("[type error]"),
ty::Param(ref param_ty) => p!(print(param_ty)),
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
ty::BoundTyKind::Anon(bv) => {
self.pretty_print_bound_var(debruijn, ty::BoundVar::from_u32(bv))?
}
ty::BoundTyKind::Anon => self.pretty_print_bound_var(debruijn, bound_ty.var)?,
ty::BoundTyKind::Param(_, s) => match self.should_print_verbose() {
true if debruijn == ty::INNERMOST => p!(write("^{}", s)),
true => p!(write("^{}_{}", debruijn.index(), s)),
@ -740,7 +738,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
}
}
ty::Placeholder(placeholder) => match placeholder.bound.kind {
ty::BoundTyKind::Anon(_) => p!(write("Placeholder({:?})", placeholder)),
ty::BoundTyKind::Anon => p!(write("Placeholder({:?})", placeholder)),
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
},
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {

View file

@ -1524,13 +1524,13 @@ pub struct BoundTy {
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
#[derive(HashStable)]
pub enum BoundTyKind {
Anon(u32),
Anon,
Param(DefId, Symbol),
}
impl From<BoundVar> for BoundTy {
fn from(var: BoundVar) -> Self {
BoundTy { var, kind: BoundTyKind::Anon(var.as_u32()) }
BoundTy { var, kind: BoundTyKind::Anon }
}
}

View file

@ -302,7 +302,7 @@ fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {
universe: placeholder.universe,
bound: ty::BoundTy {
var: ty::BoundVar::from_usize(self.variables.len()),
kind: ty::BoundTyKind::Anon(self.variables.len() as u32),
kind: ty::BoundTyKind::Anon,
},
}),
CanonicalizeMode::Response { .. } => CanonicalVarKind::PlaceholderTy(placeholder),
@ -312,7 +312,7 @@ fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {
universe: ty::UniverseIndex::ROOT,
bound: ty::BoundTy {
var: ty::BoundVar::from_usize(self.variables.len()),
kind: ty::BoundTyKind::Anon(self.variables.len() as u32),
kind: ty::BoundTyKind::Anon,
},
}),
CanonicalizeMode::Response { .. } => bug!("param ty in response: {t:?}"),
@ -351,7 +351,7 @@ fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {
var
}),
);
let bt = ty::BoundTy { var, kind: BoundTyKind::Anon(var.index() as u32) };
let bt = ty::BoundTy { var, kind: BoundTyKind::Anon };
self.interner().mk_bound(self.binder_index, bt)
}

View file

@ -95,17 +95,15 @@ fn replace_erased_lifetimes_with_bound_vars<'tcx>(
let mut counter = 0;
let ty = tcx.fold_regions(ty, |mut r, current_depth| {
if let ty::ReErased = r.kind() {
let br = ty::BoundRegion {
var: ty::BoundVar::from_u32(counter),
kind: ty::BrAnon(counter, None),
};
let br =
ty::BoundRegion { var: ty::BoundVar::from_u32(counter), kind: ty::BrAnon(None) };
counter += 1;
r = tcx.mk_re_late_bound(current_depth, br);
}
r
});
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
(0..counter).map(|i| ty::BoundVariableKind::Region(ty::BrAnon(i, None))),
(0..counter).map(|_| ty::BoundVariableKind::Region(ty::BrAnon(None))),
);
ty::Binder::bind_with_vars(ty, bound_vars)
}

View file

@ -479,14 +479,14 @@ fn lower_into(self, interner: RustInterner<'tcx>) -> Ty<'tcx> {
ty::DebruijnIndex::from_usize(bound.debruijn.depth() as usize),
ty::BoundTy {
var: ty::BoundVar::from_usize(bound.index),
kind: ty::BoundTyKind::Anon(bound.index as u32),
kind: ty::BoundTyKind::Anon,
},
),
TyKind::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
universe: ty::UniverseIndex::from_usize(placeholder.ui.counter),
bound: ty::BoundTy {
var: ty::BoundVar::from_usize(placeholder.idx),
kind: ty::BoundTyKind::Anon(placeholder.idx as u32),
kind: ty::BoundTyKind::Anon,
},
}),
TyKind::InferenceVar(_, _) => unimplemented!(),
@ -691,7 +691,7 @@ fn lower_into(
let self_ty = interner.tcx.mk_bound(
// This is going to be wrapped in a binder
ty::DebruijnIndex::from_usize(1),
ty::BoundTy { var: ty::BoundVar::from_usize(0), kind: ty::BoundTyKind::Anon(0) },
ty::BoundTy { var: ty::BoundVar::from_usize(0), kind: ty::BoundTyKind::Anon },
);
let where_clauses = predicates.into_iter().map(|predicate| {
let (predicate, binders, _named_regions) =
@ -1098,7 +1098,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
universe: ty::UniverseIndex::from_usize(0),
bound: ty::BoundTy {
var: ty::BoundVar::from_usize(idx),
kind: ty::BoundTyKind::Anon(idx as u32),
kind: ty::BoundTyKind::Anon,
},
}),
None => {
@ -1109,7 +1109,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
universe: ty::UniverseIndex::from_usize(0),
bound: ty::BoundTy {
var: ty::BoundVar::from_usize(idx),
kind: ty::BoundTyKind::Anon(idx as u32),
kind: ty::BoundTyKind::Anon,
},
})
}