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 replace_param_and_infer_substs_with_placeholder<'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 @@ impl<'tcx> TyCtxt<'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 @@ pub trait PrettyPrinter<'tcx>:
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 @@ pub trait PrettyPrinter<'tcx>:
}
}
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 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, '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 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, '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 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, '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 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'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 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
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 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'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 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'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,
},
})
}