Skip to content

Commit c92248a

Browse files
committed
Add bound_type_of
1 parent 319575a commit c92248a

File tree

30 files changed

+90
-83
lines changed

30 files changed

+90
-83
lines changed

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use rustc_index::vec::{Idx, IndexVec};
2323
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
2424
use rustc_middle::ty::fold::TypeFoldable;
2525
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
26-
use rustc_middle::ty::{
27-
self, EarlyBinder, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt,
28-
};
26+
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
2927
use std::iter;
3028

3129
use crate::nll::ToRegionVid;
@@ -479,7 +477,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
479477
.infcx
480478
.tcx
481479
.mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid()));
482-
let va_list_ty = EarlyBinder(self.infcx.tcx.type_of(va_list_did))
480+
let va_list_ty = self
481+
.infcx
482+
.tcx
483+
.bound_type_of(va_list_did)
483484
.subst(self.infcx.tcx, &[region.into()]);
484485

485486
unnormalized_input_tys = self.infcx.tcx.mk_type_list(

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_hir::lang_items::LangItem;
55
use rustc_middle::mir::TerminatorKind;
66
use rustc_middle::ty::layout::LayoutOf;
77
use rustc_middle::ty::subst::Subst;
8-
use rustc_middle::ty::EarlyBinder;
98
use rustc_span::{Span, Symbol};
109

1110
use crate::interpret::{
@@ -94,10 +93,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9493
let col = if loc_details.column { Scalar::from_u32(col) } else { Scalar::from_u32(0) };
9594

9695
// Allocate memory for `CallerLocation` struct.
97-
let loc_ty = EarlyBinder(
98-
self.tcx.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None)),
99-
)
100-
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
96+
let loc_ty = self
97+
.tcx
98+
.bound_type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
99+
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
101100
let loc_layout = self.layout_of(loc_ty).unwrap();
102101
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
103102
// pointless, since that would require allocating more memory than a Location.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
968968
}
969969
}
970970
GenericArgKind::Type(ty) => {
971-
if EarlyBinder(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 {
972972
break;
973973
}
974974
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
1010
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor};
1111
use crate::ty::print::{FmtPrinter, Printer};
1212
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
13-
use crate::ty::{self, EarlyBinder, List, Ty, TyCtxt};
13+
use crate::ty::{self, List, Ty, TyCtxt};
1414
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
1515

1616
use rustc_errors::ErrorGuaranteed;
@@ -2387,7 +2387,7 @@ impl<'tcx> Operand<'tcx> {
23872387
substs: SubstsRef<'tcx>,
23882388
span: Span,
23892389
) -> Self {
2390-
let ty = EarlyBinder(tcx.type_of(def_id)).subst(tcx, substs);
2390+
let ty = tcx.bound_type_of(def_id).subst(tcx, substs);
23912391
Operand::Constant(Box::new(Constant {
23922392
span,
23932393
user_ty: None,

compiler/rustc_middle/src/mir/tcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use crate::mir::*;
77
use crate::ty::subst::Subst;
8-
use crate::ty::{self, EarlyBinder, Ty, TyCtxt};
8+
use crate::ty::{self, Ty, TyCtxt};
99
use rustc_hir as hir;
1010
use rustc_target::abi::VariantIdx;
1111

@@ -203,7 +203,7 @@ impl<'tcx> Rvalue<'tcx> {
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))),
205205
AggregateKind::Adt(did, _, substs, _, _) => {
206-
EarlyBinder(tcx.type_of(did)).subst(tcx, substs)
206+
tcx.bound_type_of(did).subst(tcx, substs)
207207
}
208208
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
209209
AggregateKind::Generator(did, substs, movability) => {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, Substs
1919
use crate::ty::TyKind::*;
2020
use crate::ty::{
2121
self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
22-
ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, EarlyBinder, ExistentialPredicate,
23-
FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid,
24-
List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy,
25-
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut,
26-
UintTy,
22+
ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, ExistentialPredicate, FloatTy,
23+
FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List,
24+
ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, Region,
25+
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
2726
};
2827
use rustc_ast as ast;
2928
use rustc_data_structures::fingerprint::Fingerprint;
@@ -1605,7 +1604,7 @@ impl<'tcx> TyCtxt<'tcx> {
16051604
pub fn caller_location_ty(self) -> Ty<'tcx> {
16061605
self.mk_imm_ref(
16071606
self.lifetimes.re_static,
1608-
EarlyBinder(self.type_of(self.require_lang_item(LangItem::PanicLocation, None)))
1607+
self.bound_type_of(self.require_lang_item(LangItem::PanicLocation, None))
16091608
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
16101609
)
16111610
}
@@ -2334,7 +2333,7 @@ impl<'tcx> TyCtxt<'tcx> {
23342333
ty_param.into()
23352334
} else {
23362335
assert!(has_default);
2337-
EarlyBinder(self.type_of(param.def_id)).subst(self, substs).into()
2336+
self.bound_type_of(param.def_id).subst(self, substs).into()
23382337
}
23392338
}
23402339
});

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ impl<'tcx> FieldDef {
19321932
/// Returns the type of this field. The resulting type is not normalized. The `subst` is
19331933
/// typically obtained via the second field of [`TyKind::Adt`].
19341934
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
1935-
EarlyBinder(tcx.type_of(self.did)).subst(tcx, subst)
1935+
tcx.bound_type_of(self.did).subst(tcx, subst)
19361936
}
19371937

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

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

Lines changed: 11 additions & 8 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 = EarlyBinder(self_ty).subst(self.tcx(), substs);
122-
impl_trait_ref = EarlyBinder(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().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+
EarlyBinder(impl_trait_ref).subst(self.tcx(), substs),
124+
)
125+
} else {
126+
(self_ty.0, impl_trait_ref)
127+
};
124128
self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
125129
}
126130

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

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::mir::interpret::{get_slice_bytes, ConstValue, GlobalAlloc, Scalar};
88
use crate::ty::error::{ExpectedFound, TypeError};
99
use crate::ty::subst::{GenericArg, GenericArgKind, Subst, SubstsRef};
10-
use crate::ty::{self, EarlyBinder, ImplSubject, Term, Ty, TyCtxt, TypeFoldable};
10+
use crate::ty::{self, ImplSubject, Term, Ty, TyCtxt, TypeFoldable};
1111
use rustc_hir as ast;
1212
use rustc_hir::def_id::DefId;
1313
use rustc_span::DUMMY_SP;
@@ -159,8 +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
163-
.get_or_insert_with(|| EarlyBinder(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));
164164
ty::VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() }
165165
} else {
166166
ty::VarianceDiagInfo::default()

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ impl<'tcx> Ty<'tcx> {
23472347
ty::Str | ty::Slice(_) => (tcx.types.usize, false),
23482348
ty::Dynamic(..) => {
23492349
let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap();
2350-
(EarlyBinder(tcx.type_of(dyn_metadata)).subst(tcx, &[tail.into()]), false)
2350+
(tcx.bound_type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
23512351
},
23522352

23532353
// type parameters only have unit metadata if they're sized, so return true

0 commit comments

Comments
 (0)