Skip to content

Commit 1c53407

Browse files
committed
Auto merge of #112006 - kylematsuda:earlybinder-private, r=jackh726
Make `EarlyBinder`'s inner value private Currently, `EarlyBinder(T)`'s inner value is public, which allows implicitly skipping the binder by indexing into the tuple struct (i.e., `x.0`). `@lcnr` suggested making `EarlyBinder`'s inner value private so users are required to explicitly call `skip_binder` (#105779 (comment)) . This PR makes the inner value private, adds `EarlyBinder::new` for constructing a new instance, and replaces uses of `x.0` with `x.skip_binder()` (or similar). It also adds some documentation to `EarlyBinder::skip_binder` explaining how to skip the binder of `&EarlyBinder<T>` to get `&T` now that the inner value is private (since previously we could just do `&x.0`). r? `@lcnr`
2 parents 3fae1b9 + c29c212 commit 1c53407

File tree

56 files changed

+123
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+123
-113
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
361361
self.instance.subst_mir_and_normalize_erasing_regions(
362362
self.tcx,
363363
ty::ParamEnv::reveal_all(),
364-
ty::EarlyBinder(value),
364+
ty::EarlyBinder::new(value),
365365
)
366366
}
367367

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn make_mir_scope<'ll, 'tcx>(
9393
let callee = cx.tcx.subst_and_normalize_erasing_regions(
9494
instance.substs,
9595
ty::ParamEnv::reveal_all(),
96-
ty::EarlyBinder(callee),
96+
ty::EarlyBinder::new(callee),
9797
);
9898
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
9999
cx.dbg_scope_fn(callee, callee_fn_abi, None)

compiler/rustc_codegen_ssa/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
111111
self.instance.subst_mir_and_normalize_erasing_regions(
112112
self.cx.tcx(),
113113
ty::ParamEnv::reveal_all(),
114-
ty::EarlyBinder(value),
114+
ty::EarlyBinder::new(value),
115115
)
116116
}
117117
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
497497
.try_subst_mir_and_normalize_erasing_regions(
498498
*self.tcx,
499499
self.param_env,
500-
ty::EarlyBinder(value),
500+
ty::EarlyBinder::new(value),
501501
)
502502
.map_err(|_| err_inval!(TooGeneric))
503503
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12781278
// params (and trait ref's late bound params). This logic is very similar to
12791279
// `Predicate::subst_supertrait`, and it's no coincidence why.
12801280
let shifted_output = tcx.shift_bound_var_indices(num_bound_vars, output);
1281-
let subst_output = ty::EarlyBinder(shifted_output).subst(tcx, substs);
1281+
let subst_output = ty::EarlyBinder::new(shifted_output).subst(tcx, substs);
12821282

12831283
let bound_vars = tcx.late_bound_vars(binding.hir_id);
12841284
ty::Binder::bind_with_vars(subst_output, bound_vars)

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,14 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
794794
})
795795
});
796796
debug!(%ty);
797-
collected_tys.insert(def_id, ty::EarlyBinder(ty));
797+
collected_tys.insert(def_id, ty::EarlyBinder::new(ty));
798798
}
799799
Err(err) => {
800800
let reported = tcx.sess.delay_span_bug(
801801
return_span,
802802
format!("could not fully resolve: {ty} => {err:?}"),
803803
);
804-
collected_tys.insert(def_id, ty::EarlyBinder(tcx.ty_error(reported)));
804+
collected_tys.insert(def_id, ty::EarlyBinder::new(tcx.ty_error(reported)));
805805
}
806806
}
807807
}

compiler/rustc_hir_analysis/src/check/dropck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
128128
// We don't need to normalize this param-env or anything, since we're only
129129
// substituting it with free params, so no additional param-env normalization
130130
// can occur on top of what has been done in the param_env query itself.
131-
let param_env = ty::EarlyBinder(tcx.param_env(adt_def_id))
131+
let param_env = ty::EarlyBinder::new(tcx.param_env(adt_def_id))
132132
.subst(tcx, adt_to_impl_substs)
133133
.with_constness(tcx.constness(drop_impl_def_id));
134134

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13981398
}
13991399
let mut param_count = CountParams::default();
14001400
let has_region = pred.visit_with(&mut param_count).is_break();
1401-
let substituted_pred = ty::EarlyBinder(pred).subst(tcx, substs);
1401+
let substituted_pred = ty::EarlyBinder::new(pred).subst(tcx, substs);
14021402
// Don't check non-defaulted params, dependent defaults (including lifetimes)
14031403
// or preds with multiple params.
14041404
if substituted_pred.has_non_region_param() || param_count.params.len() > 1 || has_region

compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
11241124
bug!("unexpected sort of node in fn_sig(): {:?}", x);
11251125
}
11261126
};
1127-
ty::EarlyBinder(output)
1127+
ty::EarlyBinder::new(output)
11281128
}
11291129

11301130
fn infer_return_ty_for_fn_sig<'tcx>(
@@ -1312,7 +1312,7 @@ fn impl_trait_ref(
13121312
check_impl_constness(tcx, impl_.constness, ast_trait_ref),
13131313
)
13141314
})
1315-
.map(ty::EarlyBinder)
1315+
.map(ty::EarlyBinder::new)
13161316
}
13171317

13181318
fn check_impl_constness(

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub(super) fn explicit_item_bounds(
8686
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
8787
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
8888
let opaque_ty = item.expect_opaque_ty();
89-
return ty::EarlyBinder(opaque_type_bounds(
89+
return ty::EarlyBinder::new(opaque_type_bounds(
9090
tcx,
9191
opaque_def_id.expect_local(),
9292
opaque_ty.bounds,
@@ -124,7 +124,7 @@ pub(super) fn explicit_item_bounds(
124124
}
125125
_ => bug!("item_bounds called on {:?}", def_id),
126126
};
127-
ty::EarlyBinder(bounds)
127+
ty::EarlyBinder::new(bounds)
128128
}
129129

130130
pub(super) fn item_bounds(

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
323323
return map[&assoc_item.trait_item_def_id.unwrap()];
324324
}
325325
Err(_) => {
326-
return ty::EarlyBinder(tcx.ty_error_with_message(
326+
return ty::EarlyBinder::new(tcx.ty_error_with_message(
327327
DUMMY_SP,
328328
"Could not collect return position impl trait in trait tys",
329329
));
@@ -497,7 +497,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
497497
bug!("unexpected sort of node in type_of(): {:?}", x);
498498
}
499499
};
500-
ty::EarlyBinder(output)
500+
ty::EarlyBinder::new(output)
501501
}
502502

503503
fn infer_placeholder_type<'a>(

compiler/rustc_hir_analysis/src/outlives/explicit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
6868
}
6969
}
7070

71-
ty::EarlyBinder(required_predicates)
71+
ty::EarlyBinder::new(required_predicates)
7272
})
7373
}
7474
}

compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ 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
76-
.insert(item_did.to_def_id(), ty::EarlyBinder(item_required_predicates));
77+
.insert(item_did.to_def_id(), ty::EarlyBinder::new(item_required_predicates));
7778
}
7879
}
7980

@@ -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_metadata/src/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
851851
} else {
852852
tcx.arena.alloc_from_iter(lazy.decode((self, tcx)))
853853
};
854-
ty::EarlyBinder(&*output)
854+
ty::EarlyBinder::new(&*output)
855855
}
856856

857857
fn get_variant(

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17271727
ty::Closure(_, substs) => {
17281728
let constness = self.tcx.constness(def_id.to_def_id());
17291729
self.tables.constness.set_some(def_id.to_def_id().index, constness);
1730-
record!(self.tables.fn_sig[def_id.to_def_id()] <- ty::EarlyBinder(substs.as_closure().sig()));
1730+
record!(self.tables.fn_sig[def_id.to_def_id()] <- ty::EarlyBinder::new(substs.as_closure().sig()));
17311731
}
17321732

17331733
_ => bug!("closure that is neither generator nor closure"),

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'tcx> Body<'tcx> {
476476
/// Returns the return type; it always return first element from `local_decls` array.
477477
#[inline]
478478
pub fn bound_return_ty(&self) -> ty::EarlyBinder<Ty<'tcx>> {
479-
ty::EarlyBinder(self.local_decls[RETURN_PLACE].ty)
479+
ty::EarlyBinder::new(self.local_decls[RETURN_PLACE].ty)
480480
}
481481

482482
/// Gets the location of the terminator for the given block.

compiler/rustc_middle/src/ty/adt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ impl<'tcx> AdtDef<'tcx> {
573573
/// Due to normalization being eager, this applies even if
574574
/// the associated type is behind a pointer (e.g., issue #31299).
575575
pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<&'tcx [Ty<'tcx>]> {
576-
ty::EarlyBinder(tcx.adt_sized_constraint(self.did()))
576+
ty::EarlyBinder::new(tcx.adt_sized_constraint(self.did()))
577577
}
578578
}
579579

compiler/rustc_middle/src/ty/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,5 @@ pub fn const_param_default(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBind
254254
"`const_param_default` expected a generic parameter with a constant"
255255
),
256256
};
257-
ty::EarlyBinder(Const::from_anon_const(tcx, default_def_id))
257+
ty::EarlyBinder::new(Const::from_anon_const(tcx, default_def_id))
258258
}

compiler/rustc_middle/src/ty/generics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<'tcx> GenericPredicates<'tcx> {
343343
substs: SubstsRef<'tcx>,
344344
) -> impl Iterator<Item = (Predicate<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator
345345
{
346-
EarlyBinder(self.predicates).subst_iter_copied(tcx, substs)
346+
EarlyBinder::new(self.predicates).subst_iter_copied(tcx, substs)
347347
}
348348

349349
#[instrument(level = "debug", skip(self, tcx))]
@@ -358,7 +358,7 @@ impl<'tcx> GenericPredicates<'tcx> {
358358
}
359359
instantiated
360360
.predicates
361-
.extend(self.predicates.iter().map(|(p, _)| EarlyBinder(*p).subst(tcx, substs)));
361+
.extend(self.predicates.iter().map(|(p, _)| EarlyBinder::new(*p).subst(tcx, substs)));
362362
instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp));
363363
}
364364

compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
158158
fn subst_opt(self, tcx: TyCtxt<'tcx>, substs: ty::SubstsRef<'tcx>) -> Option<Self> {
159159
match self {
160160
Self::ConstIsZero(c) => {
161-
let c = ty::EarlyBinder(c).subst(tcx, substs);
161+
let c = ty::EarlyBinder::new(c).subst(tcx, substs);
162162
let pred = match c.kind().try_to_target_usize(tcx) {
163163
Some(0) => Self::True,
164164
Some(1..) => Self::False,
@@ -167,7 +167,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
167167
Some(pred)
168168
}
169169
Self::GenericType(t) => {
170-
Some(ty::EarlyBinder(t).subst(tcx, substs).inhabited_predicate(tcx))
170+
Some(ty::EarlyBinder::new(t).subst(tcx, substs).inhabited_predicate(tcx))
171171
}
172172
Self::And(&[a, b]) => match a.subst_opt(tcx, substs) {
173173
None => b.subst_opt(tcx, substs).map(|b| a.and(tcx, b)),

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ impl<'tcx> Predicate<'tcx> {
764764
let shifted_pred =
765765
tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder());
766766
// 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1>
767-
let new = EarlyBinder(shifted_pred).subst(tcx, trait_ref.skip_binder().substs);
767+
let new = EarlyBinder::new(shifted_pred).subst(tcx, trait_ref.skip_binder().substs);
768768
// 3) ['x] + ['b] -> ['x, 'b]
769769
let bound_vars =
770770
tcx.mk_bound_variable_kinds_from_iter(trait_bound_vars.iter().chain(pred_bound_vars));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
568568
let layout = tcx.generator_layout(def_id).unwrap();
569569
layout.variant_fields.iter().map(move |variant| {
570570
variant.iter().map(move |field| {
571-
ty::EarlyBinder(layout.field_tys[*field].ty).subst(tcx, self.substs)
571+
ty::EarlyBinder::new(layout.field_tys[*field].ty).subst(tcx, self.substs)
572572
})
573573
})
574574
}
@@ -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

+8-1
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,17 @@ 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> {}
545545
impl<'tcx, T> !TypeVisitable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {}
546546

547547
impl<T> EarlyBinder<T> {
548+
pub fn new(inner: T) -> EarlyBinder<T> {
549+
EarlyBinder(inner)
550+
}
551+
548552
pub fn as_ref(&self) -> EarlyBinder<&T> {
549553
EarlyBinder(&self.0)
550554
}
@@ -582,6 +586,9 @@ impl<T> EarlyBinder<T> {
582586
/// arguments of an `FnSig`). Otherwise, consider using
583587
/// [`subst_identity`](EarlyBinder::subst_identity).
584588
///
589+
/// To skip the binder on `x: &EarlyBinder<T>` to obtain `&T`, leverage
590+
/// [`EarlyBinder::as_ref`](EarlyBinder::as_ref): `x.as_ref().skip_binder()`.
591+
///
585592
/// See also [`Binder::skip_binder`](super::Binder::skip_binder), which is
586593
/// the analogous operation on [`super::Binder`].
587594
pub fn skip_binder(self) -> T {

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl<'tcx> TyCtxt<'tcx> {
709709
.as_ref()
710710
.map_or_else(|| [].iter(), |l| l.field_tys.iter())
711711
.filter(|decl| !decl.ignore_for_traits)
712-
.map(|decl| ty::EarlyBinder(decl.ty))
712+
.map(|decl| ty::EarlyBinder::new(decl.ty))
713713
}
714714

715715
/// Normalizes all opaque types in the given value, replacing them

0 commit comments

Comments
 (0)