Make EarlyBinder's inner value private; and fix all of the resulting errors
This commit is contained in:
parent
03534ac8b7
commit
c40e9cc7ca
@ -68,8 +68,9 @@ pub(super) fn infer_predicates(
|
||||
// Therefore mark `predicates_added` as true and which will ensure
|
||||
// we walk the crates again and re-calculate predicates for all
|
||||
// items.
|
||||
let item_predicates_len: usize =
|
||||
global_inferred_outlives.get(&item_did.to_def_id()).map_or(0, |p| p.0.len());
|
||||
let item_predicates_len: usize = global_inferred_outlives
|
||||
.get(&item_did.to_def_id())
|
||||
.map_or(0, |p| p.as_ref().skip_binder().len());
|
||||
if item_required_predicates.len() > item_predicates_len {
|
||||
predicates_added = true;
|
||||
global_inferred_outlives
|
||||
@ -137,7 +138,9 @@ fn insert_required_predicates_to_be_wf<'tcx>(
|
||||
// 'a` holds for `Foo`.
|
||||
debug!("Adt");
|
||||
if let Some(unsubstituted_predicates) = global_inferred_outlives.get(&def.did()) {
|
||||
for (unsubstituted_predicate, &span) in &unsubstituted_predicates.0 {
|
||||
for (unsubstituted_predicate, &span) in
|
||||
unsubstituted_predicates.as_ref().skip_binder()
|
||||
{
|
||||
// `unsubstituted_predicate` is `U: 'b` in the
|
||||
// example above. So apply the substitution to
|
||||
// get `T: 'a` (or `predicate`):
|
||||
@ -251,7 +254,7 @@ fn check_explicit_predicates<'tcx>(
|
||||
);
|
||||
let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id);
|
||||
|
||||
for (outlives_predicate, &span) in &explicit_predicates.0 {
|
||||
for (outlives_predicate, &span) in explicit_predicates.as_ref().skip_binder() {
|
||||
debug!("outlives_predicate = {:?}", &outlives_predicate);
|
||||
|
||||
// Careful: If we are inferring the effects of a `dyn Trait<..>`
|
||||
|
@ -98,24 +98,27 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
||||
let predicates = global_inferred_outlives
|
||||
.iter()
|
||||
.map(|(&def_id, set)| {
|
||||
let predicates = &*tcx.arena.alloc_from_iter(set.0.iter().filter_map(
|
||||
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
||||
match kind1.unpack() {
|
||||
GenericArgKind::Type(ty1) => Some((
|
||||
ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Lifetime(region1) => Some((
|
||||
ty::Clause::RegionOutlives(ty::OutlivesPredicate(region1, *region2)),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Const(_) => {
|
||||
// Generic consts don't impose any constraints.
|
||||
None
|
||||
let predicates =
|
||||
&*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map(
|
||||
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
||||
match kind1.unpack() {
|
||||
GenericArgKind::Type(ty1) => Some((
|
||||
ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Lifetime(region1) => Some((
|
||||
ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||
region1, *region2,
|
||||
)),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Const(_) => {
|
||||
// Generic consts don't impose any constraints.
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
));
|
||||
},
|
||||
));
|
||||
(def_id, predicates)
|
||||
})
|
||||
.collect();
|
||||
|
@ -1386,7 +1386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// the referenced item.
|
||||
let ty = tcx.type_of(def_id);
|
||||
assert!(!substs.has_escaping_bound_vars());
|
||||
assert!(!ty.0.has_escaping_bound_vars());
|
||||
assert!(!ty.skip_binder().has_escaping_bound_vars());
|
||||
let ty_substituted = self.normalize(span, ty.subst(tcx, substs));
|
||||
|
||||
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
|
||||
|
@ -293,7 +293,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
||||
) -> impl Iterator<Item = ty::Region<'tcx>> {
|
||||
let tcx = self.tcx;
|
||||
let bounds = tcx.item_bounds(alias_ty.def_id);
|
||||
trace!("{:#?}", bounds.0);
|
||||
trace!("{:#?}", bounds.skip_binder());
|
||||
bounds
|
||||
.subst_iter(tcx, alias_ty.substs)
|
||||
.filter_map(|p| p.to_opt_type_outlives())
|
||||
|
@ -123,7 +123,7 @@ pub trait Printer<'tcx>: Sized {
|
||||
impl_trait_ref.map(|i| i.subst(self.tcx(), substs)),
|
||||
)
|
||||
} else {
|
||||
(self_ty.0, impl_trait_ref.map(|i| i.0))
|
||||
(self_ty.subst_identity(), impl_trait_ref.map(|i| i.subst_identity()))
|
||||
};
|
||||
self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
|
||||
}
|
||||
|
@ -2366,7 +2366,7 @@ impl<'tcx> Ty<'tcx> {
|
||||
|
||||
ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)),
|
||||
|
||||
ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(),
|
||||
ty::Adt(def, _substs) => def.sized_constraint(tcx).skip_binder().is_empty(),
|
||||
|
||||
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
|
||||
|
||||
|
@ -538,7 +538,7 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx
|
||||
/// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Encodable, Decodable, HashStable)]
|
||||
pub struct EarlyBinder<T>(pub T);
|
||||
pub struct EarlyBinder<T>(T);
|
||||
|
||||
/// For early binders, you should first call `subst` before using any visitors.
|
||||
impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {}
|
||||
|
@ -644,8 +644,11 @@ fn build_call_shim<'tcx>(
|
||||
let sig = sig.map_bound(|sig| tcx.erase_late_bound_regions(sig));
|
||||
|
||||
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
||||
let mut sig =
|
||||
if let Some(sig_substs) = sig_substs { sig.subst(tcx, &sig_substs) } else { sig.0 };
|
||||
let mut sig = if let Some(sig_substs) = sig_substs {
|
||||
sig.subst(tcx, &sig_substs)
|
||||
} else {
|
||||
sig.skip_binder()
|
||||
};
|
||||
|
||||
if let CallKind::Indirect(fnty) = call_kind {
|
||||
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This
|
||||
|
@ -148,11 +148,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
|
||||
|
||||
ty::Adt(def, substs) => {
|
||||
let sized_crit = def.sized_constraint(ecx.tcx());
|
||||
Ok(sized_crit
|
||||
.0
|
||||
.iter()
|
||||
.map(|ty| sized_crit.rebind(*ty).subst(ecx.tcx(), substs))
|
||||
.collect())
|
||||
Ok(sized_crit.subst_iter_copied(ecx.tcx(), substs).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// consider a "quick reject". This avoids creating more types
|
||||
// and so forth that we need to.
|
||||
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
|
||||
if !drcx.substs_refs_may_unify(obligation_substs, impl_trait_ref.0.substs) {
|
||||
if !drcx
|
||||
.substs_refs_may_unify(obligation_substs, impl_trait_ref.skip_binder().substs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if self.reject_fn_ptr_impls(
|
||||
|
@ -527,9 +527,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
substs.extend(trait_predicate.trait_ref.substs.iter());
|
||||
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
|
||||
smallvec::SmallVec::with_capacity(
|
||||
bound.0.kind().bound_vars().len() + defs.count(),
|
||||
bound.skip_binder().kind().bound_vars().len() + defs.count(),
|
||||
);
|
||||
bound_vars.extend(bound.0.kind().bound_vars().into_iter());
|
||||
bound_vars.extend(bound.skip_binder().kind().bound_vars().into_iter());
|
||||
InternalSubsts::fill_single(&mut substs, defs, &mut |param, _| match param
|
||||
.kind
|
||||
{
|
||||
|
@ -2149,13 +2149,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||
ty::Adt(def, substs) => {
|
||||
let sized_crit = def.sized_constraint(self.tcx());
|
||||
// (*) binder moved here
|
||||
Where(obligation.predicate.rebind({
|
||||
sized_crit
|
||||
.0
|
||||
.iter()
|
||||
.map(|ty| sized_crit.rebind(*ty).subst(self.tcx(), substs))
|
||||
.collect()
|
||||
}))
|
||||
Where(
|
||||
obligation
|
||||
.predicate
|
||||
.rebind(sized_crit.subst_iter_copied(self.tcx(), substs).collect()),
|
||||
)
|
||||
}
|
||||
|
||||
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,
|
||||
|
@ -294,7 +294,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||
};
|
||||
Arc::new(chalk_solve::rust_ir::FnDefDatum {
|
||||
id: fn_def_id,
|
||||
sig: sig.0.lower_into(self.interner),
|
||||
sig: sig.skip_binder().lower_into(self.interner),
|
||||
binders: chalk_ir::Binders::new(binders, bound),
|
||||
})
|
||||
}
|
||||
|
@ -44,9 +44,7 @@ fn sized_constraint_for_ty<'tcx>(
|
||||
let adt_tys = adt.sized_constraint(tcx);
|
||||
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
|
||||
adt_tys
|
||||
.0
|
||||
.iter()
|
||||
.map(|ty| adt_tys.rebind(*ty).subst(tcx, substs))
|
||||
.subst_iter_copied(tcx, substs)
|
||||
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
|
||||
.collect()
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||
let mut impls = Vec::new();
|
||||
for trait_def_id in cx.tcx.all_traits() {
|
||||
if !cx.cache.effective_visibilities.is_reachable(cx.tcx, trait_def_id)
|
||||
|| cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
|
||||
|| cx.generated_synthetics.get(&(ty.skip_binder(), trait_def_id)).is_some()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -34,7 +34,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||
impl_def_id
|
||||
);
|
||||
let trait_ref = cx.tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
if !matches!(trait_ref.0.self_ty().kind(), ty::Param(_)) {
|
||||
if !matches!(trait_ref.skip_binder().self_ty().kind(), ty::Param(_)) {
|
||||
continue;
|
||||
}
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
@ -87,7 +87,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||
trait_ref, ty
|
||||
);
|
||||
|
||||
cx.generated_synthetics.insert((ty.0, trait_def_id));
|
||||
cx.generated_synthetics.insert((ty.skip_binder(), trait_def_id));
|
||||
|
||||
impls.push(Item {
|
||||
name: None,
|
||||
@ -104,10 +104,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||
// the post-inference `trait_ref`, as it's more accurate.
|
||||
trait_: Some(clean_trait_ref_with_bindings(
|
||||
cx,
|
||||
ty::Binder::dummy(trait_ref.0),
|
||||
ty::Binder::dummy(trait_ref.skip_binder()),
|
||||
ThinVec::new(),
|
||||
)),
|
||||
for_: clean_middle_ty(ty::Binder::dummy(ty.0), cx, None),
|
||||
for_: clean_middle_ty(ty::Binder::dummy(ty.skip_binder()), cx, None),
|
||||
items: cx
|
||||
.tcx
|
||||
.associated_items(impl_def_id)
|
||||
@ -116,7 +116,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||
.collect::<Vec<_>>(),
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
kind: ImplKind::Blanket(Box::new(clean_middle_ty(
|
||||
ty::Binder::dummy(trait_ref.0.self_ty()),
|
||||
ty::Binder::dummy(trait_ref.skip_binder().self_ty()),
|
||||
cx,
|
||||
None,
|
||||
))),
|
||||
|
@ -138,7 +138,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||
.type_dependent_def_id(expr.hir_id)
|
||||
.map(|def_id| cx.tcx.fn_sig(def_id))
|
||||
{
|
||||
if sig.0.unsafety() == Unsafety::Unsafe {
|
||||
if sig.skip_binder().unsafety() == Unsafety::Unsafe {
|
||||
unsafe_ops.push(("unsafe method call occurs here", expr.span));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user