Skip to content

Commit b8f9cb3

Browse files
committed
Auto merge of rust-lang#106696 - kylematsuda:early-binder, r=lcnr
Switch to `EarlyBinder` for `const_param_default` and `impl_trait_ref` queries Part of the work to close rust-lang#105779 and implement rust-lang/types-team#78. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This PR adds `EarlyBinder` to the return type of `const_param_default` and `impl_trait_ref`, and removes their `bound_X` variants. r? `@lcnr`
2 parents 4b51adf + 6e969ea commit b8f9cb3

File tree

55 files changed

+145
-112
lines changed

Some content is hidden

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

55 files changed

+145
-112
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
511511
return tcx.const_error(ty).into();
512512
}
513513
if !infer_args && has_default {
514-
tcx.bound_const_param_default(param.def_id)
515-
.subst(tcx, substs.unwrap())
516-
.into()
514+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
517515
} else {
518516
if infer_args {
519517
self.astconv.ct_infer(ty, Some(param), self.span).into()
@@ -2068,7 +2066,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20682066
};
20692067

20702068
self.one_bound_for_assoc_type(
2071-
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref)),
2069+
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
20722070
|| "Self".to_string(),
20732071
assoc_ident,
20742072
span,
@@ -2157,7 +2155,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21572155
.is_accessible_from(self.item_def_id(), tcx)
21582156
&& tcx.all_impls(*trait_def_id)
21592157
.any(|impl_def_id| {
2160-
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id);
2158+
let trait_ref = tcx.impl_trait_ref(impl_def_id);
21612159
trait_ref.map_or(false, |trait_ref| {
21622160
let impl_ = trait_ref.subst(
21632161
tcx,
@@ -2310,7 +2308,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
23102308
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative
23112309
})
23122310
.filter_map(|impl_def_id| tcx.impl_trait_ref(impl_def_id))
2313-
.map(|impl_| impl_.self_ty())
2311+
.map(|impl_| impl_.subst_identity().self_ty())
23142312
// We don't care about blanket impls.
23152313
.filter(|self_ty| !self_ty.has_non_region_param())
23162314
.map(|self_ty| tcx.erase_regions(self_ty).to_string())

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
540540
tcx,
541541
it.span,
542542
it.owner_id.def_id,
543-
impl_trait_ref,
543+
impl_trait_ref.subst_identity(),
544544
&impl_.items,
545545
);
546546
check_on_unimplemented(tcx, it);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
616616
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
617617
let impl_m = tcx.opt_associated_item(def_id).unwrap();
618618
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
619-
let impl_trait_ref = tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap();
619+
let impl_trait_ref =
620+
tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity();
620621
let param_env = tcx.param_env(def_id);
621622

622623
// First, check a few of the same things as `compare_impl_method`,
@@ -1684,7 +1685,8 @@ pub(super) fn compare_impl_const_raw(
16841685
) -> Result<(), ErrorGuaranteed> {
16851686
let impl_const_item = tcx.associated_item(impl_const_item_def);
16861687
let trait_const_item = tcx.associated_item(trait_const_item_def);
1687-
let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap();
1688+
let impl_trait_ref =
1689+
tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap().subst_identity();
16881690
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
16891691

16901692
let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
182182
hir::ItemKind::Impl(ref impl_) => {
183183
let is_auto = tcx
184184
.impl_trait_ref(def_id)
185-
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
185+
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
186186
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
187187
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
188188
let mut err =
@@ -1253,7 +1253,7 @@ fn check_impl<'tcx>(
12531253
// `#[rustc_reservation_impl]` impls are not real impls and
12541254
// therefore don't need to be WF (the trait's `Self: Trait` predicate
12551255
// won't hold).
1256-
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap();
1256+
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().subst_identity();
12571257
let trait_ref = wfcx.normalize(
12581258
ast_trait_ref.path.span,
12591259
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
@@ -1350,7 +1350,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13501350
// is incorrect when dealing with unused substs, for example
13511351
// for `struct Foo<const N: usize, const M: usize = { 1 - 2 }>`
13521352
// we should eagerly error.
1353-
let default_ct = tcx.const_param_default(param.def_id);
1353+
let default_ct = tcx.const_param_default(param.def_id).subst_identity();
13541354
if !default_ct.needs_subst() {
13551355
wfcx.register_wf_obligation(
13561356
tcx.def_span(param.def_id),
@@ -1396,7 +1396,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13961396
GenericParamDefKind::Const { .. } => {
13971397
// If the param has a default, ...
13981398
if is_our_default(param) {
1399-
let default_ct = tcx.const_param_default(param.def_id);
1399+
let default_ct = tcx.const_param_default(param.def_id).subst_identity();
14001400
// ... and it's not a dependent default, ...
14011401
if !default_ct.needs_subst() {
14021402
// ... then substitute it with the default.

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
192192
let source = tcx.type_of(impl_did);
193193
assert!(!source.has_escaping_bound_vars());
194194
let target = {
195-
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
195+
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();
196196
assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait);
197197

198198
trait_ref.substs.type_at(1)
@@ -354,7 +354,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
354354
});
355355

356356
let source = tcx.type_of(impl_did);
357-
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
357+
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();
358358
assert_eq!(trait_ref.def_id, coerce_unsized_trait);
359359
let target = trait_ref.substs.type_at(1);
360360
debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", source, target);

compiler/rustc_hir_analysis/src/coherence/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
128128

129129
let impls = tcx.hir().trait_impls(def_id);
130130
for &impl_def_id in impls {
131-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
131+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
132132

133133
check_impl(tcx, impl_def_id, trait_ref);
134134
check_object_overlap(tcx, impl_def_id, trait_ref);

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl(
2121
tcx: TyCtxt<'_>,
2222
impl_def_id: LocalDefId,
2323
) -> Result<(), ErrorGuaranteed> {
24-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
24+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
2525
trait_ref.error_reported()?;
2626

2727
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1414
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() };
1515

1616
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
17+
let trait_ref = trait_ref.subst_identity();
1718
let trait_def = tcx.trait_def(trait_ref.def_id);
1819
let unsafe_attr =
1920
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,18 +1339,22 @@ fn suggest_impl_trait<'tcx>(
13391339
None
13401340
}
13411341

1342-
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::TraitRef<'_>> {
1342+
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
13431343
let icx = ItemCtxt::new(tcx, def_id);
13441344
let item = tcx.hir().expect_item(def_id.expect_local());
13451345
match item.kind {
1346-
hir::ItemKind::Impl(ref impl_) => impl_.of_trait.as_ref().map(|ast_trait_ref| {
1347-
let selfty = tcx.type_of(def_id);
1348-
icx.astconv().instantiate_mono_trait_ref(
1349-
ast_trait_ref,
1350-
selfty,
1351-
check_impl_constness(tcx, impl_.constness, ast_trait_ref),
1352-
)
1353-
}),
1346+
hir::ItemKind::Impl(ref impl_) => impl_
1347+
.of_trait
1348+
.as_ref()
1349+
.map(|ast_trait_ref| {
1350+
let selfty = tcx.type_of(def_id);
1351+
icx.astconv().instantiate_mono_trait_ref(
1352+
ast_trait_ref,
1353+
selfty,
1354+
check_impl_constness(tcx, impl_.constness, ast_trait_ref),
1355+
)
1356+
})
1357+
.map(ty::EarlyBinder),
13541358
_ => bug!(),
13551359
}
13561360
}

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
8787
Node::Item(item) => match item.kind {
8888
ItemKind::Impl(ref impl_) => {
8989
if impl_.defaultness.is_default() {
90-
is_default_impl_trait = tcx.impl_trait_ref(def_id).map(ty::Binder::dummy);
90+
is_default_impl_trait =
91+
tcx.impl_trait_ref(def_id).map(|t| ty::Binder::dummy(t.subst_identity()));
9192
}
9293
&impl_.generics
9394
}
@@ -251,7 +252,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
251252
// for details.
252253
if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
253254
let self_ty = tcx.type_of(def_id);
254-
let trait_ref = tcx.impl_trait_ref(def_id);
255+
let trait_ref = tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity);
255256
cgp::setup_constraining_predicates(
256257
tcx,
257258
&mut predicates,

0 commit comments

Comments
 (0)