Skip to content

Commit c40e9cc

Browse files
committed
Make EarlyBinder's inner value private; and fix all of the resulting errors
1 parent 03534ac commit c40e9cc

File tree

16 files changed

+57
-54
lines changed

16 files changed

+57
-54
lines changed

compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ pub(super) fn infer_predicates(
6868
// Therefore mark `predicates_added` as true and which will ensure
6969
// we walk the crates again and re-calculate predicates for all
7070
// items.
71-
let item_predicates_len: usize =
72-
global_inferred_outlives.get(&item_did.to_def_id()).map_or(0, |p| p.0.len());
71+
let item_predicates_len: usize = global_inferred_outlives
72+
.get(&item_did.to_def_id())
73+
.map_or(0, |p| p.as_ref().skip_binder().len());
7374
if item_required_predicates.len() > item_predicates_len {
7475
predicates_added = true;
7576
global_inferred_outlives
@@ -137,7 +138,9 @@ fn insert_required_predicates_to_be_wf<'tcx>(
137138
// 'a` holds for `Foo`.
138139
debug!("Adt");
139140
if let Some(unsubstituted_predicates) = global_inferred_outlives.get(&def.did()) {
140-
for (unsubstituted_predicate, &span) in &unsubstituted_predicates.0 {
141+
for (unsubstituted_predicate, &span) in
142+
unsubstituted_predicates.as_ref().skip_binder()
143+
{
141144
// `unsubstituted_predicate` is `U: 'b` in the
142145
// example above. So apply the substitution to
143146
// get `T: 'a` (or `predicate`):
@@ -251,7 +254,7 @@ fn check_explicit_predicates<'tcx>(
251254
);
252255
let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id);
253256

254-
for (outlives_predicate, &span) in &explicit_predicates.0 {
257+
for (outlives_predicate, &span) in explicit_predicates.as_ref().skip_binder() {
255258
debug!("outlives_predicate = {:?}", &outlives_predicate);
256259

257260
// Careful: If we are inferring the effects of a `dyn Trait<..>`

compiler/rustc_hir_analysis/src/outlives/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,27 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
9898
let predicates = global_inferred_outlives
9999
.iter()
100100
.map(|(&def_id, set)| {
101-
let predicates = &*tcx.arena.alloc_from_iter(set.0.iter().filter_map(
102-
|(ty::OutlivesPredicate(kind1, region2), &span)| {
103-
match kind1.unpack() {
104-
GenericArgKind::Type(ty1) => Some((
105-
ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)),
106-
span,
107-
)),
108-
GenericArgKind::Lifetime(region1) => Some((
109-
ty::Clause::RegionOutlives(ty::OutlivesPredicate(region1, *region2)),
110-
span,
111-
)),
112-
GenericArgKind::Const(_) => {
113-
// Generic consts don't impose any constraints.
114-
None
101+
let predicates =
102+
&*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map(
103+
|(ty::OutlivesPredicate(kind1, region2), &span)| {
104+
match kind1.unpack() {
105+
GenericArgKind::Type(ty1) => Some((
106+
ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)),
107+
span,
108+
)),
109+
GenericArgKind::Lifetime(region1) => Some((
110+
ty::Clause::RegionOutlives(ty::OutlivesPredicate(
111+
region1, *region2,
112+
)),
113+
span,
114+
)),
115+
GenericArgKind::Const(_) => {
116+
// Generic consts don't impose any constraints.
117+
None
118+
}
115119
}
116-
}
117-
},
118-
));
120+
},
121+
));
119122
(def_id, predicates)
120123
})
121124
.collect();

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13861386
// the referenced item.
13871387
let ty = tcx.type_of(def_id);
13881388
assert!(!substs.has_escaping_bound_vars());
1389-
assert!(!ty.0.has_escaping_bound_vars());
1389+
assert!(!ty.skip_binder().has_escaping_bound_vars());
13901390
let ty_substituted = self.normalize(span, ty.subst(tcx, substs));
13911391

13921392
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
293293
) -> impl Iterator<Item = ty::Region<'tcx>> {
294294
let tcx = self.tcx;
295295
let bounds = tcx.item_bounds(alias_ty.def_id);
296-
trace!("{:#?}", bounds.0);
296+
trace!("{:#?}", bounds.skip_binder());
297297
bounds
298298
.subst_iter(tcx, alias_ty.substs)
299299
.filter_map(|p| p.to_opt_type_outlives())

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait Printer<'tcx>: Sized {
123123
impl_trait_ref.map(|i| i.subst(self.tcx(), substs)),
124124
)
125125
} else {
126-
(self_ty.0, impl_trait_ref.map(|i| i.0))
126+
(self_ty.subst_identity(), impl_trait_ref.map(|i| i.subst_identity()))
127127
};
128128
self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
129129
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ impl<'tcx> Ty<'tcx> {
23662366

23672367
ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)),
23682368

2369-
ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(),
2369+
ty::Adt(def, _substs) => def.sized_constraint(tcx).skip_binder().is_empty(),
23702370

23712371
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
23722372

compiler/rustc_middle/src/ty/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx
538538
/// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
539539
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
540540
#[derive(Encodable, Decodable, HashStable)]
541-
pub struct EarlyBinder<T>(pub T);
541+
pub struct EarlyBinder<T>(T);
542542

543543
/// For early binders, you should first call `subst` before using any visitors.
544544
impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {}

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,11 @@ fn build_call_shim<'tcx>(
644644
let sig = sig.map_bound(|sig| tcx.erase_late_bound_regions(sig));
645645

646646
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
647-
let mut sig =
648-
if let Some(sig_substs) = sig_substs { sig.subst(tcx, &sig_substs) } else { sig.0 };
647+
let mut sig = if let Some(sig_substs) = sig_substs {
648+
sig.subst(tcx, &sig_substs)
649+
} else {
650+
sig.skip_binder()
651+
};
649652

650653
if let CallKind::Indirect(fnty) = call_kind {
651654
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
148148

149149
ty::Adt(def, substs) => {
150150
let sized_crit = def.sized_constraint(ecx.tcx());
151-
Ok(sized_crit
152-
.0
153-
.iter()
154-
.map(|ty| sized_crit.rebind(*ty).subst(ecx.tcx(), substs))
155-
.collect())
151+
Ok(sized_crit.subst_iter_copied(ecx.tcx(), substs).collect())
156152
}
157153
}
158154
}

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
360360
// consider a "quick reject". This avoids creating more types
361361
// and so forth that we need to.
362362
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
363-
if !drcx.substs_refs_may_unify(obligation_substs, impl_trait_ref.0.substs) {
363+
if !drcx
364+
.substs_refs_may_unify(obligation_substs, impl_trait_ref.skip_binder().substs)
365+
{
364366
return;
365367
}
366368
if self.reject_fn_ptr_impls(

0 commit comments

Comments
 (0)