Skip to content

Commit d822b97

Browse files
committed
change usages of type_of to bound_type_of
1 parent 9a7cc6c commit d822b97

File tree

136 files changed

+385
-262
lines changed

Some content is hidden

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

136 files changed

+385
-262
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
25922592
if is_closure {
25932593
None
25942594
} else {
2595-
let ty = self.infcx.tcx.type_of(self.mir_def_id());
2595+
let ty = self.infcx.tcx.bound_type_of(self.mir_def_id()).subst_identity();
25962596
match ty.kind() {
25972597
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
25982598
self.mir_def_id(),

Diff for: compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11851185
let parent_self_ty =
11861186
matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. })
11871187
.then_some(parent_did)
1188-
.and_then(|did| match tcx.type_of(did).kind() {
1188+
.and_then(|did| match tcx.bound_type_of(did).subst_identity().kind() {
11891189
ty::Adt(def, ..) => Some(def.did()),
11901190
_ => None,
11911191
});

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
575575

576576
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
577577
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
578-
output_ty = self.infcx.tcx.type_of(def_id)
578+
output_ty = self.infcx.tcx.bound_type_of(def_id).subst_identity()
579579
};
580580

581581
debug!("report_fnmut_error: output_ty={:?}", output_ty);
@@ -896,7 +896,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
896896
debug!(?fn_did, ?substs);
897897

898898
// Only suggest this on function calls, not closures
899-
let ty = tcx.type_of(fn_did);
899+
let ty = tcx.bound_type_of(fn_did).subst_identity();
900900
debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind());
901901
if let ty::Closure(_, _) = ty.kind() {
902902
return;

Diff for: compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
850850
};
851851

852852
let found = tcx
853-
.any_free_region_meets(&tcx.type_of(region_parent), |r| *r == ty::ReEarlyBound(region));
853+
.any_free_region_meets(&tcx.bound_type_of(region_parent).subst_identity(), |r| {
854+
*r == ty::ReEarlyBound(region)
855+
});
854856

855857
Some(RegionName {
856858
name: self.synthesize_region_name(),

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
402402
);
403403
}
404404
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
405-
let unnormalized_ty = tcx.type_of(static_def_id);
405+
let unnormalized_ty = tcx.bound_type_of(static_def_id).subst_identity();
406406
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
407407
let literal_ty = constant.literal.ty().builtin_deref(true).unwrap().ty;
408408

Diff for: compiler/rustc_borrowck/src/universal_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
529529
match tcx.hir().body_owner_kind(self.mir_def.did) {
530530
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
531531
let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id {
532-
tcx.type_of(typeck_root_def_id)
532+
tcx.bound_type_of(typeck_root_def_id).subst_identity()
533533
} else {
534534
let tables = tcx.typeck(self.mir_def.did);
535535
tables.node_type(self.mir_hir_id)
@@ -675,7 +675,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
675675
// For a constant body, there are no inputs, and one
676676
// "output" (the type of the constant).
677677
assert_eq!(self.mir_def.did.to_def_id(), def_id);
678-
let ty = tcx.type_of(self.mir_def.def_id_for_type_of());
678+
let ty = tcx.bound_type_of(self.mir_def.def_id_for_type_of()).subst_identity();
679679
let ty = indices.fold_to_region_vids(tcx, ty);
680680
ty::Binder::dummy(tcx.intern_type_list(&[ty]))
681681
}

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
508508
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
509509
instance.substs,
510510
ty::ParamEnv::reveal_all(),
511-
cx.tcx.type_of(impl_def_id),
511+
cx.tcx.bound_type_of(impl_def_id).skip_binder(),
512512
);
513513

514514
// Only "class" methods are generally understood by LLVM,

Diff for: compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
690690
assert!(self.tcx.is_static(def_id));
691691
assert!(!self.tcx.is_thread_local_static(def_id));
692692
// Use size and align of the type.
693-
let ty = self.tcx.type_of(def_id);
693+
let ty = self.tcx.bound_type_of(def_id).subst_identity();
694694
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
695695
assert!(layout.is_sized());
696696
(layout.size, layout.align.abi, AllocKind::LiveData)

Diff for: compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
6868
pub fn fn_sig(&self) -> PolyFnSig<'tcx> {
6969
let did = self.def_id().to_def_id();
7070
if self.tcx.is_closure(did) {
71-
let ty = self.tcx.type_of(did);
71+
let ty = self.tcx.bound_type_of(did).subst_identity();
7272
let ty::Closure(_, substs) = ty.kind() else { bug!("type_of closure not ty::Closure") };
7373
substs.as_closure().sig()
7474
} else {

Diff for: compiler/rustc_hir_analysis/src/astconv/generics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn generic_arg_mismatch_err(
7777
Res::Def(DefKind::TyParam, src_def_id) => {
7878
if let Some(param_local_id) = param.def_id.as_local() {
7979
let param_name = tcx.hir().ty_param_name(param_local_id);
80-
let param_type = tcx.type_of(param.def_id);
80+
let param_type = tcx.bound_type_of(param.def_id).subst_identity();
8181
if param_type.is_suggestable(tcx, false) {
8282
err.span_suggestion(
8383
tcx.def_span(src_def_id),
@@ -97,7 +97,7 @@ fn generic_arg_mismatch_err(
9797
(
9898
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
9999
GenericParamDefKind::Const { .. },
100-
) if tcx.type_of(param.def_id) == tcx.types.usize => {
100+
) if tcx.bound_type_of(param.def_id).skip_binder() == tcx.types.usize => {
101101
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id()));
102102
if let Ok(snippet) = snippet {
103103
err.span_suggestion(

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
3030
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
3131
use rustc_middle::middle::stability::AllowUnstable;
3232
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
33+
use rustc_middle::ty::DynKind;
3334
use rustc_middle::ty::GenericParamDefKind;
3435
use rustc_middle::ty::{self, Const, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeVisitable};
35-
use rustc_middle::ty::{DynKind, EarlyBinder};
3636
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS};
3737
use rustc_span::edition::Edition;
3838
use rustc_span::lev_distance::find_best_match_for_name;
@@ -450,7 +450,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
450450
.into()
451451
}
452452
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
453-
let ty = tcx.at(self.span).type_of(param.def_id);
453+
let ty = tcx.at(self.span).bound_type_of(param.def_id).subst_identity();
454454
if self.astconv.allow_ty_infer() {
455455
self.astconv.ct_infer(ty, Some(param), inf.span).into()
456456
} else {
@@ -503,7 +503,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
503503
}
504504
}
505505
GenericParamDefKind::Const { has_default } => {
506-
let ty = tcx.at(self.span).type_of(param.def_id);
506+
let ty = tcx.at(self.span).bound_type_of(param.def_id).subst_identity();
507507
if ty.references_error() {
508508
return tcx.const_error(ty).into();
509509
}
@@ -2688,7 +2688,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26882688
// `Self` in impl (we know the concrete type).
26892689
assert_eq!(opt_self_ty, None);
26902690
// Try to evaluate any array length constants.
2691-
let ty = tcx.at(span).type_of(def_id);
2691+
let ty = tcx.at(span).bound_type_of(def_id).subst_identity();
26922692
let span_of_impl = tcx.span_of_impl(def_id);
26932693
self.prohibit_generics(path.segments.iter(), |err| {
26942694
let def_id = match *ty.kind() {
@@ -2922,7 +2922,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29222922
None,
29232923
ty::BoundConstness::NotConst,
29242924
);
2925-
EarlyBinder(tcx.at(span).type_of(def_id)).subst(tcx, substs)
2925+
tcx.at(span).bound_type_of(def_id).subst(tcx, substs)
29262926
}
29272927
hir::TyKind::Array(ty, length) => {
29282928
let length = match length {
@@ -2935,7 +2935,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29352935
tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length)
29362936
}
29372937
hir::TyKind::Typeof(e) => {
2938-
let ty_erased = tcx.type_of(e.def_id);
2938+
let ty_erased = tcx.bound_type_of(e.def_id).subst_identity();
29392939
let ty = tcx.fold_regions(ty_erased, |r, _| {
29402940
if r.is_erased() { tcx.lifetimes.re_static } else { r }
29412941
});

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) {
9393

9494
/// Check that the fields of the `union` do not need dropping.
9595
fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> bool {
96-
let item_type = tcx.type_of(item_def_id);
96+
let item_type = tcx.bound_type_of(item_def_id).subst_identity();
9797
if let ty::Adt(def, substs) = item_type.kind() {
9898
assert!(def.is_union());
9999

@@ -170,7 +170,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
170170
// would be enough to check this for `extern` statics, as statics with an initializer will
171171
// have UB during initialization if they are uninhabited, but there also seems to be no good
172172
// reason to allow any statics to be uninhabited.
173-
let ty = tcx.type_of(def_id);
173+
let ty = tcx.bound_type_of(def_id).subst_identity();
174174
let span = tcx.def_span(def_id);
175175
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
176176
Ok(l) => l,
@@ -227,7 +227,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
227227
if !tcx.features().impl_trait_projections {
228228
check_opaque_for_inheriting_lifetimes(tcx, item.owner_id.def_id, span);
229229
}
230-
if tcx.type_of(item.owner_id.def_id).references_error() {
230+
if tcx.bound_type_of(item.owner_id.def_id).subst_identity().references_error() {
231231
return;
232232
}
233233
if check_opaque_for_cycles(tcx, item.owner_id.def_id, substs, span, &origin).is_err() {
@@ -492,7 +492,7 @@ fn is_enum_of_nonnullable_ptr<'tcx>(
492492

493493
fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
494494
if tcx.codegen_fn_attrs(def_id).import_linkage.is_some() {
495-
if match tcx.type_of(def_id).kind() {
495+
if match tcx.bound_type_of(def_id).subst_identity().kind() {
496496
ty::RawPtr(_) => false,
497497
ty::Adt(adt_def, substs) => !is_enum_of_nonnullable_ptr(tcx, *adt_def, *substs),
498498
_ => true,
@@ -578,7 +578,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
578578
}
579579
}
580580
DefKind::TyAlias => {
581-
let pty_ty = tcx.type_of(id.owner_id);
581+
let pty_ty = tcx.bound_type_of(id.owner_id).subst_identity();
582582
let generics = tcx.generics_of(id.owner_id);
583583
check_type_params_are_used(tcx, &generics, pty_ty);
584584
}
@@ -854,7 +854,7 @@ fn check_impl_items_against_trait<'tcx>(
854854
}
855855

856856
pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
857-
let t = tcx.type_of(def_id);
857+
let t = tcx.bound_type_of(def_id).subst_identity();
858858
if let ty::Adt(def, substs) = t.kind()
859859
&& def.is_struct()
860860
{
@@ -974,7 +974,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
974974
&if first {
975975
format!(
976976
"`{}` contains a field of type `{}`",
977-
tcx.type_of(def.did()),
977+
tcx.bound_type_of(def.did()).subst_identity(),
978978
ident
979979
)
980980
} else {
@@ -996,7 +996,7 @@ pub(super) fn check_packed_inner(
996996
def_id: DefId,
997997
stack: &mut Vec<DefId>,
998998
) -> Option<Vec<(DefId, Span)>> {
999-
if let ty::Adt(def, substs) = tcx.type_of(def_id).kind() {
999+
if let ty::Adt(def, substs) = tcx.bound_type_of(def_id).subst_identity().kind() {
10001000
if def.is_struct() || def.is_union() {
10011001
if def.repr().align.is_some() {
10021002
return Some(vec![(def.did(), DUMMY_SP)]);

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,8 @@ fn compare_generic_param_kinds<'tcx>(
15801580
use GenericParamDefKind::*;
15811581
if match (&param_impl.kind, &param_trait.kind) {
15821582
(Const { .. }, Const { .. })
1583-
if tcx.type_of(param_impl.def_id) != tcx.type_of(param_trait.def_id) =>
1583+
if tcx.bound_type_of(param_impl.def_id)
1584+
!= tcx.bound_type_of(param_trait.def_id) =>
15841585
{
15851586
true
15861587
}
@@ -1605,7 +1606,11 @@ fn compare_generic_param_kinds<'tcx>(
16051606

16061607
let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind {
16071608
Const { .. } => {
1608-
format!("{} const parameter of type `{}`", prefix, tcx.type_of(param.def_id))
1609+
format!(
1610+
"{} const parameter of type `{}`",
1611+
prefix,
1612+
tcx.bound_type_of(param.def_id).subst_identity()
1613+
)
16091614
}
16101615
Type { .. } => format!("{} type parameter", prefix),
16111616
Lifetime { .. } => unreachable!(),
@@ -1654,7 +1659,7 @@ pub(super) fn compare_impl_const_raw(
16541659
// Create a parameter environment that represents the implementation's
16551660
// method.
16561661
// Compute placeholder form of impl and trait const tys.
1657-
let impl_ty = tcx.type_of(impl_const_item_def.to_def_id());
1662+
let impl_ty = tcx.bound_type_of(impl_const_item_def.to_def_id()).subst_identity();
16581663
let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs);
16591664
let mut cause = ObligationCause::new(
16601665
impl_c_span,
@@ -1927,7 +1932,7 @@ pub(super) fn check_type_bounds<'tcx>(
19271932
bound_vars.push(bound_var);
19281933
tcx.mk_const(
19291934
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)),
1930-
tcx.type_of(param.def_id),
1935+
tcx.bound_type_of(param.def_id).subst_identity(),
19311936
)
19321937
.into()
19331938
}
@@ -1937,7 +1942,7 @@ pub(super) fn check_type_bounds<'tcx>(
19371942
let container_id = impl_ty.container_id(tcx);
19381943

19391944
let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs);
1940-
let impl_ty_value = tcx.type_of(impl_ty.def_id);
1945+
let impl_ty_value = tcx.bound_type_of(impl_ty.def_id).subst_identity();
19411946

19421947
let param_env = tcx.param_env(impl_ty.def_id);
19431948

Diff for: compiler/rustc_hir_analysis/src/check/dropck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
2727
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
2828
///
2929
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
30-
let dtor_self_type = tcx.type_of(drop_impl_did);
30+
let dtor_self_type = tcx.bound_type_of(drop_impl_did).subst_identity();
3131
let dtor_predicates = tcx.predicates_of(drop_impl_did);
3232
match dtor_self_type.kind() {
3333
ty::Adt(adt_def, self_to_impl_substs) => {

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
450450
}
451451
ty::AssocKind::Type => format!("type {} = Type;", assoc.name),
452452
ty::AssocKind::Const => {
453-
let ty = tcx.type_of(assoc.def_id);
453+
let ty = tcx.bound_type_of(assoc.def_id).subst_identity();
454454
let val = ty_kind_suggestion(ty).unwrap_or("value");
455455
format!("const {}: {} = {};", assoc.name, ty, val)
456456
}

0 commit comments

Comments
 (0)