Make EarlyBinder's inner value private; and fix all of the resulting errors
diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
index e386b1b..ced994a 100644
--- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
+++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
@@ -68,8 +68,9 @@
// 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 @@
// '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 @@
);
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<..>`
diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs
index a8596c7..2106d6f 100644
--- a/compiler/rustc_hir_analysis/src/outlives/mod.rs
+++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs
@@ -98,24 +98,27 @@
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();
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
index 5579503..38ddb7e 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
@@ -1386,7 +1386,7 @@
// 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 {
diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs
index c2bf0f3..59ae2ce 100644
--- a/compiler/rustc_infer/src/infer/outlives/verify.rs
+++ b/compiler/rustc_infer/src/infer/outlives/verify.rs
@@ -293,7 +293,7 @@
) -> 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())
diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs
index 64e7480..2de0a3f 100644
--- a/compiler/rustc_middle/src/ty/print/mod.rs
+++ b/compiler/rustc_middle/src/ty/print/mod.rs
@@ -123,7 +123,7 @@
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)
}
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index 945ef6a..82f79a0 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -2366,7 +2366,7 @@
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,
diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs
index 43450bd..5422ee7 100644
--- a/compiler/rustc_middle/src/ty/subst.rs
+++ b/compiler/rustc_middle/src/ty/subst.rs
@@ -538,7 +538,7 @@
/// [`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> {}
diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs
index fbe6a27..522220f 100644
--- a/compiler/rustc_mir_transform/src/shim.rs
+++ b/compiler/rustc_mir_transform/src/shim.rs
@@ -644,8 +644,11 @@
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
diff --git a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs
index 0ede32c..1071b8f 100644
--- a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs
+++ b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs
@@ -148,11 +148,7 @@
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())
}
}
}
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
index 8bc82b9..3c223db 100644
--- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
@@ -360,7 +360,9 @@
// 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(
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
index 0d9f55d..0245dfd 100644
--- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
@@ -527,9 +527,9 @@
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
{
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index 3baf1c9..ed380f3 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -2149,13 +2149,11 @@
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,
diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs
index c319b2e..1d3ea96 100644
--- a/compiler/rustc_traits/src/chalk/db.rs
+++ b/compiler/rustc_traits/src/chalk/db.rs
@@ -294,7 +294,7 @@
};
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),
})
}
diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs
index 4eb1256..52bc386 100644
--- a/compiler/rustc_ty_utils/src/ty.rs
+++ b/compiler/rustc_ty_utils/src/ty.rs
@@ -44,9 +44,7 @@
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()
}
diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs
index 8e74e6e..7d3ccb9 100644
--- a/src/librustdoc/clean/blanket_impl.rs
+++ b/src/librustdoc/clean/blanket_impl.rs
@@ -21,7 +21,7 @@
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_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 @@
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 @@
// 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 @@
.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,
))),
diff --git a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs
index 2abdfac..e6fd65f 100644
--- a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs
+++ b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs
@@ -138,7 +138,7 @@
.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));
}
}