mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
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
|
// Therefore mark `predicates_added` as true and which will ensure
|
||||||
// we walk the crates again and re-calculate predicates for all
|
// we walk the crates again and re-calculate predicates for all
|
||||||
// items.
|
// items.
|
||||||
let item_predicates_len: usize =
|
let item_predicates_len: usize = global_inferred_outlives
|
||||||
global_inferred_outlives.get(&item_did.to_def_id()).map_or(0, |p| p.0.len());
|
.get(&item_did.to_def_id())
|
||||||
|
.map_or(0, |p| p.as_ref().skip_binder().len());
|
||||||
if item_required_predicates.len() > item_predicates_len {
|
if item_required_predicates.len() > item_predicates_len {
|
||||||
predicates_added = true;
|
predicates_added = true;
|
||||||
global_inferred_outlives
|
global_inferred_outlives
|
||||||
@ -137,7 +138,9 @@ fn insert_required_predicates_to_be_wf<'tcx>(
|
|||||||
// 'a` holds for `Foo`.
|
// 'a` holds for `Foo`.
|
||||||
debug!("Adt");
|
debug!("Adt");
|
||||||
if let Some(unsubstituted_predicates) = global_inferred_outlives.get(&def.did()) {
|
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
|
// `unsubstituted_predicate` is `U: 'b` in the
|
||||||
// example above. So apply the substitution to
|
// example above. So apply the substitution to
|
||||||
// get `T: 'a` (or `predicate`):
|
// 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);
|
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);
|
debug!("outlives_predicate = {:?}", &outlives_predicate);
|
||||||
|
|
||||||
// Careful: If we are inferring the effects of a `dyn Trait<..>`
|
// Careful: If we are inferring the effects of a `dyn Trait<..>`
|
||||||
|
@ -98,7 +98,8 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
|||||||
let predicates = global_inferred_outlives
|
let predicates = global_inferred_outlives
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(&def_id, set)| {
|
.map(|(&def_id, set)| {
|
||||||
let predicates = &*tcx.arena.alloc_from_iter(set.0.iter().filter_map(
|
let predicates =
|
||||||
|
&*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map(
|
||||||
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
||||||
match kind1.unpack() {
|
match kind1.unpack() {
|
||||||
GenericArgKind::Type(ty1) => Some((
|
GenericArgKind::Type(ty1) => Some((
|
||||||
@ -106,7 +107,9 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
|||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
GenericArgKind::Lifetime(region1) => Some((
|
GenericArgKind::Lifetime(region1) => Some((
|
||||||
ty::Clause::RegionOutlives(ty::OutlivesPredicate(region1, *region2)),
|
ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||||
|
region1, *region2,
|
||||||
|
)),
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
GenericArgKind::Const(_) => {
|
GenericArgKind::Const(_) => {
|
||||||
|
@ -1386,7 +1386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// the referenced item.
|
// the referenced item.
|
||||||
let ty = tcx.type_of(def_id);
|
let ty = tcx.type_of(def_id);
|
||||||
assert!(!substs.has_escaping_bound_vars());
|
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));
|
let ty_substituted = self.normalize(span, ty.subst(tcx, substs));
|
||||||
|
|
||||||
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
|
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>> {
|
) -> impl Iterator<Item = ty::Region<'tcx>> {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let bounds = tcx.item_bounds(alias_ty.def_id);
|
let bounds = tcx.item_bounds(alias_ty.def_id);
|
||||||
trace!("{:#?}", bounds.0);
|
trace!("{:#?}", bounds.skip_binder());
|
||||||
bounds
|
bounds
|
||||||
.subst_iter(tcx, alias_ty.substs)
|
.subst_iter(tcx, alias_ty.substs)
|
||||||
.filter_map(|p| p.to_opt_type_outlives())
|
.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)),
|
impl_trait_ref.map(|i| i.subst(self.tcx(), substs)),
|
||||||
)
|
)
|
||||||
} else {
|
} 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)
|
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::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,
|
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).
|
/// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
#[derive(Encodable, Decodable, HashStable)]
|
#[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.
|
/// For early binders, you should first call `subst` before using any visitors.
|
||||||
impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {}
|
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));
|
let sig = sig.map_bound(|sig| tcx.erase_late_bound_regions(sig));
|
||||||
|
|
||||||
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
||||||
let mut sig =
|
let mut sig = if let Some(sig_substs) = sig_substs {
|
||||||
if let Some(sig_substs) = sig_substs { sig.subst(tcx, &sig_substs) } else { sig.0 };
|
sig.subst(tcx, &sig_substs)
|
||||||
|
} else {
|
||||||
|
sig.skip_binder()
|
||||||
|
};
|
||||||
|
|
||||||
if let CallKind::Indirect(fnty) = call_kind {
|
if let CallKind::Indirect(fnty) = call_kind {
|
||||||
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This
|
// `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) => {
|
ty::Adt(def, substs) => {
|
||||||
let sized_crit = def.sized_constraint(ecx.tcx());
|
let sized_crit = def.sized_constraint(ecx.tcx());
|
||||||
Ok(sized_crit
|
Ok(sized_crit.subst_iter_copied(ecx.tcx(), substs).collect())
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.map(|ty| sized_crit.rebind(*ty).subst(ecx.tcx(), substs))
|
|
||||||
.collect())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
// consider a "quick reject". This avoids creating more types
|
// consider a "quick reject". This avoids creating more types
|
||||||
// and so forth that we need to.
|
// and so forth that we need to.
|
||||||
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if self.reject_fn_ptr_impls(
|
if self.reject_fn_ptr_impls(
|
||||||
|
@ -527,9 +527,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
substs.extend(trait_predicate.trait_ref.substs.iter());
|
substs.extend(trait_predicate.trait_ref.substs.iter());
|
||||||
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
|
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
|
||||||
smallvec::SmallVec::with_capacity(
|
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
|
InternalSubsts::fill_single(&mut substs, defs, &mut |param, _| match param
|
||||||
.kind
|
.kind
|
||||||
{
|
{
|
||||||
|
@ -2149,13 +2149,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
ty::Adt(def, substs) => {
|
ty::Adt(def, substs) => {
|
||||||
let sized_crit = def.sized_constraint(self.tcx());
|
let sized_crit = def.sized_constraint(self.tcx());
|
||||||
// (*) binder moved here
|
// (*) binder moved here
|
||||||
Where(obligation.predicate.rebind({
|
Where(
|
||||||
sized_crit
|
obligation
|
||||||
.0
|
.predicate
|
||||||
.iter()
|
.rebind(sized_crit.subst_iter_copied(self.tcx(), substs).collect()),
|
||||||
.map(|ty| sized_crit.rebind(*ty).subst(self.tcx(), substs))
|
)
|
||||||
.collect()
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,
|
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 {
|
Arc::new(chalk_solve::rust_ir::FnDefDatum {
|
||||||
id: fn_def_id,
|
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),
|
binders: chalk_ir::Binders::new(binders, bound),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,7 @@ fn sized_constraint_for_ty<'tcx>(
|
|||||||
let adt_tys = adt.sized_constraint(tcx);
|
let adt_tys = adt.sized_constraint(tcx);
|
||||||
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
|
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
|
||||||
adt_tys
|
adt_tys
|
||||||
.0
|
.subst_iter_copied(tcx, substs)
|
||||||
.iter()
|
|
||||||
.map(|ty| adt_tys.rebind(*ty).subst(tcx, substs))
|
|
||||||
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
|
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||||||
let mut impls = Vec::new();
|
let mut impls = Vec::new();
|
||||||
for trait_def_id in cx.tcx.all_traits() {
|
for trait_def_id in cx.tcx.all_traits() {
|
||||||
if !cx.cache.effective_visibilities.is_reachable(cx.tcx, trait_def_id)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||||||
impl_def_id
|
impl_def_id
|
||||||
);
|
);
|
||||||
let trait_ref = cx.tcx.impl_trait_ref(impl_def_id).unwrap();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let infcx = cx.tcx.infer_ctxt().build();
|
||||||
@ -87,7 +87,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||||||
trait_ref, ty
|
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 {
|
impls.push(Item {
|
||||||
name: None,
|
name: None,
|
||||||
@ -104,10 +104,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||||||
// the post-inference `trait_ref`, as it's more accurate.
|
// the post-inference `trait_ref`, as it's more accurate.
|
||||||
trait_: Some(clean_trait_ref_with_bindings(
|
trait_: Some(clean_trait_ref_with_bindings(
|
||||||
cx,
|
cx,
|
||||||
ty::Binder::dummy(trait_ref.0),
|
ty::Binder::dummy(trait_ref.skip_binder()),
|
||||||
ThinVec::new(),
|
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
|
items: cx
|
||||||
.tcx
|
.tcx
|
||||||
.associated_items(impl_def_id)
|
.associated_items(impl_def_id)
|
||||||
@ -116,7 +116,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
polarity: ty::ImplPolarity::Positive,
|
polarity: ty::ImplPolarity::Positive,
|
||||||
kind: ImplKind::Blanket(Box::new(clean_middle_ty(
|
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,
|
cx,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
|
@ -138,7 +138,7 @@ fn collect_unsafe_exprs<'tcx>(
|
|||||||
.type_dependent_def_id(expr.hir_id)
|
.type_dependent_def_id(expr.hir_id)
|
||||||
.map(|def_id| cx.tcx.fn_sig(def_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));
|
unsafe_ops.push(("unsafe method call occurs here", expr.span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user