1
Fork 0

Use BoundTy and BoundRegion instead of kind of PlaceholderTy and PlaceholderRegion

This commit is contained in:
Jack Huey 2023-04-06 21:12:17 -04:00
parent c934ce9e0a
commit 4646b3df6a
20 changed files with 121 additions and 75 deletions

View file

@ -125,9 +125,9 @@ impl<'tcx> InferCtxt<'tcx> {
ty.into()
}
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, name }) => {
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound }) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, name };
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, bound };
self.tcx.mk_placeholder(placeholder_mapped).into()
}
@ -138,9 +138,9 @@ impl<'tcx> InferCtxt<'tcx> {
)
.into(),
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => {
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, bound }) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, name };
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, bound };
self.tcx.mk_re_placeholder(placeholder_mapped).into()
}
@ -152,9 +152,9 @@ impl<'tcx> InferCtxt<'tcx> {
)
.into(),
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }, ty) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
self.tcx.mk_const(placeholder_mapped, ty).into()
}
}

View file

@ -170,15 +170,15 @@ fn msg_span_from_named_region<'tcx>(
}
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BoundRegionKind::BrNamed(def_id, name),
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrNamed(def_id, name), .. },
..
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BoundRegionKind::BrAnon(_, Some(span)),
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(_, Some(span)), .. },
..
}) => (format!("the anonymous lifetime defined here"), Some(span)),
ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BoundRegionKind::BrAnon(_, None),
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(_, None), .. },
..
}) => (format!("an anonymous lifetime"), None),
_ => bug!("{:?}", region),

View file

@ -16,8 +16,20 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
match &self.error {
Some(RegionResolutionError::ConcreteFailure(
SubregionOrigin::RelateRegionParamBound(span),
Region(Interned(RePlaceholder(ty::Placeholder { name: sub_name, .. }), _)),
Region(Interned(RePlaceholder(ty::Placeholder { name: sup_name, .. }), _)),
Region(Interned(
RePlaceholder(ty::Placeholder {
bound: ty::BoundRegion { kind: sub_name, .. },
..
}),
_,
)),
Region(Interned(
RePlaceholder(ty::Placeholder {
bound: ty::BoundRegion { kind: sup_name, .. },
..
}),
_,
)),
)) => {
let span = *span;
let (sub_span, sub_symbol) = match sub_name {

View file

@ -82,20 +82,20 @@ impl<'tcx> InferCtxt<'tcx> {
let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| {
self.tcx.mk_re_placeholder(ty::PlaceholderRegion {
universe: next_universe,
name: br.kind,
})
self.tcx
.mk_re_placeholder(ty::PlaceholderRegion { universe: next_universe, bound: br })
},
types: &mut |bound_ty: ty::BoundTy| {
self.tcx.mk_placeholder(ty::PlaceholderType {
universe: next_universe,
name: bound_ty.kind,
bound: bound_ty,
})
},
consts: &mut |bound_var: ty::BoundVar, ty| {
self.tcx
.mk_const(ty::PlaceholderConst { universe: next_universe, name: bound_var }, ty)
self.tcx.mk_const(
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
ty,
)
},
};

View file

@ -2130,13 +2130,17 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Infer(_) = t.kind() {
let idx = {
let idx = self.idx;
self.idx += 1;
idx
};
self.tcx.mk_placeholder(ty::PlaceholderType {
universe: ty::UniverseIndex::ROOT,
name: ty::BoundTyKind::Anon({
let idx = self.idx;
self.idx += 1;
idx
}),
bound: ty::BoundTy {
var: ty::BoundVar::from_u32(idx),
kind: ty::BoundTyKind::Anon(idx),
},
})
} else {
t.super_fold_with(self)
@ -2153,7 +2157,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
self.tcx.mk_const(
ty::PlaceholderConst {
universe: ty::UniverseIndex::ROOT,
name: ty::BoundVar::from_u32({
bound: ty::BoundVar::from_u32({
let idx = self.idx;
self.idx += 1;
idx

View file

@ -296,7 +296,7 @@ where
universe
});
let placeholder = ty::PlaceholderRegion { universe, name: br.kind };
let placeholder = ty::PlaceholderRegion { universe, bound: br };
debug!(?placeholder);
let placeholder_reg = nll_delegate.next_placeholder_region(placeholder);
debug!(?placeholder_reg);

View file

@ -290,9 +290,9 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
) -> TypeError<'tcx> {
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);
if self.overly_polymorphic {
TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region)
TypeError::RegionsOverlyPolymorphic(placeholder.bound.kind, other_region)
} else {
TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region)
TypeError::RegionsInsufficientlyPolymorphic(placeholder.bound.kind, other_region)
}
}
}