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

+7-4
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

+20-17
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+5-2
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

+1-5
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

+3-1
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(

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
527527
substs.extend(trait_predicate.trait_ref.substs.iter());
528528
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
529529
smallvec::SmallVec::with_capacity(
530-
bound.0.kind().bound_vars().len() + defs.count(),
530+
bound.skip_binder().kind().bound_vars().len() + defs.count(),
531531
);
532-
bound_vars.extend(bound.0.kind().bound_vars().into_iter());
532+
bound_vars.extend(bound.skip_binder().kind().bound_vars().into_iter());
533533
InternalSubsts::fill_single(&mut substs, defs, &mut |param, _| match param
534534
.kind
535535
{

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -2149,13 +2149,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21492149
ty::Adt(def, substs) => {
21502150
let sized_crit = def.sized_constraint(self.tcx());
21512151
// (*) binder moved here
2152-
Where(obligation.predicate.rebind({
2153-
sized_crit
2154-
.0
2155-
.iter()
2156-
.map(|ty| sized_crit.rebind(*ty).subst(self.tcx(), substs))
2157-
.collect()
2158-
}))
2152+
Where(
2153+
obligation
2154+
.predicate
2155+
.rebind(sized_crit.subst_iter_copied(self.tcx(), substs).collect()),
2156+
)
21592157
}
21602158

21612159
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,

compiler/rustc_traits/src/chalk/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
294294
};
295295
Arc::new(chalk_solve::rust_ir::FnDefDatum {
296296
id: fn_def_id,
297-
sig: sig.0.lower_into(self.interner),
297+
sig: sig.skip_binder().lower_into(self.interner),
298298
binders: chalk_ir::Binders::new(binders, bound),
299299
})
300300
}

compiler/rustc_ty_utils/src/ty.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ fn sized_constraint_for_ty<'tcx>(
4444
let adt_tys = adt.sized_constraint(tcx);
4545
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
4646
adt_tys
47-
.0
48-
.iter()
49-
.map(|ty| adt_tys.rebind(*ty).subst(tcx, substs))
47+
.subst_iter_copied(tcx, substs)
5048
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
5149
.collect()
5250
}

src/librustdoc/clean/blanket_impl.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
2121
let mut impls = Vec::new();
2222
for trait_def_id in cx.tcx.all_traits() {
2323
if !cx.cache.effective_visibilities.is_reachable(cx.tcx, trait_def_id)
24-
|| cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
24+
|| cx.generated_synthetics.get(&(ty.skip_binder(), trait_def_id)).is_some()
2525
{
2626
continue;
2727
}
@@ -34,7 +34,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
3434
impl_def_id
3535
);
3636
let trait_ref = cx.tcx.impl_trait_ref(impl_def_id).unwrap();
37-
if !matches!(trait_ref.0.self_ty().kind(), ty::Param(_)) {
37+
if !matches!(trait_ref.skip_binder().self_ty().kind(), ty::Param(_)) {
3838
continue;
3939
}
4040
let infcx = cx.tcx.infer_ctxt().build();
@@ -87,7 +87,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
8787
trait_ref, ty
8888
);
8989

90-
cx.generated_synthetics.insert((ty.0, trait_def_id));
90+
cx.generated_synthetics.insert((ty.skip_binder(), trait_def_id));
9191

9292
impls.push(Item {
9393
name: None,
@@ -104,10 +104,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
104104
// the post-inference `trait_ref`, as it's more accurate.
105105
trait_: Some(clean_trait_ref_with_bindings(
106106
cx,
107-
ty::Binder::dummy(trait_ref.0),
107+
ty::Binder::dummy(trait_ref.skip_binder()),
108108
ThinVec::new(),
109109
)),
110-
for_: clean_middle_ty(ty::Binder::dummy(ty.0), cx, None),
110+
for_: clean_middle_ty(ty::Binder::dummy(ty.skip_binder()), cx, None),
111111
items: cx
112112
.tcx
113113
.associated_items(impl_def_id)
@@ -116,7 +116,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
116116
.collect::<Vec<_>>(),
117117
polarity: ty::ImplPolarity::Positive,
118118
kind: ImplKind::Blanket(Box::new(clean_middle_ty(
119-
ty::Binder::dummy(trait_ref.0.self_ty()),
119+
ty::Binder::dummy(trait_ref.skip_binder().self_ty()),
120120
cx,
121121
None,
122122
))),

src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn collect_unsafe_exprs<'tcx>(
138138
.type_dependent_def_id(expr.hir_id)
139139
.map(|def_id| cx.tcx.fn_sig(def_id))
140140
{
141-
if sig.0.unsafety() == Unsafety::Unsafe {
141+
if sig.skip_binder().unsafety() == Unsafety::Unsafe {
142142
unsafe_ops.push(("unsafe method call occurs here", expr.span));
143143
}
144144
}

0 commit comments

Comments
 (0)