1
Fork 0

change usages of type_of to bound_type_of

This commit is contained in:
Kyle Matsuda 2023-02-06 17:48:12 -07:00
parent 9a7cc6c32f
commit d822b97a27
136 changed files with 385 additions and 262 deletions

View file

@ -2592,7 +2592,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if is_closure { if is_closure {
None None
} else { } else {
let ty = self.infcx.tcx.type_of(self.mir_def_id()); let ty = self.infcx.tcx.bound_type_of(self.mir_def_id()).subst_identity();
match ty.kind() { match ty.kind() {
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig( ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
self.mir_def_id(), self.mir_def_id(),

View file

@ -1185,7 +1185,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let parent_self_ty = let parent_self_ty =
matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. }) matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. })
.then_some(parent_did) .then_some(parent_did)
.and_then(|did| match tcx.type_of(did).kind() { .and_then(|did| match tcx.bound_type_of(did).subst_identity().kind() {
ty::Adt(def, ..) => Some(def.did()), ty::Adt(def, ..) => Some(def.did()),
_ => None, _ => None,
}); });

View file

@ -575,7 +575,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() { if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
output_ty = self.infcx.tcx.type_of(def_id) output_ty = self.infcx.tcx.bound_type_of(def_id).subst_identity()
}; };
debug!("report_fnmut_error: output_ty={:?}", output_ty); debug!("report_fnmut_error: output_ty={:?}", output_ty);
@ -896,7 +896,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
debug!(?fn_did, ?substs); debug!(?fn_did, ?substs);
// Only suggest this on function calls, not closures // Only suggest this on function calls, not closures
let ty = tcx.type_of(fn_did); let ty = tcx.bound_type_of(fn_did).subst_identity();
debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind()); debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind());
if let ty::Closure(_, _) = ty.kind() { if let ty::Closure(_, _) = ty.kind() {
return; return;

View file

@ -850,7 +850,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}; };
let found = tcx let found = tcx
.any_free_region_meets(&tcx.type_of(region_parent), |r| *r == ty::ReEarlyBound(region)); .any_free_region_meets(&tcx.bound_type_of(region_parent).subst_identity(), |r| {
*r == ty::ReEarlyBound(region)
});
Some(RegionName { Some(RegionName {
name: self.synthesize_region_name(), name: self.synthesize_region_name(),

View file

@ -402,7 +402,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
); );
} }
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) { } else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
let unnormalized_ty = tcx.type_of(static_def_id); let unnormalized_ty = tcx.bound_type_of(static_def_id).subst_identity();
let normalized_ty = self.cx.normalize(unnormalized_ty, locations); let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
let literal_ty = constant.literal.ty().builtin_deref(true).unwrap().ty; let literal_ty = constant.literal.ty().builtin_deref(true).unwrap().ty;

View file

@ -529,7 +529,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
match tcx.hir().body_owner_kind(self.mir_def.did) { match tcx.hir().body_owner_kind(self.mir_def.did) {
BodyOwnerKind::Closure | BodyOwnerKind::Fn => { BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id { let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id {
tcx.type_of(typeck_root_def_id) tcx.bound_type_of(typeck_root_def_id).subst_identity()
} else { } else {
let tables = tcx.typeck(self.mir_def.did); let tables = tcx.typeck(self.mir_def.did);
tables.node_type(self.mir_hir_id) tables.node_type(self.mir_hir_id)
@ -675,7 +675,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
// For a constant body, there are no inputs, and one // For a constant body, there are no inputs, and one
// "output" (the type of the constant). // "output" (the type of the constant).
assert_eq!(self.mir_def.did.to_def_id(), def_id); assert_eq!(self.mir_def.did.to_def_id(), def_id);
let ty = tcx.type_of(self.mir_def.def_id_for_type_of()); let ty = tcx.bound_type_of(self.mir_def.def_id_for_type_of()).subst_identity();
let ty = indices.fold_to_region_vids(tcx, ty); let ty = indices.fold_to_region_vids(tcx, ty);
ty::Binder::dummy(tcx.intern_type_list(&[ty])) ty::Binder::dummy(tcx.intern_type_list(&[ty]))
} }

View file

@ -508,7 +508,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions( let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
instance.substs, instance.substs,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
cx.tcx.type_of(impl_def_id), cx.tcx.bound_type_of(impl_def_id).skip_binder(),
); );
// Only "class" methods are generally understood by LLVM, // Only "class" methods are generally understood by LLVM,

View file

@ -690,7 +690,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
assert!(self.tcx.is_static(def_id)); assert!(self.tcx.is_static(def_id));
assert!(!self.tcx.is_thread_local_static(def_id)); assert!(!self.tcx.is_thread_local_static(def_id));
// Use size and align of the type. // Use size and align of the type.
let ty = self.tcx.type_of(def_id); let ty = self.tcx.bound_type_of(def_id).subst_identity();
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap(); let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
assert!(layout.is_sized()); assert!(layout.is_sized());
(layout.size, layout.align.abi, AllocKind::LiveData) (layout.size, layout.align.abi, AllocKind::LiveData)

View file

@ -68,7 +68,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
pub fn fn_sig(&self) -> PolyFnSig<'tcx> { pub fn fn_sig(&self) -> PolyFnSig<'tcx> {
let did = self.def_id().to_def_id(); let did = self.def_id().to_def_id();
if self.tcx.is_closure(did) { if self.tcx.is_closure(did) {
let ty = self.tcx.type_of(did); let ty = self.tcx.bound_type_of(did).subst_identity();
let ty::Closure(_, substs) = ty.kind() else { bug!("type_of closure not ty::Closure") }; let ty::Closure(_, substs) = ty.kind() else { bug!("type_of closure not ty::Closure") };
substs.as_closure().sig() substs.as_closure().sig()
} else { } else {

View file

@ -77,7 +77,7 @@ fn generic_arg_mismatch_err(
Res::Def(DefKind::TyParam, src_def_id) => { Res::Def(DefKind::TyParam, src_def_id) => {
if let Some(param_local_id) = param.def_id.as_local() { if let Some(param_local_id) = param.def_id.as_local() {
let param_name = tcx.hir().ty_param_name(param_local_id); let param_name = tcx.hir().ty_param_name(param_local_id);
let param_type = tcx.type_of(param.def_id); let param_type = tcx.bound_type_of(param.def_id).subst_identity();
if param_type.is_suggestable(tcx, false) { if param_type.is_suggestable(tcx, false) {
err.span_suggestion( err.span_suggestion(
tcx.def_span(src_def_id), tcx.def_span(src_def_id),
@ -97,7 +97,7 @@ fn generic_arg_mismatch_err(
( (
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }), GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
GenericParamDefKind::Const { .. }, GenericParamDefKind::Const { .. },
) if tcx.type_of(param.def_id) == tcx.types.usize => { ) if tcx.bound_type_of(param.def_id).skip_binder() == tcx.types.usize => {
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id())); let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id()));
if let Ok(snippet) = snippet { if let Ok(snippet) = snippet {
err.span_suggestion( err.span_suggestion(

View file

@ -30,9 +30,9 @@ use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::middle::stability::AllowUnstable;
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef}; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
use rustc_middle::ty::DynKind;
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, Const, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeVisitable}; use rustc_middle::ty::{self, Const, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{DynKind, EarlyBinder};
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS}; use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::lev_distance::find_best_match_for_name;
@ -450,7 +450,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.into() .into()
} }
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => { (&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
let ty = tcx.at(self.span).type_of(param.def_id); let ty = tcx.at(self.span).bound_type_of(param.def_id).subst_identity();
if self.astconv.allow_ty_infer() { if self.astconv.allow_ty_infer() {
self.astconv.ct_infer(ty, Some(param), inf.span).into() self.astconv.ct_infer(ty, Some(param), inf.span).into()
} else { } else {
@ -503,7 +503,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
} }
GenericParamDefKind::Const { has_default } => { GenericParamDefKind::Const { has_default } => {
let ty = tcx.at(self.span).type_of(param.def_id); let ty = tcx.at(self.span).bound_type_of(param.def_id).subst_identity();
if ty.references_error() { if ty.references_error() {
return tcx.const_error(ty).into(); return tcx.const_error(ty).into();
} }
@ -2688,7 +2688,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// `Self` in impl (we know the concrete type). // `Self` in impl (we know the concrete type).
assert_eq!(opt_self_ty, None); assert_eq!(opt_self_ty, None);
// Try to evaluate any array length constants. // Try to evaluate any array length constants.
let ty = tcx.at(span).type_of(def_id); let ty = tcx.at(span).bound_type_of(def_id).subst_identity();
let span_of_impl = tcx.span_of_impl(def_id); let span_of_impl = tcx.span_of_impl(def_id);
self.prohibit_generics(path.segments.iter(), |err| { self.prohibit_generics(path.segments.iter(), |err| {
let def_id = match *ty.kind() { let def_id = match *ty.kind() {
@ -2922,7 +2922,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
None, None,
ty::BoundConstness::NotConst, ty::BoundConstness::NotConst,
); );
EarlyBinder(tcx.at(span).type_of(def_id)).subst(tcx, substs) tcx.at(span).bound_type_of(def_id).subst(tcx, substs)
} }
hir::TyKind::Array(ty, length) => { hir::TyKind::Array(ty, length) => {
let length = match length { let length = match length {
@ -2935,7 +2935,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length) tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length)
} }
hir::TyKind::Typeof(e) => { hir::TyKind::Typeof(e) => {
let ty_erased = tcx.type_of(e.def_id); let ty_erased = tcx.bound_type_of(e.def_id).subst_identity();
let ty = tcx.fold_regions(ty_erased, |r, _| { let ty = tcx.fold_regions(ty_erased, |r, _| {
if r.is_erased() { tcx.lifetimes.re_static } else { r } if r.is_erased() { tcx.lifetimes.re_static } else { r }
}); });

View file

@ -93,7 +93,7 @@ fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) {
/// Check that the fields of the `union` do not need dropping. /// Check that the fields of the `union` do not need dropping.
fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> bool { fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> bool {
let item_type = tcx.type_of(item_def_id); let item_type = tcx.bound_type_of(item_def_id).subst_identity();
if let ty::Adt(def, substs) = item_type.kind() { if let ty::Adt(def, substs) = item_type.kind() {
assert!(def.is_union()); assert!(def.is_union());
@ -170,7 +170,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
// would be enough to check this for `extern` statics, as statics with an initializer will // would be enough to check this for `extern` statics, as statics with an initializer will
// have UB during initialization if they are uninhabited, but there also seems to be no good // have UB during initialization if they are uninhabited, but there also seems to be no good
// reason to allow any statics to be uninhabited. // reason to allow any statics to be uninhabited.
let ty = tcx.type_of(def_id); let ty = tcx.bound_type_of(def_id).subst_identity();
let span = tcx.def_span(def_id); let span = tcx.def_span(def_id);
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) { let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
Ok(l) => l, Ok(l) => l,
@ -227,7 +227,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
if !tcx.features().impl_trait_projections { if !tcx.features().impl_trait_projections {
check_opaque_for_inheriting_lifetimes(tcx, item.owner_id.def_id, span); check_opaque_for_inheriting_lifetimes(tcx, item.owner_id.def_id, span);
} }
if tcx.type_of(item.owner_id.def_id).references_error() { if tcx.bound_type_of(item.owner_id.def_id).subst_identity().references_error() {
return; return;
} }
if check_opaque_for_cycles(tcx, item.owner_id.def_id, substs, span, &origin).is_err() { 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>(
fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) { fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
if tcx.codegen_fn_attrs(def_id).import_linkage.is_some() { if tcx.codegen_fn_attrs(def_id).import_linkage.is_some() {
if match tcx.type_of(def_id).kind() { if match tcx.bound_type_of(def_id).subst_identity().kind() {
ty::RawPtr(_) => false, ty::RawPtr(_) => false,
ty::Adt(adt_def, substs) => !is_enum_of_nonnullable_ptr(tcx, *adt_def, *substs), ty::Adt(adt_def, substs) => !is_enum_of_nonnullable_ptr(tcx, *adt_def, *substs),
_ => true, _ => true,
@ -578,7 +578,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
} }
} }
DefKind::TyAlias => { DefKind::TyAlias => {
let pty_ty = tcx.type_of(id.owner_id); let pty_ty = tcx.bound_type_of(id.owner_id).subst_identity();
let generics = tcx.generics_of(id.owner_id); let generics = tcx.generics_of(id.owner_id);
check_type_params_are_used(tcx, &generics, pty_ty); check_type_params_are_used(tcx, &generics, pty_ty);
} }
@ -854,7 +854,7 @@ fn check_impl_items_against_trait<'tcx>(
} }
pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) { pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
let t = tcx.type_of(def_id); let t = tcx.bound_type_of(def_id).subst_identity();
if let ty::Adt(def, substs) = t.kind() if let ty::Adt(def, substs) = t.kind()
&& def.is_struct() && def.is_struct()
{ {
@ -974,7 +974,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
&if first { &if first {
format!( format!(
"`{}` contains a field of type `{}`", "`{}` contains a field of type `{}`",
tcx.type_of(def.did()), tcx.bound_type_of(def.did()).subst_identity(),
ident ident
) )
} else { } else {
@ -996,7 +996,7 @@ pub(super) fn check_packed_inner(
def_id: DefId, def_id: DefId,
stack: &mut Vec<DefId>, stack: &mut Vec<DefId>,
) -> Option<Vec<(DefId, Span)>> { ) -> Option<Vec<(DefId, Span)>> {
if let ty::Adt(def, substs) = tcx.type_of(def_id).kind() { if let ty::Adt(def, substs) = tcx.bound_type_of(def_id).subst_identity().kind() {
if def.is_struct() || def.is_union() { if def.is_struct() || def.is_union() {
if def.repr().align.is_some() { if def.repr().align.is_some() {
return Some(vec![(def.did(), DUMMY_SP)]); return Some(vec![(def.did(), DUMMY_SP)]);

View file

@ -1580,7 +1580,8 @@ fn compare_generic_param_kinds<'tcx>(
use GenericParamDefKind::*; use GenericParamDefKind::*;
if match (&param_impl.kind, &param_trait.kind) { if match (&param_impl.kind, &param_trait.kind) {
(Const { .. }, Const { .. }) (Const { .. }, Const { .. })
if tcx.type_of(param_impl.def_id) != tcx.type_of(param_trait.def_id) => if tcx.bound_type_of(param_impl.def_id)
!= tcx.bound_type_of(param_trait.def_id) =>
{ {
true true
} }
@ -1605,7 +1606,11 @@ fn compare_generic_param_kinds<'tcx>(
let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind { let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind {
Const { .. } => { Const { .. } => {
format!("{} const parameter of type `{}`", prefix, tcx.type_of(param.def_id)) format!(
"{} const parameter of type `{}`",
prefix,
tcx.bound_type_of(param.def_id).subst_identity()
)
} }
Type { .. } => format!("{} type parameter", prefix), Type { .. } => format!("{} type parameter", prefix),
Lifetime { .. } => unreachable!(), Lifetime { .. } => unreachable!(),
@ -1654,7 +1659,7 @@ pub(super) fn compare_impl_const_raw(
// Create a parameter environment that represents the implementation's // Create a parameter environment that represents the implementation's
// method. // method.
// Compute placeholder form of impl and trait const tys. // Compute placeholder form of impl and trait const tys.
let impl_ty = tcx.type_of(impl_const_item_def.to_def_id()); let impl_ty = tcx.bound_type_of(impl_const_item_def.to_def_id()).subst_identity();
let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs); let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs);
let mut cause = ObligationCause::new( let mut cause = ObligationCause::new(
impl_c_span, impl_c_span,
@ -1927,7 +1932,7 @@ pub(super) fn check_type_bounds<'tcx>(
bound_vars.push(bound_var); bound_vars.push(bound_var);
tcx.mk_const( tcx.mk_const(
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)), ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)),
tcx.type_of(param.def_id), tcx.bound_type_of(param.def_id).subst_identity(),
) )
.into() .into()
} }
@ -1937,7 +1942,7 @@ pub(super) fn check_type_bounds<'tcx>(
let container_id = impl_ty.container_id(tcx); let container_id = impl_ty.container_id(tcx);
let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs); let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs);
let impl_ty_value = tcx.type_of(impl_ty.def_id); let impl_ty_value = tcx.bound_type_of(impl_ty.def_id).subst_identity();
let param_env = tcx.param_env(impl_ty.def_id); let param_env = tcx.param_env(impl_ty.def_id);

View file

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

View file

@ -450,7 +450,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
} }
ty::AssocKind::Type => format!("type {} = Type;", assoc.name), ty::AssocKind::Type => format!("type {} = Type;", assoc.name),
ty::AssocKind::Const => { ty::AssocKind::Const => {
let ty = tcx.type_of(assoc.def_id); let ty = tcx.bound_type_of(assoc.def_id).subst_identity();
let val = ty_kind_suggestion(ty).unwrap_or("value"); let val = ty_kind_suggestion(ty).unwrap_or("value");
format!("const {}: {} = {};", assoc.name, ty, val) format!("const {}: {} = {};", assoc.name, ty, val)
} }

View file

@ -874,7 +874,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
// Const parameters are well formed if their type is structural match. // Const parameters are well formed if their type is structural match.
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => { hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
let ty = tcx.type_of(param.def_id); let ty = tcx.bound_type_of(param.def_id).subst_identity();
if tcx.features().adt_const_params { if tcx.features().adt_const_params {
if let Some(non_structural_match_ty) = if let Some(non_structural_match_ty) =
@ -1011,12 +1011,12 @@ fn check_associated_item(
let self_ty = match item.container { let self_ty = match item.container {
ty::TraitContainer => tcx.types.self_param, ty::TraitContainer => tcx.types.self_param,
ty::ImplContainer => tcx.type_of(item.container_id(tcx)), ty::ImplContainer => tcx.bound_type_of(item.container_id(tcx)).subst_identity(),
}; };
match item.kind { match item.kind {
ty::AssocKind::Const => { ty::AssocKind::Const => {
let ty = tcx.type_of(item.def_id); let ty = tcx.bound_type_of(item.def_id).subst_identity();
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty); let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
wfcx.register_wf_obligation(span, loc, ty.into()); wfcx.register_wf_obligation(span, loc, ty.into());
} }
@ -1037,7 +1037,7 @@ fn check_associated_item(
check_associated_type_bounds(wfcx, item, span) check_associated_type_bounds(wfcx, item, span)
} }
if item.defaultness(tcx).has_value() { if item.defaultness(tcx).has_value() {
let ty = tcx.type_of(item.def_id); let ty = tcx.bound_type_of(item.def_id).subst_identity();
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty); let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
wfcx.register_wf_obligation(span, loc, ty.into()); wfcx.register_wf_obligation(span, loc, ty.into());
} }
@ -1070,7 +1070,11 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
let field_id = field.did.expect_local(); let field_id = field.did.expect_local();
let hir::FieldDef { ty: hir_ty, .. } = let hir::FieldDef { ty: hir_ty, .. } =
tcx.hir().get_by_def_id(field_id).expect_field(); tcx.hir().get_by_def_id(field_id).expect_field();
let ty = wfcx.normalize(hir_ty.span, None, tcx.type_of(field.did)); let ty = wfcx.normalize(
hir_ty.span,
None,
tcx.bound_type_of(field.did).subst_identity(),
);
wfcx.register_wf_obligation( wfcx.register_wf_obligation(
hir_ty.span, hir_ty.span,
Some(WellFormedLoc::Ty(field_id)), Some(WellFormedLoc::Ty(field_id)),
@ -1082,7 +1086,7 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
// intermediate types must be sized. // intermediate types must be sized.
let needs_drop_copy = || { let needs_drop_copy = || {
packed && { packed && {
let ty = tcx.type_of(variant.fields.last().unwrap().did); let ty = tcx.bound_type_of(variant.fields.last().unwrap().did).subst_identity();
let ty = tcx.erase_regions(ty); let ty = tcx.erase_regions(ty);
if ty.needs_infer() { if ty.needs_infer() {
tcx.sess tcx.sess
@ -1104,7 +1108,11 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
let field_id = field.did.expect_local(); let field_id = field.did.expect_local();
let hir::FieldDef { ty: hir_ty, .. } = let hir::FieldDef { ty: hir_ty, .. } =
tcx.hir().get_by_def_id(field_id).expect_field(); tcx.hir().get_by_def_id(field_id).expect_field();
let ty = wfcx.normalize(hir_ty.span, None, tcx.type_of(field.did)); let ty = wfcx.normalize(
hir_ty.span,
None,
tcx.bound_type_of(field.did).subst_identity(),
);
wfcx.register_bound( wfcx.register_bound(
traits::ObligationCause::new( traits::ObligationCause::new(
hir_ty.span, hir_ty.span,
@ -1215,7 +1223,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo
debug!("check_item_type: {:?}", item_id); debug!("check_item_type: {:?}", item_id);
enter_wf_checking_ctxt(tcx, ty_span, item_id, |wfcx| { enter_wf_checking_ctxt(tcx, ty_span, item_id, |wfcx| {
let ty = tcx.type_of(item_id); let ty = tcx.bound_type_of(item_id).subst_identity();
let item_ty = wfcx.normalize(ty_span, Some(WellFormedLoc::Ty(item_id)), ty); let item_ty = wfcx.normalize(ty_span, Some(WellFormedLoc::Ty(item_id)), ty);
let mut forbid_unsized = true; let mut forbid_unsized = true;
@ -1300,7 +1308,7 @@ fn check_impl<'tcx>(
wfcx.register_obligations(obligations); wfcx.register_obligations(obligations);
} }
None => { None => {
let self_ty = tcx.type_of(item.owner_id); let self_ty = tcx.bound_type_of(item.owner_id).subst_identity();
let self_ty = wfcx.normalize( let self_ty = wfcx.normalize(
item.span, item.span,
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
@ -1345,7 +1353,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
match param.kind { match param.kind {
GenericParamDefKind::Type { .. } => { GenericParamDefKind::Type { .. } => {
if is_our_default(param) { if is_our_default(param) {
let ty = tcx.type_of(param.def_id); let ty = tcx.bound_type_of(param.def_id).subst_identity();
// Ignore dependent defaults -- that is, where the default of one type // Ignore dependent defaults -- that is, where the default of one type
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't // parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
// be sure if it will error or not as user might always specify the other. // be sure if it will error or not as user might always specify the other.
@ -1397,7 +1405,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
GenericParamDefKind::Type { .. } => { GenericParamDefKind::Type { .. } => {
// If the param has a default, ... // If the param has a default, ...
if is_our_default(param) { if is_our_default(param) {
let default_ty = tcx.type_of(param.def_id); let default_ty = tcx.bound_type_of(param.def_id).subst_identity();
// ... and it's not a dependent default, ... // ... and it's not a dependent default, ...
if !default_ty.needs_subst() { if !default_ty.needs_subst() {
// ... then substitute it with the default. // ... then substitute it with the default.
@ -1813,7 +1821,7 @@ fn check_variances_for_type_defn<'tcx>(
item: &hir::Item<'tcx>, item: &hir::Item<'tcx>,
hir_generics: &hir::Generics<'_>, hir_generics: &hir::Generics<'_>,
) { ) {
let ty = tcx.type_of(item.owner_id); let ty = tcx.bound_type_of(item.owner_id).subst_identity();
if tcx.has_error_field(ty) { if tcx.has_error_field(ty) {
return; return;
} }

View file

@ -50,7 +50,7 @@ impl<'tcx> Checker<'tcx> {
fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) { fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
// Destructors only work on local ADT types. // Destructors only work on local ADT types.
match tcx.type_of(impl_did).kind() { match tcx.bound_type_of(impl_did).subst_identity().kind() {
ty::Adt(def, _) if def.did().is_local() => return, ty::Adt(def, _) if def.did().is_local() => return,
ty::Error(_) => return, ty::Error(_) => return,
_ => {} _ => {}
@ -64,7 +64,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did); debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
let self_type = tcx.type_of(impl_did); let self_type = tcx.bound_type_of(impl_did).subst_identity();
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);
let param_env = tcx.param_env(impl_did); let param_env = tcx.param_env(impl_did);
@ -206,7 +206,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span)); let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));
let source = tcx.type_of(impl_did); let source = tcx.bound_type_of(impl_did).subst_identity();
assert!(!source.has_escaping_bound_vars()); assert!(!source.has_escaping_bound_vars());
let target = { let target = {
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity(); let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();
@ -370,7 +370,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
tcx.sess.fatal(&format!("`CoerceUnsized` implementation {}", err.to_string())); tcx.sess.fatal(&format!("`CoerceUnsized` implementation {}", err.to_string()));
}); });
let source = tcx.type_of(impl_did); let source = tcx.bound_type_of(impl_did).subst_identity();
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity(); let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();
assert_eq!(trait_ref.def_id, coerce_unsized_trait); assert_eq!(trait_ref.def_id, coerce_unsized_trait);
let target = trait_ref.substs.type_at(1); let target = trait_ref.substs.type_at(1);
@ -482,7 +482,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
.filter_map(|(i, f)| { .filter_map(|(i, f)| {
let (a, b) = (f.ty(tcx, substs_a), f.ty(tcx, substs_b)); let (a, b) = (f.ty(tcx, substs_a), f.ty(tcx, substs_b));
if tcx.type_of(f.did).is_phantom_data() { if tcx.bound_type_of(f.did).subst_identity().is_phantom_data() {
// Ignore PhantomData fields // Ignore PhantomData fields
return None; return None;
} }

View file

@ -173,7 +173,7 @@ impl<'tcx> InherentCollect<'tcx> {
let id = id.owner_id.def_id; let id = id.owner_id.def_id;
let item_span = self.tcx.def_span(id); let item_span = self.tcx.def_span(id);
let self_ty = self.tcx.type_of(id); let self_ty = self.tcx.bound_type_of(id).subst_identity();
match *self_ty.kind() { match *self_ty.kind() {
ty::Adt(def, _) => self.check_def_id(id, self_ty, def.did()), ty::Adt(def, _) => self.check_def_id(id, self_ty, def.did()),
ty::Foreign(did) => self.check_def_id(id, self_ty, did), ty::Foreign(did) => self.check_def_id(id, self_ty, did),

View file

@ -1143,8 +1143,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>>
} }
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => { Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id)); let ty = tcx.bound_type_of(tcx.hir().get_parent_item(hir_id)).subst_identity();
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id)); let inputs = data.fields().iter().map(|f| tcx.bound_type_of(f.def_id).subst_identity());
ty::Binder::dummy(tcx.mk_fn_sig( ty::Binder::dummy(tcx.mk_fn_sig(
inputs, inputs,
ty, ty,
@ -1345,7 +1345,7 @@ fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::EarlyBinder<ty::
.of_trait .of_trait
.as_ref() .as_ref()
.map(|ast_trait_ref| { .map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id); let selfty = tcx.bound_type_of(def_id).subst_identity();
icx.astconv().instantiate_mono_trait_ref( icx.astconv().instantiate_mono_trait_ref(
ast_trait_ref, ast_trait_ref,
selfty, selfty,

View file

@ -1804,7 +1804,7 @@ fn is_late_bound_map(
let mut walker = ConstrainedCollectorPostAstConv { let mut walker = ConstrainedCollectorPostAstConv {
arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(), arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(),
}; };
walker.visit_ty(self.tcx.type_of(alias_def)); walker.visit_ty(self.tcx.bound_type_of(alias_def).subst_identity());
match segments.last() { match segments.last() {
Some(hir::PathSegment { args: Some(args), .. }) => { Some(hir::PathSegment { args: Some(args), .. }) => {

View file

@ -251,7 +251,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
// in trait checking. See `setup_constraining_predicates` // in trait checking. See `setup_constraining_predicates`
// for details. // for details.
if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node { if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
let self_ty = tcx.type_of(def_id); let self_ty = tcx.bound_type_of(def_id).subst_identity();
let trait_ref = tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity); let trait_ref = tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity);
cgp::setup_constraining_predicates( cgp::setup_constraining_predicates(
tcx, tcx,

View file

@ -377,7 +377,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def { Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def {
VariantData::Unit(..) | VariantData::Struct(..) => { VariantData::Unit(..) | VariantData::Struct(..) => {
tcx.type_of(tcx.hir().get_parent_item(hir_id)) tcx.bound_type_of(tcx.hir().get_parent_item(hir_id)).subst_identity()
} }
VariantData::Tuple(..) => { VariantData::Tuple(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
@ -394,7 +394,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
Node::AnonConst(_) if let Some(param) = tcx.opt_const_param_of(def_id) => { Node::AnonConst(_) if let Some(param) = tcx.opt_const_param_of(def_id) => {
// We defer to `type_of` of the corresponding parameter // We defer to `type_of` of the corresponding parameter
// for generic arguments. // for generic arguments.
tcx.type_of(param) tcx.bound_type_of(param).subst_identity()
} }
Node::AnonConst(_) => { Node::AnonConst(_) => {
@ -456,7 +456,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
def_id.to_def_id(), def_id.to_def_id(),
); );
if let Some(assoc_item) = assoc_item { if let Some(assoc_item) = assoc_item {
tcx.type_of(assoc_item.def_id) tcx.bound_type_of(assoc_item.def_id).subst_identity()
} else { } else {
// FIXME(associated_const_equality): add a useful error message here. // FIXME(associated_const_equality): add a useful error message here.
tcx.ty_error_with_message( tcx.ty_error_with_message(
@ -501,7 +501,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
if let Some(param) if let Some(param)
= assoc_item.map(|item| &tcx.generics_of(item.def_id).params[idx]).filter(|param| param.kind.is_ty_or_const()) = assoc_item.map(|item| &tcx.generics_of(item.def_id).params[idx]).filter(|param| param.kind.is_ty_or_const())
{ {
tcx.type_of(param.def_id) tcx.bound_type_of(param.def_id).subst_identity()
} else { } else {
// FIXME(associated_const_equality): add a useful error message here. // FIXME(associated_const_equality): add a useful error message here.
tcx.ty_error_with_message( tcx.ty_error_with_message(
@ -515,7 +515,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
def_id: param_def_id, def_id: param_def_id,
kind: GenericParamKind::Const { default: Some(ct), .. }, kind: GenericParamKind::Const { default: Some(ct), .. },
.. ..
}) if ct.hir_id == hir_id => tcx.type_of(param_def_id), }) if ct.hir_id == hir_id => tcx.bound_type_of(param_def_id).subst_identity(),
x => tcx.ty_error_with_message( x => tcx.ty_error_with_message(
DUMMY_SP, DUMMY_SP,

View file

@ -70,7 +70,7 @@ pub fn provide(providers: &mut Providers) {
fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) { fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) {
// Every lifetime used in an associated type must be constrained. // Every lifetime used in an associated type must be constrained.
let impl_self_ty = tcx.type_of(impl_def_id); let impl_self_ty = tcx.bound_type_of(impl_def_id).subst_identity();
if impl_self_ty.references_error() { if impl_self_ty.references_error() {
// Don't complain about unconstrained type params when self ty isn't known due to errors. // Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836) // (#36836)
@ -104,7 +104,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
match item.kind { match item.kind {
ty::AssocKind::Type => { ty::AssocKind::Type => {
if item.defaultness(tcx).has_value() { if item.defaultness(tcx).has_value() {
cgp::parameters_for(&tcx.type_of(def_id), true) cgp::parameters_for(&tcx.bound_type_of(def_id).subst_identity(), true)
} else { } else {
Vec::new() Vec::new()
} }

View file

@ -187,7 +187,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
fn main_fn_diagnostics_def_id(tcx: TyCtxt<'_>, def_id: DefId, sp: Span) -> LocalDefId { fn main_fn_diagnostics_def_id(tcx: TyCtxt<'_>, def_id: DefId, sp: Span) -> LocalDefId {
if let Some(local_def_id) = def_id.as_local() { if let Some(local_def_id) = def_id.as_local() {
let hir_type = tcx.type_of(local_def_id); let hir_type = tcx.bound_type_of(local_def_id).subst_identity();
if !matches!(hir_type.kind(), ty::FnDef(..)) { if !matches!(hir_type.kind(), ty::FnDef(..)) {
span_bug!(sp, "main has a non-function type: found `{}`", hir_type); span_bug!(sp, "main has a non-function type: found `{}`", hir_type);
} }
@ -366,7 +366,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
let start_def_id = start_def_id.expect_local(); let start_def_id = start_def_id.expect_local();
let start_id = tcx.hir().local_def_id_to_hir_id(start_def_id); let start_id = tcx.hir().local_def_id_to_hir_id(start_def_id);
let start_span = tcx.def_span(start_def_id); let start_span = tcx.def_span(start_def_id);
let start_t = tcx.type_of(start_def_id); let start_t = tcx.bound_type_of(start_def_id).subst_identity();
match start_t.kind() { match start_t.kind() {
ty::FnDef(..) => { ty::FnDef(..) => {
if let Some(Node::Item(it)) = tcx.hir().find(start_id) { if let Some(Node::Item(it)) = tcx.hir().find(start_id) {

View file

@ -46,7 +46,7 @@ pub(super) fn infer_predicates(
// For field of type &'a T (reference) or Adt // For field of type &'a T (reference) or Adt
// (struct/enum/union) there will be outlive // (struct/enum/union) there will be outlive
// requirements for adt_def. // requirements for adt_def.
let field_ty = tcx.type_of(field_def.did); let field_ty = tcx.bound_type_of(field_def.did).subst_identity();
let field_span = tcx.def_span(field_def.did); let field_span = tcx.def_span(field_def.did);
insert_required_predicates_to_be_wf( insert_required_predicates_to_be_wf(
tcx, tcx,

View file

@ -101,7 +101,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
let inferred_start = self.terms_cx.inferred_starts[&def_id]; let inferred_start = self.terms_cx.inferred_starts[&def_id];
let current_item = &CurrentItem { inferred_start }; let current_item = &CurrentItem { inferred_start };
match tcx.type_of(def_id).kind() { match tcx.bound_type_of(def_id).subst_identity().kind() {
ty::Adt(def, _) => { ty::Adt(def, _) => {
// Not entirely obvious: constraints on structs/enums do not // Not entirely obvious: constraints on structs/enums do not
// affect the variance of their type parameters. See discussion // affect the variance of their type parameters. See discussion
@ -112,7 +112,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
for field in def.all_fields() { for field in def.all_fields() {
self.add_constraints_from_ty( self.add_constraints_from_ty(
current_item, current_item,
tcx.type_of(field.did), tcx.bound_type_of(field.did).subst_identity(),
self.covariant, self.covariant,
); );
} }

View file

@ -103,7 +103,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
self.enforce_const_invariance(generics, variances); self.enforce_const_invariance(generics, variances);
// Functions are permitted to have unused generic parameters: make those invariant. // Functions are permitted to have unused generic parameters: make those invariant.
if let ty::FnDef(..) = tcx.type_of(def_id).kind() { if let ty::FnDef(..) = tcx.bound_type_of(def_id).subst_identity().kind() {
for variance in variances.iter_mut() { for variance in variances.iter_mut() {
if *variance == ty::Bivariant { if *variance == ty::Bivariant {
*variance = ty::Invariant; *variance = ty::Invariant;

View file

@ -1130,7 +1130,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.unwrap_or(false); .unwrap_or(false);
let (res, self_ctor_substs) = if let Res::SelfCtor(impl_def_id) = res { let (res, self_ctor_substs) = if let Res::SelfCtor(impl_def_id) = res {
let ty = self.handle_raw_ty(span, tcx.at(span).type_of(impl_def_id)); let ty =
self.handle_raw_ty(span, tcx.at(span).bound_type_of(impl_def_id).subst_identity());
match ty.normalized.ty_adt_def() { match ty.normalized.ty_adt_def() {
Some(adt_def) if adt_def.has_ctor() => { Some(adt_def) if adt_def.has_ctor() => {
let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap(); let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();
@ -1226,7 +1227,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
(GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => { (GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
let tcx = self.fcx.tcx(); let tcx = self.fcx.tcx();
self.fcx.ct_infer(tcx.type_of(param.def_id), Some(param), inf.span).into() self.fcx
.ct_infer(
tcx.bound_type_of(param.def_id).subst_identity(),
Some(param),
inf.span,
)
.into()
} }
_ => unreachable!(), _ => unreachable!(),
} }

View file

@ -312,7 +312,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// same rules that check_expr_struct uses for macro hygiene. // same rules that check_expr_struct uses for macro hygiene.
if self.tcx.adjust_ident(expr_field.ident, variant_def_id) == field.ident(self.tcx) if self.tcx.adjust_ident(expr_field.ident, variant_def_id) == field.ident(self.tcx)
{ {
return Some((expr_field.expr, self.tcx.type_of(field.did))); return Some((
expr_field.expr,
self.tcx.bound_type_of(field.did).subst_identity(),
));
} }
} }
} }
@ -339,7 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
receiver: Option<&'tcx hir::Expr<'tcx>>, receiver: Option<&'tcx hir::Expr<'tcx>>,
args: &'tcx [hir::Expr<'tcx>], args: &'tcx [hir::Expr<'tcx>],
) -> bool { ) -> bool {
let ty = self.tcx.type_of(def_id); let ty = self.tcx.bound_type_of(def_id).subst_identity();
if !ty.is_fn() { if !ty.is_fn() {
return false; return false;
} }

View file

@ -1378,7 +1378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Same item // Same item
return false; return false;
} }
let item_ty = self.tcx.type_of(item.def_id); let item_ty = self.tcx.bound_type_of(item.def_id).subst_identity();
// FIXME(compiler-errors): This check is *so* rudimentary // FIXME(compiler-errors): This check is *so* rudimentary
if item_ty.needs_subst() { if item_ty.needs_subst() {
return false; return false;

View file

@ -154,7 +154,7 @@ fn typeck_const_arg<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
(did, param_did): (LocalDefId, DefId), (did, param_did): (LocalDefId, DefId),
) -> &ty::TypeckResults<'tcx> { ) -> &ty::TypeckResults<'tcx> {
let fallback = move || tcx.type_of(param_did); let fallback = move || tcx.bound_type_of(param_did).subst_identity();
typeck_with_fallback(tcx, did, fallback) typeck_with_fallback(tcx, did, fallback)
} }
@ -162,7 +162,7 @@ fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tc
if let Some(param_did) = tcx.opt_const_param_of(def_id) { if let Some(param_did) = tcx.opt_const_param_of(def_id) {
tcx.typeck_const_arg((def_id, param_did)) tcx.typeck_const_arg((def_id, param_did))
} else { } else {
let fallback = move || tcx.type_of(def_id.to_def_id()); let fallback = move || tcx.bound_type_of(def_id.to_def_id()).subst_identity();
typeck_with_fallback(tcx, def_id, fallback) typeck_with_fallback(tcx, def_id, fallback)
} }
} }

View file

@ -384,7 +384,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
} }
(GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => { (GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
let tcx = self.cfcx.tcx(); let tcx = self.cfcx.tcx();
self.cfcx.ct_infer(tcx.type_of(param.def_id), Some(param), inf.span).into() self.cfcx
.ct_infer(
tcx.bound_type_of(param.def_id).subst_identity(),
Some(param),
inf.span,
)
.into()
} }
_ => unreachable!(), _ => unreachable!(),
} }

View file

@ -1958,7 +1958,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
kind: ConstVariableOriginKind::SubstitutionPlaceholder, kind: ConstVariableOriginKind::SubstitutionPlaceholder,
span, span,
}; };
self.next_const_var(self.tcx.type_of(param.def_id), origin).into() self.next_const_var(self.tcx.bound_type_of(param.def_id).subst_identity(), origin)
.into()
} }
}) })
} }

View file

@ -906,8 +906,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// different from the received one // different from the received one
// So we avoid suggestion method with Box<Self> // So we avoid suggestion method with Box<Self>
// for instance // for instance
self.tcx.at(span).type_of(*def_id) != rcvr_ty self.tcx.at(span).bound_type_of(*def_id).subst_identity()
&& self.tcx.at(span).type_of(*def_id) != rcvr_ty != rcvr_ty
&& self
.tcx
.at(span)
.bound_type_of(*def_id)
.subst_identity()
!= rcvr_ty
} }
(Mode::Path, false, _) => true, (Mode::Path, false, _) => true,
_ => false, _ => false,
@ -927,7 +933,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.iter() .iter()
.take(limit) .take(limit)
.map(|impl_item| { .map(|impl_item| {
format!("- `{}`", self.tcx.at(span).type_of(*impl_item)) format!(
"- `{}`",
self.tcx.at(span).bound_type_of(*impl_item).subst_identity()
)
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("\n");
@ -1104,7 +1113,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None None
}; };
let impl_ty = self.tcx.at(span).type_of(impl_did); let impl_ty = self.tcx.at(span).bound_type_of(impl_did).subst_identity();
let insertion = match self.tcx.impl_trait_ref(impl_did) { let insertion = match self.tcx.impl_trait_ref(impl_did) {
None => String::new(), None => String::new(),
@ -1233,7 +1242,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// When the "method" is resolved through dereferencing, we really want the // When the "method" is resolved through dereferencing, we really want the
// original type that has the associated function for accurate suggestions. // original type that has the associated function for accurate suggestions.
// (#61411) // (#61411)
let impl_ty = self.tcx.type_of(*impl_did); let impl_ty = self.tcx.bound_type_of(*impl_did).subst_identity();
let target_ty = self let target_ty = self
.autoderef(sugg_span, rcvr_ty) .autoderef(sugg_span, rcvr_ty)
.find(|(rcvr_ty, _)| { .find(|(rcvr_ty, _)| {

View file

@ -72,7 +72,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}; };
// Next, let's figure out the set of trait objects with implicit static bounds // Next, let's figure out the set of trait objects with implicit static bounds
let ty = self.tcx().type_of(*impl_def_id); let ty = self.tcx().bound_type_of(*impl_def_id).subst_identity();
let mut v = super::static_impl_trait::TraitObjectVisitor(FxIndexSet::default()); let mut v = super::static_impl_trait::TraitObjectVisitor(FxIndexSet::default());
v.visit_ty(ty); v.visit_ty(ty);
let mut traits = vec![]; let mut traits = vec![];

View file

@ -123,7 +123,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
br: ty::BoundRegionKind, br: ty::BoundRegionKind,
hir_sig: &hir::FnSig<'_>, hir_sig: &hir::FnSig<'_>,
) -> Option<Span> { ) -> Option<Span> {
let fn_ty = self.tcx().type_of(scope_def_id); let fn_ty = self.tcx().bound_type_of(scope_def_id).subst_identity();
if let ty::FnDef(_, _) = fn_ty.kind() { if let ty::FnDef(_, _) = fn_ty.kind() {
let ret_ty = fn_ty.fn_sig(self.tcx()).output(); let ret_ty = fn_ty.fn_sig(self.tcx()).output();
let span = hir_sig.decl.output.span(); let span = hir_sig.decl.output.span();

View file

@ -1166,7 +1166,9 @@ impl<'tcx> InferCtxt<'tcx> {
origin, origin,
val: ConstVariableValue::Unknown { universe: self.universe() }, val: ConstVariableValue::Unknown { universe: self.universe() },
}); });
self.tcx.mk_const(const_var_id, self.tcx.type_of(param.def_id)).into() self.tcx
.mk_const(const_var_id, self.tcx.bound_type_of(param.def_id).subst_identity())
.into()
} }
} }
} }

View file

@ -182,9 +182,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
| hir::ItemKind::TyAlias(..) | hir::ItemKind::TyAlias(..)
| hir::ItemKind::Enum(..) | hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..) | hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..) => { | hir::ItemKind::Union(..) => self.check_heap_type(
self.check_heap_type(cx, it.span, cx.tcx.type_of(it.owner_id)) cx,
} it.span,
cx.tcx.bound_type_of(it.owner_id).subst_identity(),
),
_ => (), _ => (),
} }
@ -192,7 +194,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
match it.kind { match it.kind {
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
for field in struct_def.fields() { for field in struct_def.fields() {
self.check_heap_type(cx, field.span, cx.tcx.type_of(field.def_id)); self.check_heap_type(
cx,
field.span,
cx.tcx.bound_type_of(field.def_id).subst_identity(),
);
} }
} }
_ => (), _ => (),
@ -589,7 +595,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
// If the method is an impl for an item with docs_hidden, don't doc. // If the method is an impl for an item with docs_hidden, don't doc.
MethodLateContext::PlainImpl => { MethodLateContext::PlainImpl => {
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
let impl_ty = cx.tcx.type_of(parent); let impl_ty = cx.tcx.bound_type_of(parent).subst_identity();
let outerdef = match impl_ty.kind() { let outerdef = match impl_ty.kind() {
ty::Adt(def, _) => Some(def.did()), ty::Adt(def, _) => Some(def.did()),
ty::Foreign(def_id) => Some(*def_id), ty::Foreign(def_id) => Some(*def_id),
@ -698,7 +704,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
// and recommending Copy might be a bad idea. // and recommending Copy might be a bad idea.
for field in def.all_fields() { for field in def.all_fields() {
let did = field.did; let did = field.did;
if cx.tcx.type_of(did).is_unsafe_ptr() { if cx.tcx.bound_type_of(did).subst_identity().is_unsafe_ptr() {
return; return;
} }
} }
@ -798,7 +804,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
if self.impling_types.is_none() { if self.impling_types.is_none() {
let mut impls = LocalDefIdSet::default(); let mut impls = LocalDefIdSet::default();
cx.tcx.for_each_impl(debug, |d| { cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { if let Some(ty_def) = cx.tcx.bound_type_of(d).subst_identity().ty_adt_def() {
if let Some(def_id) = ty_def.did().as_local() { if let Some(def_id) = ty_def.did().as_local() {
impls.insert(def_id); impls.insert(def_id);
} }
@ -2852,8 +2858,8 @@ impl ClashingExternDeclarations {
structurally_same_type_impl( structurally_same_type_impl(
seen_types, seen_types,
cx, cx,
tcx.type_of(a_did), tcx.bound_type_of(a_did).subst_identity(),
tcx.type_of(b_did), tcx.bound_type_of(b_did).subst_identity(),
ckind, ckind,
) )
}, },
@ -2953,8 +2959,8 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
if let ForeignItemKind::Fn(..) = this_fi.kind { if let ForeignItemKind::Fn(..) = this_fi.kind {
let tcx = cx.tcx; let tcx = cx.tcx;
if let Some(existing_did) = self.insert(tcx, this_fi) { if let Some(existing_did) = self.insert(tcx, this_fi) {
let existing_decl_ty = tcx.type_of(existing_did); let existing_decl_ty = tcx.bound_type_of(existing_did).skip_binder();
let this_decl_ty = tcx.type_of(this_fi.owner_id); let this_decl_ty = tcx.bound_type_of(this_fi.owner_id).subst_identity();
debug!( debug!(
"ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}", "ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}",
existing_did, existing_decl_ty, this_fi.owner_id, this_decl_ty existing_did, existing_decl_ty, this_fi.owner_id, this_decl_ty

View file

@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
// `Deref` is being implemented for `t` // `Deref` is being implemented for `t`
if let hir::ItemKind::Impl(impl_) = item.kind if let hir::ItemKind::Impl(impl_) = item.kind
&& let Some(trait_) = &impl_.of_trait && let Some(trait_) = &impl_.of_trait
&& let t = cx.tcx.type_of(item.owner_id) && let t = cx.tcx.bound_type_of(item.owner_id).subst_identity()
&& let opt_did @ Some(did) = trait_.trait_def_id() && let opt_did @ Some(did) = trait_.trait_def_id()
&& opt_did == cx.tcx.lang_items().deref_trait() && opt_did == cx.tcx.lang_items().deref_trait()
// `t` is `dyn t_principal` // `t` is `dyn t_principal`

View file

@ -216,7 +216,7 @@ fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, path: &Path<'_>) -> Option<String> {
} }
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait. // Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => { Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => {
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() { if let ty::Adt(adt, substs) = cx.tcx.bound_type_of(did).subst_identity().kind() {
if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(adt.did()) if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(adt.did())
{ {
// NOTE: This path is currently unreachable as `Ty<'tcx>` is // NOTE: This path is currently unreachable as `Ty<'tcx>` is

View file

@ -50,7 +50,7 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
return Some(format!("{}{}", name, gen_args(cx, path_segment))); return Some(format!("{}{}", name, gen_args(cx, path_segment)));
} }
Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => { Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => {
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() { if let ty::Adt(adt, substs) = cx.tcx.bound_type_of(did).subst_identity().kind() {
if cx.tcx.has_attr(adt.did(), sym::rustc_pass_by_value) { if cx.tcx.has_attr(adt.did(), sym::rustc_pass_by_value) {
return Some(cx.tcx.def_path_str_with_substs(adt.did(), substs)); return Some(cx.tcx.def_path_str_with_substs(adt.did(), substs));
} }

View file

@ -651,7 +651,7 @@ pub fn transparent_newtype_field<'a, 'tcx>(
) -> Option<&'a ty::FieldDef> { ) -> Option<&'a ty::FieldDef> {
let param_env = tcx.param_env(variant.def_id); let param_env = tcx.param_env(variant.def_id);
variant.fields.iter().find(|field| { variant.fields.iter().find(|field| {
let field_ty = tcx.type_of(field.did); let field_ty = tcx.bound_type_of(field.did).subst_identity();
let is_zst = tcx.layout_of(param_env.and(field_ty)).map_or(false, |layout| layout.is_zst()); let is_zst = tcx.layout_of(param_env.and(field_ty)).map_or(false, |layout| layout.is_zst());
!is_zst !is_zst
}) })
@ -1240,7 +1240,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} }
fn check_foreign_static(&mut self, id: hir::OwnerId, span: Span) { fn check_foreign_static(&mut self, id: hir::OwnerId, span: Span) {
let ty = self.cx.tcx.type_of(id); let ty = self.cx.tcx.bound_type_of(id).subst_identity();
self.check_type_for_ffi_and_report_errors(span, ty, true, false); self.check_type_for_ffi_and_report_errors(span, ty, true, false);
} }
@ -1301,7 +1301,7 @@ declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences { impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind { if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind {
let t = cx.tcx.type_of(it.owner_id); let t = cx.tcx.bound_type_of(it.owner_id).subst_identity();
let ty = cx.tcx.erase_regions(t); let ty = cx.tcx.erase_regions(t);
let Ok(layout) = cx.layout_of(ty) else { return }; let Ok(layout) = cx.layout_of(ty) else { return };
let Variants::Multiple { let Variants::Multiple {
@ -1421,7 +1421,7 @@ impl InvalidAtomicOrdering {
&& recognized_names.contains(&method_path.ident.name) && recognized_names.contains(&method_path.ident.name)
&& let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) && let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
&& let Some(impl_did) = cx.tcx.impl_of_method(m_def_id) && let Some(impl_did) = cx.tcx.impl_of_method(m_def_id)
&& let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() && let Some(adt) = cx.tcx.bound_type_of(impl_did).subst_identity().ty_adt_def()
// skip extension traits, only lint functions from the standard library // skip extension traits, only lint functions from the standard library
&& cx.tcx.trait_id_of_impl(impl_did).is_none() && cx.tcx.trait_id_of_impl(impl_did).is_none()
&& let parent = cx.tcx.parent(adt.did()) && let parent = cx.tcx.parent(adt.did())

View file

@ -498,7 +498,8 @@ impl<'tcx> Collector<'tcx> {
fn i686_arg_list_size(&self, item: &hir::ForeignItemRef) -> usize { fn i686_arg_list_size(&self, item: &hir::ForeignItemRef) -> usize {
let argument_types: &List<Ty<'_>> = self.tcx.erase_late_bound_regions( let argument_types: &List<Ty<'_>> = self.tcx.erase_late_bound_regions(
self.tcx self.tcx
.type_of(item.id.owner_id) .bound_type_of(item.id.owner_id)
.subst_identity()
.fn_sig(self.tcx) .fn_sig(self.tcx)
.inputs() .inputs()
.map_bound(|slice| self.tcx.mk_type_list(slice.iter())), .map_bound(|slice| self.tcx.mk_type_list(slice.iter())),

View file

@ -104,7 +104,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.impl_trait_ref(def_id) self.impl_trait_ref(def_id)
.map(|t| t.subst_identity()) .map(|t| t.subst_identity())
.map(ImplSubject::Trait) .map(ImplSubject::Trait)
.unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id))) .unwrap_or_else(|| ImplSubject::Inherent(self.bound_type_of(def_id).subst_identity()))
} }
} }

View file

@ -2497,7 +2497,7 @@ impl<'tcx> ConstantKind<'tcx> {
}; };
debug!("expr.kind: {:?}", expr.kind); debug!("expr.kind: {:?}", expr.kind);
let ty = tcx.type_of(def.def_id_for_type_of()); let ty = tcx.bound_type_of(def.def_id_for_type_of()).subst_identity();
debug!(?ty); debug!(?ty);
// FIXME(const_generics): We currently have to special case parameters because `min_const_generics` // FIXME(const_generics): We currently have to special case parameters because `min_const_generics`

View file

@ -165,7 +165,7 @@ impl<'tcx> Rvalue<'tcx> {
tcx.mk_array_with_const_len(operand.ty(local_decls, tcx), count) tcx.mk_array_with_const_len(operand.ty(local_decls, tcx), count)
} }
Rvalue::ThreadLocalRef(did) => { Rvalue::ThreadLocalRef(did) => {
let static_ty = tcx.type_of(did); let static_ty = tcx.bound_type_of(did).subst_identity();
if tcx.is_mutable_static(did) { if tcx.is_mutable_static(did) {
tcx.mk_mut_ptr(static_ty) tcx.mk_mut_ptr(static_ty)
} else if tcx.is_foreign_item(did) { } else if tcx.is_foreign_item(did) {

View file

@ -263,7 +263,9 @@ pub fn ancestors(
if let Some(reported) = specialization_graph.has_errored { if let Some(reported) = specialization_graph.has_errored {
Err(reported) Err(reported)
} else if let Err(reported) = tcx.type_of(start_from_impl).error_reported() { } else if let Err(reported) =
tcx.bound_type_of(start_from_impl).subst_identity().error_reported()
{
Err(reported) Err(reported)
} else { } else {
Ok(Ancestors { Ok(Ancestors {

View file

@ -83,7 +83,11 @@ impl AssocItem {
} }
ty::AssocKind::Type => format!("type {};", self.name), ty::AssocKind::Type => format!("type {};", self.name),
ty::AssocKind::Const => { ty::AssocKind::Const => {
format!("const {}: {:?};", self.name, tcx.type_of(self.def_id)) format!(
"const {}: {:?};",
self.name,
tcx.bound_type_of(self.def_id).subst_identity()
)
} }
} }
} }

View file

@ -71,7 +71,7 @@ impl<'tcx> Const<'tcx> {
let expr = &tcx.hir().body(body_id).value; let expr = &tcx.hir().body(body_id).value;
debug!(?expr); debug!(?expr);
let ty = tcx.type_of(def.def_id_for_type_of()); let ty = tcx.bound_type_of(def.def_id_for_type_of()).subst_identity();
match Self::try_eval_lit_or_param(tcx, ty, expr) { match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v, Some(v) => v,

View file

@ -1149,7 +1149,7 @@ impl<'tcx> TyCtxt<'tcx> {
_ => return None, _ => return None,
} }
let ret_ty = self.type_of(scope_def_id); let ret_ty = self.bound_type_of(scope_def_id).subst_identity();
match ret_ty.kind() { match ret_ty.kind() {
ty::FnDef(_, _) => { ty::FnDef(_, _) => {
let sig = ret_ty.fn_sig(self); let sig = ret_ty.fn_sig(self);
@ -2002,7 +2002,7 @@ impl<'tcx> TyCtxt<'tcx> {
GenericParamDefKind::Const { .. } => self GenericParamDefKind::Const { .. } => self
.mk_const( .mk_const(
ParamConst { index: param.index, name: param.name }, ParamConst { index: param.index, name: param.name },
self.type_of(param.def_id), self.bound_type_of(param.def_id).subst_identity(),
) )
.into(), .into(),
} }

View file

@ -481,8 +481,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => { Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id); let parent = self.tcx.parent(def_id);
let parent_ty = self.tcx.bound_type_of(parent).subst_identity();
if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent) if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *self.tcx.type_of(parent).kind() && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& parent_opaque_def_id == def_id && parent_opaque_def_id == def_id
{ {
// Okay // Okay
@ -564,8 +565,9 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => { Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id); let parent = self.tcx.parent(def_id);
let parent_ty = self.tcx.bound_type_of(parent).subst_identity();
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *self.tcx.type_of(parent).kind() && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& parent_opaque_def_id == def_id && parent_opaque_def_id == def_id
{ {
t t

View file

@ -87,7 +87,7 @@ impl<'tcx> VariantDef {
InhabitedPredicate::all( InhabitedPredicate::all(
tcx, tcx,
self.fields.iter().map(|field| { self.fields.iter().map(|field| {
let pred = tcx.type_of(field.did).inhabited_predicate(tcx); let pred = tcx.bound_type_of(field.did).subst_identity().inhabited_predicate(tcx);
if adt.is_enum() { if adt.is_enum() {
return pred; return pred;
} }

View file

@ -102,8 +102,8 @@ impl<'tcx> Instance<'tcx> {
/// Returns the `Ty` corresponding to this `Instance`, with generic substitutions applied and /// Returns the `Ty` corresponding to this `Instance`, with generic substitutions applied and
/// lifetimes erased, allowing a `ParamEnv` to be specified for use during normalization. /// lifetimes erased, allowing a `ParamEnv` to be specified for use during normalization.
pub fn ty(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Ty<'tcx> { pub fn ty(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Ty<'tcx> {
let ty = tcx.type_of(self.def.def_id()); let ty = tcx.bound_type_of(self.def.def_id());
tcx.subst_and_normalize_erasing_regions(self.substs, param_env, ty) tcx.subst_and_normalize_erasing_regions(self.substs, param_env, ty.skip_binder())
} }
/// Finds a crate that contains a monomorphization of this instance that /// Finds a crate that contains a monomorphization of this instance that
@ -662,7 +662,7 @@ fn polymorphize<'tcx>(
let def_id = instance.def_id(); let def_id = instance.def_id();
let upvars_ty = if tcx.is_closure(def_id) { let upvars_ty = if tcx.is_closure(def_id) {
Some(substs.as_closure().tupled_upvars_ty()) Some(substs.as_closure().tupled_upvars_ty())
} else if tcx.type_of(def_id).is_generator() { } else if tcx.bound_type_of(def_id).skip_binder().is_generator() {
Some(substs.as_generator().tupled_upvars_ty()) Some(substs.as_generator().tupled_upvars_ty())
} else { } else {
None None

View file

@ -754,7 +754,7 @@ pub trait PrettyPrinter<'tcx>:
// NOTE: I know we should check for NO_QUERIES here, but it's alright. // NOTE: I know we should check for NO_QUERIES here, but it's alright.
// `type_of` on a type alias or assoc type should never cause a cycle. // `type_of` on a type alias or assoc type should never cause a cycle.
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) =
*self.tcx().type_of(parent).kind() *self.tcx().bound_type_of(parent).subst_identity().kind()
{ {
if d == def_id { if d == def_id {
// If the type alias directly starts with the `impl` of the // If the type alias directly starts with the `impl` of the

View file

@ -225,7 +225,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
for &impl_def_id in tcx.hir().trait_impls(trait_id) { for &impl_def_id in tcx.hir().trait_impls(trait_id) {
let impl_def_id = impl_def_id.to_def_id(); let impl_def_id = impl_def_id.to_def_id();
let impl_self_ty = tcx.type_of(impl_def_id); let impl_self_ty = tcx.bound_type_of(impl_def_id).subst_identity();
if impl_self_ty.references_error() { if impl_self_ty.references_error() {
continue; continue;
} }

View file

@ -362,7 +362,7 @@ impl<'tcx> TyCtxt<'tcx> {
let drop_trait = self.lang_items().drop_trait()?; let drop_trait = self.lang_items().drop_trait()?;
self.ensure().coherent_trait(drop_trait); self.ensure().coherent_trait(drop_trait);
let ty = self.type_of(adt_did); let ty = self.bound_type_of(adt_did).subst_identity();
let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| { let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| {
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() { if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
if validate(self, impl_did).is_ok() { if validate(self, impl_did).is_ok() {
@ -415,12 +415,12 @@ impl<'tcx> TyCtxt<'tcx> {
// <P1, P2, P0>, and then look up which of the impl substs refer to // <P1, P2, P0>, and then look up which of the impl substs refer to
// parameters marked as pure. // parameters marked as pure.
let impl_substs = match *self.type_of(impl_def_id).kind() { let impl_substs = match *self.bound_type_of(impl_def_id).subst_identity().kind() {
ty::Adt(def_, substs) if def_ == def => substs, ty::Adt(def_, substs) if def_ == def => substs,
_ => bug!(), _ => bug!(),
}; };
let item_substs = match *self.type_of(def.did()).kind() { let item_substs = match *self.bound_type_of(def.did()).subst_identity().kind() {
ty::Adt(def_, substs) if def_ == def => substs, ty::Adt(def_, substs) if def_ == def => substs,
_ => bug!(), _ => bug!(),
}; };
@ -602,7 +602,10 @@ impl<'tcx> TyCtxt<'tcx> {
/// Get the type of the pointer to the static that we use in MIR. /// Get the type of the pointer to the static that we use in MIR.
pub fn static_ptr_ty(self, def_id: DefId) -> Ty<'tcx> { pub fn static_ptr_ty(self, def_id: DefId) -> Ty<'tcx> {
// Make sure that any constants in the static's type are evaluated. // Make sure that any constants in the static's type are evaluated.
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id)); let static_ty = self.normalize_erasing_regions(
ty::ParamEnv::empty(),
self.bound_type_of(def_id).subst_identity(),
);
// Make sure that accesses to unsafe statics end up using raw pointers. // Make sure that accesses to unsafe statics end up using raw pointers.
// For thread-locals, this needs to be kept in sync with `Rvalue::ty`. // For thread-locals, this needs to be kept in sync with `Rvalue::ty`.

View file

@ -643,7 +643,7 @@ fn construct_error(
let num_params = match body_owner_kind { let num_params = match body_owner_kind {
hir::BodyOwnerKind::Fn => tcx.fn_sig(def).skip_binder().inputs().skip_binder().len(), hir::BodyOwnerKind::Fn => tcx.fn_sig(def).skip_binder().inputs().skip_binder().len(),
hir::BodyOwnerKind::Closure => { hir::BodyOwnerKind::Closure => {
let ty = tcx.type_of(def); let ty = tcx.bound_type_of(def).subst_identity();
match ty.kind() { match ty.kind() {
ty::Closure(_, substs) => { ty::Closure(_, substs) => {
1 + substs.as_closure().sig().inputs().skip_binder().len() 1 + substs.as_closure().sig().inputs().skip_binder().len()

View file

@ -41,7 +41,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
// //
// Here we test for this function itself whether its ABI allows // Here we test for this function itself whether its ABI allows
// unwinding or not. // unwinding or not.
let body_ty = tcx.type_of(def_id); let body_ty = tcx.bound_type_of(def_id).skip_binder();
let body_abi = match body_ty.kind() { let body_abi = match body_ty.kind() {
ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), ty::FnDef(..) => body_ty.fn_sig(tcx).abi(),
ty::Closure(..) => Abi::RustCall, ty::Closure(..) => Abi::RustCall,

View file

@ -82,7 +82,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
return; return;
} }
let is_generator = tcx.type_of(def_id.to_def_id()).is_generator(); let is_generator = tcx.bound_type_of(def_id.to_def_id()).subst_identity().is_generator();
// FIXME(welseywiser) const prop doesn't work on generators because of query cycles // FIXME(welseywiser) const prop doesn't work on generators because of query cycles
// computing their layout. // computing their layout.
if is_generator { if is_generator {

View file

@ -57,7 +57,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
return; return;
} }
let is_generator = tcx.type_of(def_id.to_def_id()).is_generator(); let is_generator = tcx.bound_type_of(def_id.to_def_id()).subst_identity().is_generator();
// FIXME(welseywiser) const prop doesn't work on generators because of query cycles // FIXME(welseywiser) const prop doesn't work on generators because of query cycles
// computing their layout. // computing their layout.
if is_generator { if is_generator {

View file

@ -163,7 +163,7 @@ pub fn deduced_param_attrs<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [Ded
// Codegen won't use this information for anything if all the function parameters are passed // Codegen won't use this information for anything if all the function parameters are passed
// directly. Detect that and bail, for compilation speed. // directly. Detect that and bail, for compilation speed.
let fn_ty = tcx.type_of(def_id); let fn_ty = tcx.bound_type_of(def_id).subst_identity();
if matches!(fn_ty.kind(), ty::FnDef(..)) { if matches!(fn_ty.kind(), ty::FnDef(..)) {
if fn_ty if fn_ty
.fn_sig(tcx) .fn_sig(tcx)

View file

@ -93,7 +93,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
if let Some(def_id) = tcx.lang_items().owned_box() { if let Some(def_id) = tcx.lang_items().owned_box() {
let unique_did = tcx.adt_def(def_id).non_enum_variant().fields[0].did; let unique_did = tcx.adt_def(def_id).non_enum_variant().fields[0].did;
let Some(nonnull_def) = tcx.type_of(unique_did).ty_adt_def() else { let Some(nonnull_def) = tcx.bound_type_of(unique_did).subst_identity().ty_adt_def() else {
span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique") span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique")
}; };

View file

@ -49,7 +49,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
let body = &*tcx.mir_built(ty::WithOptConstParam::unknown(local_def_id)).borrow(); let body = &*tcx.mir_built(ty::WithOptConstParam::unknown(local_def_id)).borrow();
let body_ty = tcx.type_of(def_id); let body_ty = tcx.bound_type_of(def_id).skip_binder();
let body_abi = match body_ty.kind() { let body_abi = match body_ty.kind() {
ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), ty::FnDef(..) => body_ty.fn_sig(tcx).abi(),
ty::Closure(..) => Abi::RustCall, ty::Closure(..) => Abi::RustCall,

View file

@ -13,7 +13,7 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// Avoid query cycles (generators require optimized MIR for layout). // Avoid query cycles (generators require optimized MIR for layout).
if tcx.type_of(body.source.def_id()).is_generator() { if tcx.bound_type_of(body.source.def_id()).subst_identity().is_generator() {
return; return;
} }
let param_env = tcx.param_env(body.source.def_id()); let param_env = tcx.param_env(body.source.def_id());

View file

@ -692,7 +692,7 @@ fn build_call_shim<'tcx>(
// `FnDef` call with optional receiver. // `FnDef` call with optional receiver.
CallKind::Direct(def_id) => { CallKind::Direct(def_id) => {
let ty = tcx.type_of(def_id); let ty = tcx.bound_type_of(def_id).subst_identity();
( (
Operand::Constant(Box::new(Constant { Operand::Constant(Box::new(Constant {
span, span,

View file

@ -308,7 +308,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
let impl_self_ty = tcx.subst_and_normalize_erasing_regions( let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
instance.substs, instance.substs,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
tcx.type_of(impl_def_id), tcx.bound_type_of(impl_def_id).skip_binder(),
); );
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) { if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
return Some(def_id); return Some(def_id);

View file

@ -2174,7 +2174,7 @@ impl CheckAttrVisitor<'_> {
let tcx = self.tcx; let tcx = self.tcx;
if target == Target::Fn { if target == Target::Fn {
let Some(tokenstream) = tcx.get_diagnostic_item(sym::TokenStream) else {return}; let Some(tokenstream) = tcx.get_diagnostic_item(sym::TokenStream) else {return};
let tokenstream = tcx.type_of(tokenstream); let tokenstream = tcx.bound_type_of(tokenstream).subst_identity();
let id = hir_id.expect_owner(); let id = hir_id.expect_owner();
let hir_sig = tcx.hir().fn_sig_by_hir_id(hir_id).unwrap(); let hir_sig = tcx.hir().fn_sig_by_hir_id(hir_id).unwrap();

View file

@ -315,7 +315,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
//// This is done to handle the case where, for example, the static //// This is done to handle the case where, for example, the static
//// method of a private type is used, but the type itself is never //// method of a private type is used, but the type itself is never
//// called directly. //// called directly.
let self_ty = self.tcx.type_of(item); let self_ty = self.tcx.bound_type_of(item).subst_identity();
match *self_ty.kind() { match *self_ty.kind() {
ty::Adt(def, _) => self.check_def_id(def.did()), ty::Adt(def, _) => self.check_def_id(def.did()),
ty::Foreign(did) => self.check_def_id(did), ty::Foreign(did) => self.check_def_id(did),
@ -654,7 +654,7 @@ impl<'tcx> DeadVisitor<'tcx> {
if self.live_symbols.contains(&field.did.expect_local()) { if self.live_symbols.contains(&field.did.expect_local()) {
return ShouldWarnAboutField::No; return ShouldWarnAboutField::No;
} }
let field_type = self.tcx.type_of(field.did); let field_type = self.tcx.bound_type_of(field.did).subst_identity();
if field_type.is_phantom_data() { if field_type.is_phantom_data() {
return ShouldWarnAboutField::No; return ShouldWarnAboutField::No;
} }

View file

@ -29,7 +29,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) {
fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) { fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
let tcx = tcx; let tcx = tcx;
let param_env = tcx.param_env(item_def_id); let param_env = tcx.param_env(item_def_id);
let ty = tcx.type_of(item_def_id); let ty = tcx.bound_type_of(item_def_id).subst_identity();
match tcx.layout_of(param_env.and(ty)) { match tcx.layout_of(param_env.and(ty)) {
Ok(ty_layout) => { Ok(ty_layout) => {
// Check out the `#[rustc_layout(..)]` attribute to tell what to dump. // Check out the `#[rustc_layout(..)]` attribute to tell what to dump.

View file

@ -207,7 +207,7 @@ where
// so we need to visit the self type additionally. // so we need to visit the self type additionally.
if let Some(assoc_item) = tcx.opt_associated_item(def_id) { if let Some(assoc_item) = tcx.opt_associated_item(def_id) {
if let Some(impl_def_id) = assoc_item.impl_container(tcx) { if let Some(impl_def_id) = assoc_item.impl_container(tcx) {
tcx.type_of(impl_def_id).visit_with(self)?; tcx.bound_type_of(impl_def_id).subst_identity().visit_with(self)?;
} }
} }
} }
@ -341,7 +341,7 @@ trait VisibilityLike: Sized {
effective_visibilities: &EffectiveVisibilities, effective_visibilities: &EffectiveVisibilities,
) -> Self { ) -> Self {
let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX }; let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX };
find.visit(tcx.type_of(def_id)); find.visit(tcx.bound_type_of(def_id).subst_identity());
if let Some(trait_ref) = tcx.impl_trait_ref(def_id) { if let Some(trait_ref) = tcx.impl_trait_ref(def_id) {
find.visit_trait(trait_ref.subst_identity()); find.visit_trait(trait_ref.subst_identity());
} }
@ -837,11 +837,11 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
GenericParamDefKind::Lifetime => {} GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => { GenericParamDefKind::Type { has_default, .. } => {
if has_default { if has_default {
self.visit(self.ev.tcx.type_of(param.def_id)); self.visit(self.ev.tcx.bound_type_of(param.def_id).subst_identity());
} }
} }
GenericParamDefKind::Const { has_default } => { GenericParamDefKind::Const { has_default } => {
self.visit(self.ev.tcx.type_of(param.def_id)); self.visit(self.ev.tcx.bound_type_of(param.def_id).subst_identity());
if has_default { if has_default {
self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity()); self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity());
} }
@ -857,7 +857,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
} }
fn ty(&mut self) -> &mut Self { fn ty(&mut self) -> &mut Self {
self.visit(self.ev.tcx.type_of(self.item_def_id)); self.visit(self.ev.tcx.bound_type_of(self.item_def_id).subst_identity());
self self
} }
@ -1268,7 +1268,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Method calls have to be checked specially. // Method calls have to be checked specially.
self.span = segment.ident.span; self.span = segment.ident.span;
if let Some(def_id) = self.typeck_results().type_dependent_def_id(expr.hir_id) { if let Some(def_id) = self.typeck_results().type_dependent_def_id(expr.hir_id) {
if self.visit(self.tcx.type_of(def_id)).is_break() { if self.visit(self.tcx.bound_type_of(def_id).subst_identity()).is_break() {
return; return;
} }
} else { } else {
@ -1742,12 +1742,12 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
GenericParamDefKind::Lifetime => {} GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => { GenericParamDefKind::Type { has_default, .. } => {
if has_default { if has_default {
self.visit(self.tcx.type_of(param.def_id)); self.visit(self.tcx.bound_type_of(param.def_id).subst_identity());
} }
} }
// FIXME(generic_const_exprs): May want to look inside const here // FIXME(generic_const_exprs): May want to look inside const here
GenericParamDefKind::Const { .. } => { GenericParamDefKind::Const { .. } => {
self.visit(self.tcx.type_of(param.def_id)); self.visit(self.tcx.bound_type_of(param.def_id).subst_identity());
} }
} }
} }
@ -1774,7 +1774,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
} }
fn ty(&mut self) -> &mut Self { fn ty(&mut self) -> &mut Self {
self.visit(self.tcx.type_of(self.item_def_id)); self.visit(self.tcx.bound_type_of(self.item_def_id).subst_identity());
self self
} }

View file

@ -26,7 +26,7 @@ pub(super) fn mangle<'tcx>(
let key = tcx.def_key(ty_def_id); let key = tcx.def_key(ty_def_id);
match key.disambiguated_data.data { match key.disambiguated_data.data {
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => { DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
instance_ty = tcx.type_of(ty_def_id); instance_ty = tcx.bound_type_of(ty_def_id).subst_identity();
debug!(?instance_ty); debug!(?instance_ty);
break; break;
} }

View file

@ -696,7 +696,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
let variant = adt_def.non_enum_variant(); let variant = adt_def.non_enum_variant();
let param_env = tcx.param_env(variant.def_id); let param_env = tcx.param_env(variant.def_id);
let field = variant.fields.iter().find(|field| { let field = variant.fields.iter().find(|field| {
let ty = tcx.type_of(field.did); let ty = tcx.bound_type_of(field.did).subst_identity();
let is_zst = let is_zst =
tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst()); tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst());
!is_zst !is_zst

View file

@ -82,8 +82,8 @@ pub fn overlapping_impls(
(Some(a), Some(b)) => iter::zip(a.skip_binder().substs, b.skip_binder().substs) (Some(a), Some(b)) => iter::zip(a.skip_binder().substs, b.skip_binder().substs)
.all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)), .all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)),
(None, None) => { (None, None) => {
let self_ty1 = tcx.type_of(impl1_def_id); let self_ty1 = tcx.bound_type_of(impl1_def_id).skip_binder();
let self_ty2 = tcx.type_of(impl2_def_id); let self_ty2 = tcx.bound_type_of(impl2_def_id).skip_binder();
drcx.types_may_unify(self_ty1, self_ty2) drcx.types_may_unify(self_ty1, self_ty2)
} }
_ => bug!("unexpected impls: {impl1_def_id:?} {impl2_def_id:?}"), _ => bug!("unexpected impls: {impl1_def_id:?} {impl2_def_id:?}"),

View file

@ -2432,7 +2432,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}; };
let mut suggestions = vec![( let mut suggestions = vec![(
path.span.shrink_to_lo(), path.span.shrink_to_lo(),
format!("<{} as ", self.tcx.type_of(impl_def_id)) format!("<{} as ", self.tcx.bound_type_of(impl_def_id).subst_identity())
)]; )];
if let Some(generic_arg) = trait_path_segment.args { if let Some(generic_arg) = trait_path_segment.args {
let between_span = trait_path_segment.ident.span.between(generic_arg.span_ext); let between_span = trait_path_segment.ident.span.between(generic_arg.span_ext);

View file

@ -200,7 +200,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(def) = self_ty.ty_adt_def() { if let Some(def) = self_ty.ty_adt_def() {
// We also want to be able to select self's original // We also want to be able to select self's original
// signature with no type arguments resolved // signature with no type arguments resolved
flags.push((sym::_Self, Some(self.tcx.type_of(def.did()).to_string()))); flags.push((
sym::_Self,
Some(self.tcx.bound_type_of(def.did()).subst_identity().to_string()),
));
} }
for param in generics.params.iter() { for param in generics.params.iter() {
@ -218,7 +221,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(def) = param_ty.ty_adt_def() { if let Some(def) = param_ty.ty_adt_def() {
// We also want to be able to select the parameter's // We also want to be able to select the parameter's
// original signature with no type arguments resolved // original signature with no type arguments resolved
flags.push((name, Some(self.tcx.type_of(def.did()).to_string()))); flags.push((
name,
Some(self.tcx.bound_type_of(def.did()).subst_identity().to_string()),
));
} }
} }
} }
@ -251,7 +257,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(def) = aty.ty_adt_def() { if let Some(def) = aty.ty_adt_def() {
// We also want to be able to select the slice's type's original // We also want to be able to select the slice's type's original
// signature with no type arguments resolved // signature with no type arguments resolved
flags.push((sym::_Self, Some(format!("[{}]", self.tcx.type_of(def.did()))))); flags.push((
sym::_Self,
Some(format!("[{}]", self.tcx.bound_type_of(def.did()).subst_identity())),
));
} }
if aty.is_integral() { if aty.is_integral() {
flags.push((sym::_Self, Some("[{integral}]".to_string()))); flags.push((sym::_Self, Some("[{integral}]".to_string())));
@ -269,7 +278,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(def) = aty.ty_adt_def() { if let Some(def) = aty.ty_adt_def() {
// We also want to be able to select the array's type's original // We also want to be able to select the array's type's original
// signature with no type arguments resolved // signature with no type arguments resolved
let def_ty = self.tcx.type_of(def.did()); let def_ty = self.tcx.bound_type_of(def.did()).subst_identity();
flags.push((sym::_Self, Some(format!("[{def_ty}; _]")))); flags.push((sym::_Self, Some(format!("[{def_ty}; _]"))));
if let Some(n) = len { if let Some(n) = len {
flags.push((sym::_Self, Some(format!("[{def_ty}; {n}]")))); flags.push((sym::_Self, Some(format!("[{def_ty}; {n}]"))));

View file

@ -557,7 +557,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::INNERMOST, ty::INNERMOST,
ty::BoundVar::from_usize(bound_vars.len() - 1), ty::BoundVar::from_usize(bound_vars.len() - 1),
), ),
tcx.type_of(param.def_id), tcx.bound_type_of(param.def_id).subst_identity(),
) )
.into() .into()
} }

View file

@ -455,7 +455,13 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti
w.push('>'); w.push('>');
} }
write!(w, " {} for {}", trait_ref.print_only_trait_path(), tcx.type_of(impl_def_id)).unwrap(); write!(
w,
" {} for {}",
trait_ref.print_only_trait_path(),
tcx.bound_type_of(impl_def_id).subst_identity()
)
.unwrap();
// The predicates will contain default bounds like `T: Sized`. We need to // The predicates will contain default bounds like `T: Sized`. We need to
// remove these bounds, and add `T: ?Sized` to any untouched type parameters. // remove these bounds, and add `T: ?Sized` to any untouched type parameters.

View file

@ -246,7 +246,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
// Grab the ADT and the param we might need to calculate its layout // Grab the ADT and the param we might need to calculate its layout
let param_env = tcx.param_env(did); let param_env = tcx.param_env(did);
let adt_ty = tcx.type_of(did); let adt_ty = tcx.bound_type_of(did).subst_identity();
// The ADT is a 1-zst if it's a ZST and its alignment is 1. // The ADT is a 1-zst if it's a ZST and its alignment is 1.
// Mark the ADT as _not_ a 1-zst if there was a layout error. // Mark the ADT as _not_ a 1-zst if there was a layout error.
@ -738,7 +738,7 @@ fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> {
ty::GenericParamDefKind::Const { .. } => tcx ty::GenericParamDefKind::Const { .. } => tcx
.mk_const( .mk_const(
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)), ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
tcx.type_of(param.def_id), tcx.bound_type_of(param.def_id).subst_identity(),
) )
.into(), .into(),
}) })

View file

@ -308,7 +308,7 @@ pub(crate) fn adt_dtorck_constraint(
let mut result = DropckConstraint::empty(); let mut result = DropckConstraint::empty();
for field in def.all_fields() { for field in def.all_fields() {
let fty = tcx.type_of(field.did); let fty = tcx.bound_type_of(field.did).subst_identity();
dtorck_constraint_for_ty(tcx, span, fty, 0, fty, &mut result)?; dtorck_constraint_for_ty(tcx, span, fty, 0, fty, &mut result)?;
} }
result.outlives.extend(tcx.destructor_constraints(def)); result.outlives.extend(tcx.destructor_constraints(def));

View file

@ -28,7 +28,7 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
tcx.intern_type_list(&types) tcx.intern_type_list(&types)
} }
// Only the impl self type // Only the impl self type
None => tcx.intern_type_list(&[tcx.type_of(def_id)]), None => tcx.intern_type_list(&[tcx.bound_type_of(def_id).subst_identity()]),
} }
} }
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)), DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),

View file

@ -52,8 +52,9 @@ fn inner_resolve_instance<'tcx>(
tcx.normalize_erasing_regions(param_env, substs), tcx.normalize_erasing_regions(param_env, substs),
) )
} else { } else {
let ty = tcx.type_of(def.def_id_for_type_of()); let ty = tcx.bound_type_of(def.def_id_for_type_of());
let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, ty); let item_type =
tcx.subst_and_normalize_erasing_regions(substs, param_env, ty.skip_binder());
let def = match *item_type.kind() { let def = match *item_type.kind() {
ty::FnDef(def_id, ..) if tcx.is_intrinsic(def_id) => { ty::FnDef(def_id, ..) if tcx.is_intrinsic(def_id) => {

View file

@ -453,9 +453,10 @@ fn layout_of_uncached<'tcx>(
let param_env = tcx.param_env(def.did()); let param_env = tcx.param_env(def.did());
def.is_struct() def.is_struct()
&& match def.variants().iter().next().and_then(|x| x.fields.last()) { && match def.variants().iter().next().and_then(|x| x.fields.last()) {
Some(last_field) => { Some(last_field) => tcx
tcx.type_of(last_field.did).is_sized(tcx, param_env) .bound_type_of(last_field.did)
} .subst_identity()
.is_sized(tcx, param_env),
None => false, None => false,
} }
}, },

View file

@ -295,9 +295,15 @@ fn adt_drop_tys<'tcx>(
let adt_has_dtor = let adt_has_dtor =
|adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant); |adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant);
// `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_substs)` // `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_substs)`
drop_tys_helper(tcx, tcx.type_of(def_id), tcx.param_env(def_id), adt_has_dtor, false) drop_tys_helper(
.collect::<Result<Vec<_>, _>>() tcx,
.map(|components| tcx.intern_type_list(&components)) tcx.bound_type_of(def_id).subst_identity(),
tcx.param_env(def_id),
adt_has_dtor,
false,
)
.collect::<Result<Vec<_>, _>>()
.map(|components| tcx.intern_type_list(&components))
} }
// If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed // If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed
// a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters // a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters
@ -308,7 +314,7 @@ fn adt_significant_drop_tys(
) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { ) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
drop_tys_helper( drop_tys_helper(
tcx, tcx,
tcx.type_of(def_id), // identical to `tcx.make_adt(def, identity_substs)` tcx.bound_type_of(def_id).subst_identity(), // identical to `tcx.make_adt(def, identity_substs)`
tcx.param_env(def_id), tcx.param_env(def_id),
adt_consider_insignificant_dtor(tcx), adt_consider_insignificant_dtor(tcx),
true, true,

View file

@ -31,7 +31,7 @@ fn representability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Representability {
} }
Representability::Representable Representability::Representable
} }
DefKind::Field => representability_ty(tcx, tcx.type_of(def_id)), DefKind::Field => representability_ty(tcx, tcx.bound_type_of(def_id).subst_identity()),
def_kind => bug!("unexpected {def_kind:?}"), def_kind => bug!("unexpected {def_kind:?}"),
} }
} }
@ -91,7 +91,11 @@ fn params_in_repr(tcx: TyCtxt<'_>, def_id: DefId) -> BitSet<u32> {
let mut params_in_repr = BitSet::new_empty(generics.params.len()); let mut params_in_repr = BitSet::new_empty(generics.params.len());
for variant in adt_def.variants() { for variant in adt_def.variants() {
for field in variant.fields.iter() { for field in variant.fields.iter() {
params_in_repr_ty(tcx, tcx.type_of(field.did), &mut params_in_repr); params_in_repr_ty(
tcx,
tcx.bound_type_of(field.did).subst_identity(),
&mut params_in_repr,
);
} }
} }
params_in_repr params_in_repr

View file

@ -99,12 +99,10 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
} }
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
let result = tcx.mk_type_list( let result =
def.variants() tcx.mk_type_list(def.variants().iter().flat_map(|v| v.fields.last()).flat_map(|f| {
.iter() sized_constraint_for_ty(tcx, def, tcx.bound_type_of(f.did).subst_identity())
.flat_map(|v| v.fields.last()) }));
.flat_map(|f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did))),
);
debug!("adt_sized_constraint: {:?} => {:?}", def, result); debug!("adt_sized_constraint: {:?} => {:?}", def, result);
@ -299,7 +297,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica
// In an inherent impl, we assume that the receiver type and all its // In an inherent impl, we assume that the receiver type and all its
// constituents are well-formed. // constituents are well-formed.
NodeKind::InherentImpl => { NodeKind::InherentImpl => {
let self_ty = tcx.type_of(def_id); let self_ty = tcx.bound_type_of(def_id).subst_identity();
inputs.extend(self_ty.walk()); inputs.extend(self_ty.walk());
} }

View file

@ -137,7 +137,7 @@ where
pub(crate) fn get_auto_trait_impls(&mut self, item_def_id: DefId) -> Vec<Item> { pub(crate) fn get_auto_trait_impls(&mut self, item_def_id: DefId) -> Vec<Item> {
let tcx = self.cx.tcx; let tcx = self.cx.tcx;
let param_env = tcx.param_env(item_def_id); let param_env = tcx.param_env(item_def_id);
let ty = tcx.type_of(item_def_id); let ty = tcx.bound_type_of(item_def_id).subst_identity();
let f = auto_trait::AutoTraitFinder::new(tcx); let f = auto_trait::AutoTraitFinder::new(tcx);
debug!("get_auto_trait_impls({:?})", ty); debug!("get_auto_trait_impls({:?})", ty);

View file

@ -303,7 +303,11 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> { fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> {
let predicates = cx.tcx.explicit_predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
let type_ = clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(did)), cx, Some(did)); let type_ = clean_middle_ty(
ty::Binder::dummy(cx.tcx.bound_type_of(did).subst_identity()),
cx,
Some(did),
);
Box::new(clean::Typedef { Box::new(clean::Typedef {
type_, type_,
@ -414,7 +418,11 @@ pub(crate) fn build_impl(
let for_ = match &impl_item { let for_ = match &impl_item {
Some(impl_) => clean_ty(impl_.self_ty, cx), Some(impl_) => clean_ty(impl_.self_ty, cx),
None => clean_middle_ty(ty::Binder::dummy(tcx.type_of(did)), cx, Some(did)), None => clean_middle_ty(
ty::Binder::dummy(tcx.bound_type_of(did).subst_identity()),
cx,
Some(did),
),
}; };
// Only inline impl if the implementing type is // Only inline impl if the implementing type is
@ -652,14 +660,22 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant { fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
clean::Constant { clean::Constant {
type_: clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(def_id)), cx, Some(def_id)), type_: clean_middle_ty(
ty::Binder::dummy(cx.tcx.bound_type_of(def_id).subst_identity()),
cx,
Some(def_id),
),
kind: clean::ConstantKind::Extern { def_id }, kind: clean::ConstantKind::Extern { def_id },
} }
} }
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static { fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
clean::Static { clean::Static {
type_: clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(did)), cx, Some(did)), type_: clean_middle_ty(
ty::Binder::dummy(cx.tcx.bound_type_of(did).subst_identity()),
cx,
Some(did),
),
mutability: if mutable { Mutability::Mut } else { Mutability::Not }, mutability: if mutable { Mutability::Mut } else { Mutability::Not },
expr: None, expr: None,
} }

View file

@ -217,7 +217,11 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant { pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id(); let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id();
Constant { Constant {
type_: clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(def_id)), cx, Some(def_id)), type_: clean_middle_ty(
ty::Binder::dummy(cx.tcx.bound_type_of(def_id).subst_identity()),
cx,
Some(def_id),
),
kind: ConstantKind::Anonymous { body: constant.value.body }, kind: ConstantKind::Anonymous { body: constant.value.body },
} }
} }
@ -482,7 +486,7 @@ fn clean_generic_param_def<'tcx>(
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => { ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
let default = if has_default { let default = if has_default {
Some(clean_middle_ty( Some(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def.def_id)), ty::Binder::dummy(cx.tcx.bound_type_of(def.def_id).subst_identity()),
cx, cx,
Some(def.def_id), Some(def.def_id),
)) ))
@ -504,7 +508,7 @@ fn clean_generic_param_def<'tcx>(
GenericParamDefKind::Const { GenericParamDefKind::Const {
did: def.def_id, did: def.def_id,
ty: Box::new(clean_middle_ty( ty: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def.def_id)), ty::Binder::dummy(cx.tcx.bound_type_of(def.def_id).subst_identity()),
cx, cx,
Some(def.def_id), Some(def.def_id),
)), )),
@ -1214,7 +1218,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
let kind = match assoc_item.kind { let kind = match assoc_item.kind {
ty::AssocKind::Const => { ty::AssocKind::Const => {
let ty = clean_middle_ty( let ty = clean_middle_ty(
ty::Binder::dummy(tcx.type_of(assoc_item.def_id)), ty::Binder::dummy(tcx.bound_type_of(assoc_item.def_id).subst_identity()),
cx, cx,
Some(assoc_item.def_id), Some(assoc_item.def_id),
); );
@ -1253,7 +1257,9 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
if assoc_item.fn_has_self_parameter { if assoc_item.fn_has_self_parameter {
let self_ty = match assoc_item.container { let self_ty = match assoc_item.container {
ty::ImplContainer => tcx.type_of(assoc_item.container_id(tcx)), ty::ImplContainer => {
tcx.bound_type_of(assoc_item.container_id(tcx)).subst_identity()
}
ty::TraitContainer => tcx.types.self_param, ty::TraitContainer => tcx.types.self_param,
}; };
let self_arg_ty = sig.input(0).skip_binder(); let self_arg_ty = sig.input(0).skip_binder();
@ -1400,7 +1406,9 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
AssocTypeItem( AssocTypeItem(
Box::new(Typedef { Box::new(Typedef {
type_: clean_middle_ty( type_: clean_middle_ty(
ty::Binder::dummy(tcx.type_of(assoc_item.def_id)), ty::Binder::dummy(
tcx.bound_type_of(assoc_item.def_id).subst_identity(),
),
cx, cx,
Some(assoc_item.def_id), Some(assoc_item.def_id),
), ),
@ -1418,7 +1426,9 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
AssocTypeItem( AssocTypeItem(
Box::new(Typedef { Box::new(Typedef {
type_: clean_middle_ty( type_: clean_middle_ty(
ty::Binder::dummy(tcx.type_of(assoc_item.def_id)), ty::Binder::dummy(
tcx.bound_type_of(assoc_item.def_id).subst_identity(),
),
cx, cx,
Some(assoc_item.def_id), Some(assoc_item.def_id),
), ),
@ -1928,7 +1938,11 @@ pub(crate) fn clean_middle_field<'tcx>(field: &ty::FieldDef, cx: &mut DocContext
clean_field_with_def_id( clean_field_with_def_id(
field.did, field.did,
field.name, field.name,
clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(field.did)), cx, Some(field.did)), clean_middle_ty(
ty::Binder::dummy(cx.tcx.bound_type_of(field.did).subst_identity()),
cx,
Some(field.did),
),
cx, cx,
) )
} }
@ -2375,9 +2389,11 @@ fn clean_impl<'tcx>(
let for_ = clean_ty(impl_.self_ty, cx); let for_ = clean_ty(impl_.self_ty, cx);
let type_alias = for_.def_id(&cx.cache).and_then(|did| match tcx.def_kind(did) { let type_alias = for_.def_id(&cx.cache).and_then(|did| match tcx.def_kind(did) {
DefKind::TyAlias => { DefKind::TyAlias => Some(clean_middle_ty(
Some(clean_middle_ty(ty::Binder::dummy(tcx.type_of(did)), cx, Some(did))) ty::Binder::dummy(tcx.bound_type_of(did).subst_identity()),
} cx,
Some(did),
)),
_ => None, _ => None,
}); });
let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| { let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| {

View file

@ -266,7 +266,7 @@ pub(crate) fn print_evaluated_const(
underscores_and_type: bool, underscores_and_type: bool,
) -> Option<String> { ) -> Option<String> {
tcx.const_eval_poly(def_id).ok().and_then(|val| { tcx.const_eval_poly(def_id).ok().and_then(|val| {
let ty = tcx.type_of(def_id); let ty = tcx.bound_type_of(def_id).subst_identity();
match (val, ty.kind()) { match (val, ty.kind()) {
(_, &ty::Ref(..)) => None, (_, &ty::Ref(..)) => None,
(ConstValue::Scalar(_), &ty::Adt(_, _)) => None, (ConstValue::Scalar(_), &ty::Adt(_, _)) => None,

View file

@ -453,7 +453,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => { | clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
dids.insert(path.def_id()); dids.insert(path.def_id());
if let Some(generics) = path.generics() && if let Some(generics) = path.generics() &&
let ty::Adt(adt, _) = self.tcx.type_of(path.def_id()).kind() && let ty::Adt(adt, _) = self.tcx.bound_type_of(path.def_id()).subst_identity().kind() &&
adt.is_fundamental() { adt.is_fundamental() {
for ty in generics { for ty in generics {
if let Some(did) = ty.def_id(self.cache) { if let Some(did) = ty.def_id(self.cache) {

View file

@ -1855,7 +1855,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
let tcx = cx.tcx(); let tcx = cx.tcx();
let param_env = tcx.param_env(ty_def_id); let param_env = tcx.param_env(ty_def_id);
let ty = tcx.type_of(ty_def_id); let ty = tcx.bound_type_of(ty_def_id).subst_identity();
match tcx.layout_of(param_env.and(ty)) { match tcx.layout_of(param_env.and(ty)) {
Ok(ty_layout) => { Ok(ty_layout) => {
writeln!( writeln!(

View file

@ -293,7 +293,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
let ty_res = self.resolve_path(&path, TypeNS, item_id, module_id).ok_or_else(no_res)?; let ty_res = self.resolve_path(&path, TypeNS, item_id, module_id).ok_or_else(no_res)?;
match ty_res { match ty_res {
Res::Def(DefKind::Enum, did) => match tcx.type_of(did).kind() { Res::Def(DefKind::Enum, did) => match tcx.bound_type_of(did).subst_identity().kind() {
ty::Adt(def, _) if def.is_enum() => { ty::Adt(def, _) if def.is_enum() => {
if let Some(variant) = def.variants().iter().find(|v| v.name == variant_name) if let Some(variant) = def.variants().iter().find(|v| v.name == variant_name)
&& let Some(field) = variant.fields.iter().find(|f| f.name == variant_field_name) { && let Some(field) = variant.fields.iter().find(|f| f.name == variant_field_name) {
@ -471,7 +471,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
/// This is used for resolving type aliases. /// This is used for resolving type aliases.
fn def_id_to_res(&self, ty_id: DefId) -> Option<Res> { fn def_id_to_res(&self, ty_id: DefId) -> Option<Res> {
use PrimitiveType::*; use PrimitiveType::*;
Some(match *self.cx.tcx.type_of(ty_id).kind() { Some(match *self.cx.tcx.bound_type_of(ty_id).subst_identity().kind() {
ty::Bool => Res::Primitive(Bool), ty::Bool => Res::Primitive(Bool),
ty::Char => Res::Primitive(Char), ty::Char => Res::Primitive(Char),
ty::Int(ity) => Res::Primitive(ity.into()), ty::Int(ity) => Res::Primitive(ity.into()),
@ -572,7 +572,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
debug!("looking for associated item named {} for item {:?}", item_name, did); debug!("looking for associated item named {} for item {:?}", item_name, did);
// Checks if item_name is a variant of the `SomeItem` enum // Checks if item_name is a variant of the `SomeItem` enum
if ns == TypeNS && def_kind == DefKind::Enum { if ns == TypeNS && def_kind == DefKind::Enum {
match tcx.type_of(did).kind() { match tcx.bound_type_of(did).subst_identity().kind() {
ty::Adt(adt_def, _) => { ty::Adt(adt_def, _) => {
for variant in adt_def.variants() { for variant in adt_def.variants() {
if variant.name == item_name { if variant.name == item_name {
@ -606,7 +606,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
// something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn) // something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
.or_else(|| { .or_else(|| {
resolve_associated_trait_item( resolve_associated_trait_item(
tcx.type_of(did), tcx.bound_type_of(did).subst_identity(),
module_id, module_id,
item_name, item_name,
ns, ns,
@ -639,7 +639,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
// they also look like associated items (`module::Type::Variant`), // they also look like associated items (`module::Type::Variant`),
// because they are real Rust syntax (unlike the intra-doc links // because they are real Rust syntax (unlike the intra-doc links
// field syntax) and are handled by the compiler's resolver. // field syntax) and are handled by the compiler's resolver.
let def = match tcx.type_of(did).kind() { let def = match tcx.bound_type_of(did).subst_identity().kind() {
ty::Adt(def, _) if !def.is_enum() => def, ty::Adt(def, _) if !def.is_enum() => def,
_ => return None, _ => return None,
}; };

View file

@ -109,7 +109,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
// `Generics`. To avoid relying on the `impl` block, these // `Generics`. To avoid relying on the `impl` block, these
// things would need to be created from wholecloth, in a // things would need to be created from wholecloth, in a
// form that is valid for use in type inference. // form that is valid for use in type inference.
let ty = tcx.type_of(def_id); let ty = tcx.bound_type_of(def_id).subst_identity();
match ty.kind() { match ty.kind() {
ty::Slice(ty) ty::Slice(ty)
| ty::Ref(_, ty, _) | ty::Ref(_, ty, _)

View file

@ -169,7 +169,7 @@ where
}; };
let ident_span = path.ident.span; let ident_span = path.ident.span;
(tcx.type_of(def_id), call_span, ident_span) (tcx.bound_type_of(def_id).subst_identity(), call_span, ident_span)
} }
_ => { _ => {
return; return;

View file

@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
&& let Some(def_id) = cx.tcx.impl_of_method(def_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id)
&& cx.tcx.type_of(def_id).is_unsafe_ptr() && cx.tcx.bound_type_of(def_id).subst_identity().is_unsafe_ptr()
{ {
true true
} else { } else {

View file

@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
of_trait: Some(ref trait_ref), of_trait: Some(ref trait_ref),
.. ..
}) = item.kind; }) = item.kind;
let ty = cx.tcx.type_of(item.owner_id); let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity();
if is_copy(cx, ty); if is_copy(cx, ty);
if let Some(trait_id) = trait_ref.trait_def_id(); if let Some(trait_id) = trait_ref.trait_def_id();
if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id); if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id);

View file

@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
.fields .fields
.iter() .iter()
.all(|field| { .all(|field| {
is_copy(cx, cx.tcx.type_of(field.did)) is_copy(cx, cx.tcx.bound_type_of(field.did).subst_identity())
}); });
if !has_drop(cx, binding_type) || all_fields_are_copy; if !has_drop(cx, binding_type) || all_fields_are_copy;
then { then {

View file

@ -167,7 +167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
.iter() .iter()
.find_map(|f_def| { .find_map(|f_def| {
if f_def.ident(self.cx.tcx) == field.ident if f_def.ident(self.cx.tcx) == field.ident
{ Some(self.cx.tcx.type_of(f_def.did)) } { Some(self.cx.tcx.bound_type_of(f_def.did).subst_identity()) }
else { None } else { None }
}); });
self.ty_bounds.push(bound.into()); self.ty_bounds.push(bound.into());

View file

@ -735,7 +735,7 @@ fn walk_parents<'tcx>(
span, span,
.. ..
}) if span.ctxt() == ctxt => { }) if span.ctxt() == ctxt => {
let ty = cx.tcx.type_of(owner_id.def_id); let ty = cx.tcx.bound_type_of(owner_id.def_id).subst_identity();
Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx)) Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx))
}, },
@ -771,7 +771,7 @@ fn walk_parents<'tcx>(
}) => variant_of_res(cx, cx.qpath_res(path, *hir_id)) }) => variant_of_res(cx, cx.qpath_res(path, *hir_id))
.and_then(|variant| variant.fields.iter().find(|f| f.name == field.ident.name)) .and_then(|variant| variant.fields.iter().find(|f| f.name == field.ident.name))
.map(|field_def| { .map(|field_def| {
ty_auto_deref_stability(cx, cx.tcx.type_of(field_def.did), precedence).position_for_arg() ty_auto_deref_stability(cx, cx.tcx.bound_type_of(field_def.did).subst_identity(), precedence).position_for_arg()
}), }),
_ => None, _ => None,
}, },

View file

@ -184,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir); if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir);
if let ImplItemKind::Fn(_, b) = &impl_item.kind; if let ImplItemKind::Fn(_, b) = &impl_item.kind;
if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b); if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b);
if let Some(adt_def) = cx.tcx.type_of(item.owner_id).ty_adt_def(); if let Some(adt_def) = cx.tcx.bound_type_of(item.owner_id).subst_identity().ty_adt_def();
if let attrs = cx.tcx.hir().attrs(item.hir_id()); if let attrs = cx.tcx.hir().attrs(item.hir_id());
if !attrs.iter().any(|attr| attr.doc_str().is_some()); if !attrs.iter().any(|attr| attr.doc_str().is_some());
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);

Some files were not shown because too many files have changed in this diff Show more