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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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(

0 commit comments

Comments
 (0)