Skip to content

Commit 2a8a0fc

Browse files
committed
Auto merge of rust-lang#96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L1308). Everything is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk. Either way, tracking when we have or haven't already substituted out these in rustc can be helpful. As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted. r? `@nikomatsakis`
2 parents 70b3681 + 06a1e88 commit 2a8a0fc

File tree

67 files changed

+400
-217
lines changed

Some content is hidden

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

67 files changed

+400
-217
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use rustc_middle::mir::{
1313
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
1414
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
1515
};
16-
use rustc_middle::ty::{self, subst::Subst, suggest_constraining_type_params, PredicateKind, Ty};
16+
use rustc_middle::ty::{
17+
self, subst::Subst, suggest_constraining_type_params, EarlyBinder, PredicateKind, Ty,
18+
};
1719
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
1820
use rustc_span::symbol::sym;
1921
use rustc_span::{BytePos, Span};
@@ -336,7 +338,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
336338
let find_fn_kind_from_did = |predicates: &[(ty::Predicate<'tcx>, Span)], substs| {
337339
predicates.iter().find_map(|(pred, _)| {
338340
let pred = if let Some(substs) = substs {
339-
pred.subst(tcx, substs).kind().skip_binder()
341+
EarlyBinder(*pred).subst(tcx, substs).kind().skip_binder()
340342
} else {
341343
pred.kind().skip_binder()
342344
};

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
477477
.infcx
478478
.tcx
479479
.mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid()));
480-
let va_list_ty =
481-
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
480+
let va_list_ty = self
481+
.infcx
482+
.tcx
483+
.bound_type_of(va_list_did)
484+
.subst(self.infcx.tcx, &[region.into()]);
482485

483486
unnormalized_input_tys = self.infcx.tcx.mk_type_list(
484487
unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)),

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::pretty::display_allocation;
1313
use rustc_middle::traits::Reveal;
1414
use rustc_middle::ty::layout::LayoutOf;
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
16-
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
16+
use rustc_middle::ty::{self, subst::Subst, EarlyBinder, TyCtxt};
1717
use rustc_span::source_map::Span;
1818
use rustc_target::abi::{self, Abi};
1919
use std::borrow::Cow;
@@ -47,7 +47,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4747
"Unexpected DefKind: {:?}",
4848
ecx.tcx.def_kind(cid.instance.def_id())
4949
);
50-
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?;
50+
let layout = ecx.layout_of(EarlyBinder(body.return_ty()).subst(tcx, cid.instance.substs))?;
5151
assert!(!layout.is_unsized());
5252
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
5353

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9595
// Allocate memory for `CallerLocation` struct.
9696
let loc_ty = self
9797
.tcx
98-
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
98+
.bound_type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
9999
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
100100
let loc_layout = self.layout_of(loc_ty).unwrap();
101101
// This can fail if rustc runs out of memory right here. Trying to emit an error would be

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use rustc_middle::ty::{
7070
self,
7171
error::TypeError,
7272
subst::{GenericArgKind, Subst, SubstsRef},
73-
Binder, List, Region, Ty, TyCtxt, TypeFoldable,
73+
Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable,
7474
};
7575
use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span};
7676
use rustc_target::spec::abi;
@@ -961,12 +961,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
961961
for (def_id, actual) in iter::zip(default_params, substs.iter().rev()) {
962962
match actual.unpack() {
963963
GenericArgKind::Const(c) => {
964-
if self.tcx.const_param_default(def_id).subst(self.tcx, substs) != c {
964+
if EarlyBinder(self.tcx.const_param_default(def_id)).subst(self.tcx, substs)
965+
!= c
966+
{
965967
break;
966968
}
967969
}
968970
GenericArgKind::Type(ty) => {
969-
if self.tcx.type_of(def_id).subst(self.tcx, substs) != ty {
971+
if self.tcx.bound_type_of(def_id).subst(self.tcx, substs) != ty {
970972
break;
971973
}
972974
}
@@ -1383,8 +1385,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13831385
}
13841386

13851387
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
1386-
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
1387-
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
1388+
let sig1 = self.tcx.bound_fn_sig(*did1).subst(self.tcx, substs1);
1389+
let sig2 = self.tcx.bound_fn_sig(*did2).subst(self.tcx, substs2);
13881390
let mut values = self.cmp_fn_sig(&sig1, &sig2);
13891391
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did1, substs1));
13901392
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did2, substs2));
@@ -1395,7 +1397,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13951397
}
13961398

13971399
(ty::FnDef(did1, substs1), ty::FnPtr(sig2)) => {
1398-
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
1400+
let sig1 = self.tcx.bound_fn_sig(*did1).subst(self.tcx, substs1);
13991401
let mut values = self.cmp_fn_sig(&sig1, sig2);
14001402
values.0.push_highlighted(format!(
14011403
" {{{}}}",
@@ -1405,7 +1407,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14051407
}
14061408

14071409
(ty::FnPtr(sig1), ty::FnDef(did2, substs2)) => {
1408-
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
1410+
let sig2 = self.tcx.bound_fn_sig(*did2).subst(self.tcx, substs2);
14091411
let mut values = self.cmp_fn_sig(sig1, &sig2);
14101412
values.1.push_normal(format!(
14111413
" {{{}}}",
@@ -1847,9 +1849,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18471849
// Future::Output
18481850
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
18491851

1850-
let bounds = self.tcx.explicit_item_bounds(*def_id);
1852+
let bounds = self.tcx.bound_explicit_item_bounds(*def_id);
18511853

1852-
for (predicate, _) in bounds {
1854+
for predicate in bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) {
18531855
let predicate = predicate.subst(self.tcx, substs);
18541856
let output = predicate
18551857
.kind()

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
561561
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
562562
}
563563

564-
let item_bounds = tcx.explicit_item_bounds(def_id);
564+
let item_bounds = tcx.bound_explicit_item_bounds(def_id);
565565

566-
for (predicate, _) in item_bounds {
566+
for predicate in item_bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) {
567567
debug!(?predicate);
568568
let predicate = predicate.subst(tcx, substs);
569569

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::captures::Captures;
44
use rustc_data_structures::sso::SsoHashSet;
55
use rustc_hir::def_id::DefId;
66
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
7-
use rustc_middle::ty::{self, Ty, TyCtxt};
7+
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
88

99
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
1010
/// obligation into a series of `'a: 'b` constraints and "verifys", as
@@ -290,7 +290,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
290290
debug!("projection_bounds(projection_ty={:?})", projection_ty);
291291
let tcx = self.tcx;
292292
self.region_bounds_declared_on_associated_item(projection_ty.item_def_id)
293-
.map(move |r| r.subst(tcx, projection_ty.substs))
293+
.map(move |r| EarlyBinder(r).subst(tcx, projection_ty.substs))
294294
}
295295

296296
/// Given the `DefId` of an associated item, returns any region

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ impl<'tcx> Operand<'tcx> {
23932393
substs: SubstsRef<'tcx>,
23942394
span: Span,
23952395
) -> Self {
2396-
let ty = tcx.type_of(def_id).subst(tcx, substs);
2396+
let ty = tcx.bound_type_of(def_id).subst(tcx, substs);
23972397
Operand::Constant(Box::new(Constant {
23982398
span,
23992399
user_ty: None,

compiler/rustc_middle/src/mir/tcx.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ impl<'tcx> Rvalue<'tcx> {
202202
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
203203
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
204204
AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))),
205-
AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs),
205+
AggregateKind::Adt(did, _, substs, _, _) => {
206+
tcx.bound_type_of(did).subst(tcx, substs)
207+
}
206208
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
207209
AggregateKind::Generator(did, substs, movability) => {
208210
tcx.mk_generator(did, substs, movability)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ impl<'tcx> TyCtxt<'tcx> {
16031603
pub fn caller_location_ty(self) -> Ty<'tcx> {
16041604
self.mk_imm_ref(
16051605
self.lifetimes.re_static,
1606-
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
1606+
self.bound_type_of(self.require_lang_item(LangItem::PanicLocation, None))
16071607
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
16081608
)
16091609
}
@@ -2332,7 +2332,7 @@ impl<'tcx> TyCtxt<'tcx> {
23322332
ty_param.into()
23332333
} else {
23342334
assert!(has_default);
2335-
self.type_of(param.def_id).subst(self, substs).into()
2335+
self.bound_type_of(param.def_id).subst(self, substs).into()
23362336
}
23372337
}
23382338
});

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
22
use crate::ty;
33
use crate::ty::subst::{Subst, SubstsRef};
4+
use crate::ty::EarlyBinder;
45
use rustc_ast as ast;
56
use rustc_data_structures::fx::FxHashMap;
67
use rustc_hir::def_id::DefId;
@@ -229,7 +230,11 @@ impl<'tcx> GenericPredicates<'tcx> {
229230
substs: SubstsRef<'tcx>,
230231
) -> InstantiatedPredicates<'tcx> {
231232
InstantiatedPredicates {
232-
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(),
233+
predicates: self
234+
.predicates
235+
.iter()
236+
.map(|(p, _)| EarlyBinder(*p).subst(tcx, substs))
237+
.collect(),
233238
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
234239
}
235240
}
@@ -243,7 +248,9 @@ impl<'tcx> GenericPredicates<'tcx> {
243248
if let Some(def_id) = self.parent {
244249
tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
245250
}
246-
instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)));
251+
instantiated
252+
.predicates
253+
.extend(self.predicates.iter().map(|(p, _)| EarlyBinder(*p).subst(tcx, substs)));
247254
instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp));
248255
}
249256

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
22
use crate::ty::print::{FmtPrinter, Printer};
33
use crate::ty::subst::{InternalSubsts, Subst};
4-
use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
4+
use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt, TypeFoldable};
55
use rustc_errors::ErrorGuaranteed;
66
use rustc_hir::def::Namespace;
77
use rustc_hir::def_id::{CrateNum, DefId};
@@ -558,7 +558,11 @@ impl<'tcx> Instance<'tcx> {
558558
where
559559
T: TypeFoldable<'tcx> + Copy,
560560
{
561-
if let Some(substs) = self.substs_for_mir_body() { v.subst(tcx, substs) } else { *v }
561+
if let Some(substs) = self.substs_for_mir_body() {
562+
EarlyBinder(*v).subst(tcx, substs)
563+
} else {
564+
*v
565+
}
562566
}
563567

564568
#[inline(always)]

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
22
use crate::mir::{GeneratorLayout, GeneratorSavedLocal};
33
use crate::ty::normalize_erasing_regions::NormalizationError;
44
use crate::ty::subst::Subst;
5-
use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable};
5+
use crate::ty::{self, subst::SubstsRef, EarlyBinder, ReprOptions, Ty, TyCtxt, TypeFoldable};
66
use rustc_ast as ast;
77
use rustc_attr as attr;
88
use rustc_hir as hir;
@@ -1706,7 +1706,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
17061706
) -> Result<Layout<'tcx>, LayoutError<'tcx>> {
17071707
use SavedLocalEligibility::*;
17081708
let tcx = self.tcx;
1709-
let subst_field = |ty: Ty<'tcx>| ty.subst(tcx, substs);
1709+
let subst_field = |ty: Ty<'tcx>| EarlyBinder(ty).subst(tcx, substs);
17101710

17111711
let Some(info) = tcx.generator_layout(def_id) else {
17121712
return Err(LayoutError::Unknown(ty));
@@ -2750,7 +2750,7 @@ impl<'tcx> ty::Instance<'tcx> {
27502750
// track of a polymorphization `ParamEnv` to allow normalizing later.
27512751
let mut sig = match *ty.kind() {
27522752
ty::FnDef(def_id, substs) => tcx
2753-
.normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id))
2753+
.normalize_erasing_regions(tcx.param_env(def_id), tcx.bound_fn_sig(def_id))
27542754
.subst(tcx, substs),
27552755
_ => unreachable!(),
27562756
};

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub use self::sty::RegionKind::*;
7777
pub use self::sty::TyKind::*;
7878
pub use self::sty::{
7979
Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind,
80-
CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBoundRegion,
80+
CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBinder, EarlyBoundRegion,
8181
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig,
8282
GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, InlineConstSubstsParts, ParamConst,
8383
ParamTy, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig,
@@ -735,7 +735,7 @@ impl<'tcx> Predicate<'tcx> {
735735
let shifted_pred =
736736
tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder());
737737
// 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1>
738-
let new = shifted_pred.subst(tcx, trait_ref.skip_binder().substs);
738+
let new = EarlyBinder(shifted_pred).subst(tcx, trait_ref.skip_binder().substs);
739739
// 3) ['x] + ['b] -> ['x, 'b]
740740
let bound_vars =
741741
tcx.mk_bound_variable_kinds(trait_bound_vars.iter().chain(pred_bound_vars));
@@ -1931,7 +1931,7 @@ impl<'tcx> FieldDef {
19311931
/// Returns the type of this field. The resulting type is not normalized. The `subst` is
19321932
/// typically obtained via the second field of [`TyKind::Adt`].
19331933
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
1934-
tcx.type_of(self.did).subst(tcx, subst)
1934+
tcx.bound_type_of(self.did).subst(tcx, subst)
19351935
}
19361936

19371937
/// Computes the `Ident` of this variant by looking up the `Span`

compiler/rustc_middle/src/ty/normalize_erasing_regions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::mir;
1111
use crate::traits::query::NoSolution;
1212
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder};
1313
use crate::ty::subst::{Subst, SubstsRef};
14-
use crate::ty::{self, Ty, TyCtxt};
14+
use crate::ty::{self, EarlyBinder, Ty, TyCtxt};
1515

1616
#[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)]
1717
pub enum NormalizationError<'tcx> {
@@ -133,7 +133,7 @@ impl<'tcx> TyCtxt<'tcx> {
133133
param_env={:?})",
134134
param_substs, value, param_env,
135135
);
136-
let substituted = value.subst(self, param_substs);
136+
let substituted = EarlyBinder(value).subst(self, param_substs);
137137
self.normalize_erasing_regions(param_env, substituted)
138138
}
139139

@@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
157157
param_env={:?})",
158158
param_substs, value, param_env,
159159
);
160-
let substituted = value.subst(self, param_substs);
160+
let substituted = EarlyBinder(value).subst(self, param_substs);
161161
self.try_normalize_erasing_regions(param_env, substituted)
162162
}
163163
}

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,16 @@ pub trait Printer<'tcx>: Sized {
115115

116116
DefPathData::Impl => {
117117
let generics = self.tcx().generics_of(def_id);
118-
let mut self_ty = self.tcx().type_of(def_id);
119-
let mut impl_trait_ref = self.tcx().impl_trait_ref(def_id);
120-
if substs.len() >= generics.count() {
121-
self_ty = self_ty.subst(self.tcx(), substs);
122-
impl_trait_ref = impl_trait_ref.subst(self.tcx(), substs);
123-
}
118+
let self_ty = self.tcx().bound_type_of(def_id);
119+
let impl_trait_ref = self.tcx().bound_impl_trait_ref(def_id);
120+
let (self_ty, impl_trait_ref) = if substs.len() >= generics.count() {
121+
(
122+
self_ty.subst(self.tcx(), substs),
123+
impl_trait_ref.map(|i| i.subst(self.tcx(), substs)),
124+
)
125+
} else {
126+
(self_ty.0, impl_trait_ref.map(|i| i.0))
127+
};
124128
self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
125129
}
126130

@@ -203,7 +207,7 @@ pub trait Printer<'tcx>: Sized {
203207
has_default
204208
&& substs[param.index as usize]
205209
== GenericArg::from(
206-
self.tcx().type_of(param.def_id).subst(self.tcx(), substs),
210+
self.tcx().bound_type_of(param.def_id).subst(self.tcx(), substs),
207211
)
208212
}
209213
ty::GenericParamDefKind::Const { has_default } => {

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ pub trait PrettyPrinter<'tcx>:
587587
p!(")")
588588
}
589589
ty::FnDef(def_id, substs) => {
590-
let sig = self.tcx().fn_sig(def_id).subst(self.tcx(), substs);
590+
let sig = self.tcx().bound_fn_sig(def_id).subst(self.tcx(), substs);
591591
p!(print(sig), " {{", print_value_path(def_id, substs), "}}");
592592
}
593593
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
@@ -774,13 +774,13 @@ pub trait PrettyPrinter<'tcx>:
774774

775775
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
776776
// by looking up the projections associated with the def_id.
777-
let bounds = self.tcx().explicit_item_bounds(def_id);
777+
let bounds = self.tcx().bound_explicit_item_bounds(def_id);
778778

779779
let mut traits = BTreeMap::new();
780780
let mut fn_traits = BTreeMap::new();
781781
let mut is_sized = false;
782782

783-
for (predicate, _) in bounds {
783+
for predicate in bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) {
784784
let predicate = predicate.subst(self.tcx(), substs);
785785
let bound_predicate = predicate.kind();
786786

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
159159
let params = iter::zip(a_subst, b_subst).enumerate().map(|(i, (a, b))| {
160160
let variance = variances[i];
161161
let variance_info = if variance == ty::Invariant {
162-
let ty = *cached_ty.get_or_insert_with(|| tcx.type_of(ty_def_id).subst(tcx, a_subst));
162+
let ty =
163+
*cached_ty.get_or_insert_with(|| tcx.bound_type_of(ty_def_id).subst(tcx, a_subst));
163164
ty::VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() }
164165
} else {
165166
ty::VarianceDiagInfo::default()

0 commit comments

Comments
 (0)