Skip to content

Commit 9556b56

Browse files
committed
Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU
Switch to `EarlyBinder` for `type_of` query Part of the work to finish #105779 and implement rust-lang/types-team#78. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `type_of` query and removes `bound_type_of`. r? `@lcnr`
2 parents ea21839 + f6c3469 commit 9556b56

File tree

164 files changed

+443
-334
lines changed

Some content is hidden

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

164 files changed

+443
-334
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
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.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(),

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
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.type_of(did).subst_identity().kind() {
11891189
ty::Adt(def, ..) => Some(def.did()),
11901190
_ => None,
11911191
});

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 2 additions & 2 deletions
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.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.type_of(fn_did).subst_identity();
900900
debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind());
901901
if let ty::Closure(_, _) = ty.kind() {
902902
return;

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
849849
return None;
850850
};
851851

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

855856
Some(RegionName {
856857
name: self.synthesize_region_name(),

compiler/rustc_borrowck/src/type_check/mod.rs

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

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
482482
);
483483
let region =
484484
self.infcx.tcx.mk_re_var(self.infcx.next_nll_region_var(FR).to_region_vid());
485-
let va_list_ty = self
486-
.infcx
487-
.tcx
488-
.bound_type_of(va_list_did)
489-
.subst(self.infcx.tcx, &[region.into()]);
485+
let va_list_ty =
486+
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
490487

491488
unnormalized_input_tys = self.infcx.tcx.mk_type_list(
492489
unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)),
@@ -529,7 +526,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
529526
match tcx.hir().body_owner_kind(self.mir_def.did) {
530527
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
531528
let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id {
532-
tcx.type_of(typeck_root_def_id)
529+
tcx.type_of(typeck_root_def_id).subst_identity()
533530
} else {
534531
let tables = tcx.typeck(self.mir_def.did);
535532
tables.node_type(self.mir_hir_id)
@@ -675,7 +672,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
675672
// For a constant body, there are no inputs, and one
676673
// "output" (the type of the constant).
677674
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());
675+
let ty = tcx.type_of(self.mir_def.def_id_for_type_of()).subst_identity();
679676
let ty = indices.fold_to_region_vids(tcx, ty);
680677
ty::Binder::dummy(tcx.intern_type_list(&[ty]))
681678
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
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.type_of(impl_def_id).skip_binder(),
512512
);
513513

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

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-
.bound_type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
98+
.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
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,11 @@ 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
694+
.tcx
695+
.type_of(def_id)
696+
.no_bound_vars()
697+
.expect("statics should not have generic parameters");
694698
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
695699
assert!(layout.is_sized());
696700
(layout.size, layout.align.abi, AllocKind::LiveData)

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

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

0 commit comments

Comments
 (0)