Add bound_type_of

This commit is contained in:
Jack Huey 2022-05-08 15:12:56 -04:00
parent 319575ae8c
commit c92248ab9f
30 changed files with 90 additions and 83 deletions

View File

@ -23,9 +23,7 @@ use rustc_index::vec::{Idx, IndexVec};
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin}; use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::{ use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
self, EarlyBinder, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt,
};
use std::iter; use std::iter;
use crate::nll::ToRegionVid; use crate::nll::ToRegionVid;
@ -479,7 +477,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
.infcx .infcx
.tcx .tcx
.mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid())); .mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid()));
let va_list_ty = EarlyBinder(self.infcx.tcx.type_of(va_list_did)) let va_list_ty = self
.infcx
.tcx
.bound_type_of(va_list_did)
.subst(self.infcx.tcx, &[region.into()]); .subst(self.infcx.tcx, &[region.into()]);
unnormalized_input_tys = self.infcx.tcx.mk_type_list( unnormalized_input_tys = self.infcx.tcx.mk_type_list(

View File

@ -5,7 +5,6 @@ use rustc_hir::lang_items::LangItem;
use rustc_middle::mir::TerminatorKind; use rustc_middle::mir::TerminatorKind;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::EarlyBinder;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use crate::interpret::{ use crate::interpret::{
@ -94,10 +93,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let col = if loc_details.column { Scalar::from_u32(col) } else { Scalar::from_u32(0) }; let col = if loc_details.column { Scalar::from_u32(col) } else { Scalar::from_u32(0) };
// Allocate memory for `CallerLocation` struct. // Allocate memory for `CallerLocation` struct.
let loc_ty = EarlyBinder( let loc_ty = self
self.tcx.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None)), .tcx
) .bound_type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter())); .subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
let loc_layout = self.layout_of(loc_ty).unwrap(); let loc_layout = self.layout_of(loc_ty).unwrap();
// This can fail if rustc runs out of memory right here. Trying to emit an error would be // This can fail if rustc runs out of memory right here. Trying to emit an error would be
// pointless, since that would require allocating more memory than a Location. // pointless, since that would require allocating more memory than a Location.

View File

@ -968,7 +968,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
} }
GenericArgKind::Type(ty) => { GenericArgKind::Type(ty) => {
if EarlyBinder(self.tcx.type_of(def_id)).subst(self.tcx, substs) != ty { if self.tcx.bound_type_of(def_id).subst(self.tcx, substs) != ty {
break; break;
} }
} }

View File

@ -10,7 +10,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor}; use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor};
use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
use crate::ty::{self, EarlyBinder, List, Ty, TyCtxt}; use crate::ty::{self, List, Ty, TyCtxt};
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex}; use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
@ -2387,7 +2387,7 @@ impl<'tcx> Operand<'tcx> {
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
span: Span, span: Span,
) -> Self { ) -> Self {
let ty = EarlyBinder(tcx.type_of(def_id)).subst(tcx, substs); let ty = tcx.bound_type_of(def_id).subst(tcx, substs);
Operand::Constant(Box::new(Constant { Operand::Constant(Box::new(Constant {
span, span,
user_ty: None, user_ty: None,

View File

@ -5,7 +5,7 @@
use crate::mir::*; use crate::mir::*;
use crate::ty::subst::Subst; use crate::ty::subst::Subst;
use crate::ty::{self, EarlyBinder, Ty, TyCtxt}; use crate::ty::{self, Ty, TyCtxt};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_target::abi::VariantIdx; use rustc_target::abi::VariantIdx;
@ -203,7 +203,7 @@ impl<'tcx> Rvalue<'tcx> {
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64), AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))), AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))),
AggregateKind::Adt(did, _, substs, _, _) => { AggregateKind::Adt(did, _, substs, _, _) => {
EarlyBinder(tcx.type_of(did)).subst(tcx, substs) tcx.bound_type_of(did).subst(tcx, substs)
} }
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs), AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
AggregateKind::Generator(did, substs, movability) => { AggregateKind::Generator(did, substs, movability) => {

View File

@ -19,11 +19,10 @@ use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, Substs
use crate::ty::TyKind::*; use crate::ty::TyKind::*;
use crate::ty::{ use crate::ty::{
self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, EarlyBinder, ExistentialPredicate, ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, ExistentialPredicate, FloatTy,
FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List,
List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, Region,
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
UintTy,
}; };
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
@ -1605,7 +1604,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn caller_location_ty(self) -> Ty<'tcx> { pub fn caller_location_ty(self) -> Ty<'tcx> {
self.mk_imm_ref( self.mk_imm_ref(
self.lifetimes.re_static, self.lifetimes.re_static,
EarlyBinder(self.type_of(self.require_lang_item(LangItem::PanicLocation, None))) self.bound_type_of(self.require_lang_item(LangItem::PanicLocation, None))
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())), .subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
) )
} }
@ -2334,7 +2333,7 @@ impl<'tcx> TyCtxt<'tcx> {
ty_param.into() ty_param.into()
} else { } else {
assert!(has_default); assert!(has_default);
EarlyBinder(self.type_of(param.def_id)).subst(self, substs).into() self.bound_type_of(param.def_id).subst(self, substs).into()
} }
} }
}); });

View File

@ -1932,7 +1932,7 @@ impl<'tcx> FieldDef {
/// Returns the type of this field. The resulting type is not normalized. The `subst` is /// Returns the type of this field. The resulting type is not normalized. The `subst` is
/// typically obtained via the second field of [`TyKind::Adt`]. /// typically obtained via the second field of [`TyKind::Adt`].
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> { pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
EarlyBinder(tcx.type_of(self.did)).subst(tcx, subst) tcx.bound_type_of(self.did).subst(tcx, subst)
} }
/// Computes the `Ident` of this variant by looking up the `Span` /// Computes the `Ident` of this variant by looking up the `Span`

View File

@ -115,12 +115,16 @@ pub trait Printer<'tcx>: Sized {
DefPathData::Impl => { DefPathData::Impl => {
let generics = self.tcx().generics_of(def_id); let generics = self.tcx().generics_of(def_id);
let mut self_ty = self.tcx().type_of(def_id); let self_ty = self.tcx().bound_type_of(def_id);
let mut impl_trait_ref = self.tcx().impl_trait_ref(def_id); let impl_trait_ref = self.tcx().impl_trait_ref(def_id);
if substs.len() >= generics.count() { let (self_ty, impl_trait_ref) = if substs.len() >= generics.count() {
self_ty = EarlyBinder(self_ty).subst(self.tcx(), substs); (
impl_trait_ref = EarlyBinder(impl_trait_ref).subst(self.tcx(), substs); self_ty.subst(self.tcx(), substs),
} EarlyBinder(impl_trait_ref).subst(self.tcx(), substs),
)
} else {
(self_ty.0, impl_trait_ref)
};
self.print_impl_path(def_id, substs, self_ty, impl_trait_ref) self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
} }
@ -203,8 +207,7 @@ pub trait Printer<'tcx>: Sized {
has_default has_default
&& substs[param.index as usize] && substs[param.index as usize]
== GenericArg::from( == GenericArg::from(
EarlyBinder(self.tcx().type_of(param.def_id)) self.tcx().bound_type_of(param.def_id).subst(self.tcx(), substs),
.subst(self.tcx(), substs),
) )
} }
ty::GenericParamDefKind::Const { has_default } => { ty::GenericParamDefKind::Const { has_default } => {

View File

@ -7,7 +7,7 @@
use crate::mir::interpret::{get_slice_bytes, ConstValue, GlobalAlloc, Scalar}; use crate::mir::interpret::{get_slice_bytes, ConstValue, GlobalAlloc, Scalar};
use crate::ty::error::{ExpectedFound, TypeError}; use crate::ty::error::{ExpectedFound, TypeError};
use crate::ty::subst::{GenericArg, GenericArgKind, Subst, SubstsRef}; use crate::ty::subst::{GenericArg, GenericArgKind, Subst, SubstsRef};
use crate::ty::{self, EarlyBinder, ImplSubject, Term, Ty, TyCtxt, TypeFoldable}; use crate::ty::{self, ImplSubject, Term, Ty, TyCtxt, TypeFoldable};
use rustc_hir as ast; use rustc_hir as ast;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
@ -159,8 +159,8 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
let params = iter::zip(a_subst, b_subst).enumerate().map(|(i, (a, b))| { let params = iter::zip(a_subst, b_subst).enumerate().map(|(i, (a, b))| {
let variance = variances[i]; let variance = variances[i];
let variance_info = if variance == ty::Invariant { let variance_info = if variance == ty::Invariant {
let ty = *cached_ty let ty =
.get_or_insert_with(|| EarlyBinder(tcx.type_of(ty_def_id)).subst(tcx, a_subst)); *cached_ty.get_or_insert_with(|| tcx.bound_type_of(ty_def_id).subst(tcx, a_subst));
ty::VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() } ty::VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() }
} else { } else {
ty::VarianceDiagInfo::default() ty::VarianceDiagInfo::default()

View File

@ -2347,7 +2347,7 @@ impl<'tcx> Ty<'tcx> {
ty::Str | ty::Slice(_) => (tcx.types.usize, false), ty::Str | ty::Slice(_) => (tcx.types.usize, false),
ty::Dynamic(..) => { ty::Dynamic(..) => {
let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap(); let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap();
(EarlyBinder(tcx.type_of(dyn_metadata)).subst(tcx, &[tail.into()]), false) (tcx.bound_type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
}, },
// type parameters only have unit metadata if they're sized, so return true // type parameters only have unit metadata if they're sized, so return true

View File

@ -592,6 +592,10 @@ impl<'tcx> TyCtxt<'tcx> {
trace!(?expanded_type); trace!(?expanded_type);
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) } if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
} }
pub fn bound_type_of(self, def_id: DefId) -> EarlyBinder<Ty<'tcx>> {
EarlyBinder(self.type_of(def_id))
}
} }
struct OpaqueTypeExpander<'tcx> { struct OpaqueTypeExpander<'tcx> {
@ -623,8 +627,8 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) { let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
Some(expanded_ty) => *expanded_ty, Some(expanded_ty) => *expanded_ty,
None => { None => {
let generic_ty = self.tcx.type_of(def_id); let generic_ty = self.tcx.bound_type_of(def_id);
let concrete_ty = EarlyBinder(generic_ty).subst(self.tcx, substs); let concrete_ty = generic_ty.subst(self.tcx, substs);
let expanded_ty = self.fold_ty(concrete_ty); let expanded_ty = self.fold_ty(concrete_ty);
self.expanded_cache.insert((def_id, substs), expanded_ty); self.expanded_cache.insert((def_id, substs), expanded_ty);
expanded_ty expanded_ty

View File

@ -16,7 +16,7 @@ use rustc_middle::mir::*;
use rustc_middle::thir::*; use rustc_middle::thir::*;
use rustc_middle::ty::subst::{GenericArg, Subst}; use rustc_middle::ty::subst::{GenericArg, Subst};
use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, adjustment::PointerCast, EarlyBinder, Ty, TyCtxt}; use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span; use rustc_span::Span;
@ -834,8 +834,8 @@ fn trait_method<'tcx>(
.find(|item| item.kind == ty::AssocKind::Fn) .find(|item| item.kind == ty::AssocKind::Fn)
.expect("trait method not found"); .expect("trait method not found");
let method_ty = tcx.type_of(item.def_id); let method_ty = tcx.bound_type_of(item.def_id);
let method_ty = EarlyBinder(method_ty).subst(tcx, substs); let method_ty = method_ty.subst(tcx, substs);
ConstantKind::zero_sized(method_ty) ConstantKind::zero_sized(method_ty)
} }

View File

@ -14,7 +14,7 @@ use rustc_middle::middle::region;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::thir::{BindingMode, Expr, ExprId, LintLevel, PatKind, Thir}; use rustc_middle::thir::{BindingMode, Expr, ExprId, LintLevel, PatKind, Thir};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeckResults}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeckResults};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -177,8 +177,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
let ty = if fn_sig.c_variadic && index == fn_sig.inputs().len() { let ty = if fn_sig.c_variadic && index == fn_sig.inputs().len() {
let va_list_did = tcx.require_lang_item(LangItem::VaList, Some(arg.span)); let va_list_did = tcx.require_lang_item(LangItem::VaList, Some(arg.span));
EarlyBinder(tcx.type_of(va_list_did)) tcx.bound_type_of(va_list_did).subst(tcx, &[tcx.lifetimes.re_erased.into()])
.subst(tcx, &[tcx.lifetimes.re_erased.into()])
} else { } else {
fn_sig.inputs()[index] fn_sig.inputs()[index]
}; };

View File

@ -62,7 +62,7 @@ use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::GeneratorSubsts; use rustc_middle::ty::GeneratorSubsts;
use rustc_middle::ty::{self, AdtDef, EarlyBinder, Ty, TyCtxt}; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
use rustc_mir_dataflow::impls::{ use rustc_mir_dataflow::impls::{
MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive,
}; };
@ -245,7 +245,9 @@ impl<'tcx> TransformVisitor<'tcx> {
) -> impl Iterator<Item = Statement<'tcx>> { ) -> impl Iterator<Item = Statement<'tcx>> {
let kind = AggregateKind::Adt(self.state_adt_ref.did(), idx, self.state_substs, None, None); let kind = AggregateKind::Adt(self.state_adt_ref.did(), idx, self.state_substs, None, None);
assert_eq!(self.state_adt_ref.variant(idx).fields.len(), 1); assert_eq!(self.state_adt_ref.variant(idx).fields.len(), 1);
let ty = EarlyBinder(self.tcx.type_of(self.state_adt_ref.variant(idx).fields[0].did)) let ty = self
.tcx
.bound_type_of(self.state_adt_ref.variant(idx).fields[0].did)
.subst(self.tcx, self.state_substs); .subst(self.tcx, self.state_substs);
expand_aggregate( expand_aggregate(
Place::return_place(), Place::return_place(),

View File

@ -135,7 +135,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
let header = ty::ImplHeader { let header = ty::ImplHeader {
impl_def_id, impl_def_id,
self_ty: EarlyBinder(tcx.type_of(impl_def_id)).subst(tcx, impl_substs), self_ty: tcx.bound_type_of(impl_def_id).subst(tcx, impl_substs),
trait_ref: EarlyBinder(tcx.impl_trait_ref(impl_def_id)).subst(tcx, impl_substs), trait_ref: EarlyBinder(tcx.impl_trait_ref(impl_def_id)).subst(tcx, impl_substs),
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates, predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
}; };

View File

@ -515,8 +515,8 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
} }
let substs = substs.super_fold_with(self); let substs = substs.super_fold_with(self);
let generic_ty = self.tcx().type_of(def_id); let generic_ty = self.tcx().bound_type_of(def_id);
let concrete_ty = EarlyBinder(generic_ty).subst(self.tcx(), substs); let concrete_ty = generic_ty.subst(self.tcx(), substs);
self.depth += 1; self.depth += 1;
let folded_ty = self.fold_ty(concrete_ty); let folded_ty = self.fold_ty(concrete_ty);
self.depth -= 1; self.depth -= 1;

View File

@ -14,7 +14,7 @@ use rustc_infer::traits::Normalized;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder}; use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitor}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
use std::ops::ControlFlow; use std::ops::ControlFlow;
@ -217,8 +217,8 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
self.infcx.report_overflow_error(&obligation, true); self.infcx.report_overflow_error(&obligation, true);
} }
let generic_ty = self.tcx().type_of(def_id); let generic_ty = self.tcx().bound_type_of(def_id);
let concrete_ty = EarlyBinder(generic_ty).subst(self.tcx(), substs); let concrete_ty = generic_ty.subst(self.tcx(), substs);
self.anon_depth += 1; self.anon_depth += 1;
if concrete_ty == ty { if concrete_ty == ty {
bug!( bug!(

View File

@ -1006,10 +1006,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// The last field of the structure has to exist and contain type/const parameters. // The last field of the structure has to exist and contain type/const parameters.
let (tail_field, prefix_fields) = let (tail_field, prefix_fields) =
def.non_enum_variant().fields.split_last().ok_or(Unimplemented)?; def.non_enum_variant().fields.split_last().ok_or(Unimplemented)?;
let tail_field_ty = tcx.type_of(tail_field.did); let tail_field_ty = tcx.bound_type_of(tail_field.did);
let mut unsizing_params = GrowableBitSet::new_empty(); let mut unsizing_params = GrowableBitSet::new_empty();
for arg in tail_field_ty.walk() { for arg in tail_field_ty.0.walk() {
if let Some(i) = maybe_unsizing_param_idx(arg) { if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i); unsizing_params.insert(i);
} }
@ -1030,8 +1030,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`. // Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`.
let source_tail = EarlyBinder(tail_field_ty).subst(tcx, substs_a); let source_tail = tail_field_ty.subst(tcx, substs_a);
let target_tail = EarlyBinder(tail_field_ty).subst(tcx, substs_b); let target_tail = tail_field_ty.subst(tcx, substs_b);
// Check that the source struct with the target's // Check that the source struct with the target's
// unsizing parameters is equal to the target. // unsizing parameters is equal to the target.

View File

@ -1960,7 +1960,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// We can resolve the `impl Trait` to its concrete type, // We can resolve the `impl Trait` to its concrete type,
// which enforces a DAG between the functions requiring // which enforces a DAG between the functions requiring
// the auto trait bounds in question. // the auto trait bounds in question.
t.rebind(vec![EarlyBinder(self.tcx().type_of(def_id)).subst(self.tcx(), substs)]) t.rebind(vec![self.tcx().bound_type_of(def_id).subst(self.tcx(), substs)])
} }
} }
} }

View File

@ -464,7 +464,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let trait_item_id = assoc_item.trait_item_def_id.expect("assoc_ty with no trait version"); let trait_item_id = assoc_item.trait_item_def_id.expect("assoc_ty with no trait version");
let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
let binders = binders_for(self.interner, bound_vars); let binders = binders_for(self.interner, bound_vars);
let ty = EarlyBinder(self.interner.tcx.type_of(def_id)) let ty = self
.interner
.tcx
.bound_type_of(def_id)
.subst(self.interner.tcx, bound_vars) .subst(self.interner.tcx, bound_vars)
.lower_into(self.interner); .lower_into(self.interner);

View File

@ -237,7 +237,7 @@ fn drop_tys_helper<'tcx>(
Ok(Vec::new()) Ok(Vec::new())
} else { } else {
let field_tys = adt_def.all_fields().map(|field| { let field_tys = adt_def.all_fields().map(|field| {
let r = EarlyBinder(tcx.type_of(field.did)).subst(tcx, substs); let r = tcx.bound_type_of(field.did).subst(tcx, substs);
debug!("drop_tys_helper: Subst into {:?} with {:?} gettng {:?}", field, substs, r); debug!("drop_tys_helper: Subst into {:?} with {:?} gettng {:?}", field, substs, r);
r r
}); });

View File

@ -444,7 +444,7 @@ pub fn conservative_is_privately_uninhabited_raw<'tcx>(
// one uninhabited field. // one uninhabited field.
def.variants().iter().all(|var| { def.variants().iter().all(|var| {
var.fields.iter().any(|field| { var.fields.iter().any(|field| {
let ty = EarlyBinder(tcx.type_of(field.did)).subst(tcx, substs); let ty = tcx.bound_type_of(field.did).subst(tcx, substs);
tcx.conservative_is_privately_uninhabited(param_env.and(ty)) tcx.conservative_is_privately_uninhabited(param_env.and(ty))
}) })
}) })

View File

@ -18,7 +18,7 @@ use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES}; use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, EarlyBinder, ParamEnv, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{self, ParamEnv, ToPredicate, Ty, TyCtxt};
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS}; use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{self, Span}; use rustc_span::{self, Span};
@ -171,7 +171,7 @@ pub(super) fn check_fn<'a, 'tcx>(
let va_list_did = tcx.require_lang_item(LangItem::VaList, Some(span)); let va_list_did = tcx.require_lang_item(LangItem::VaList, Some(span));
let region = fcx.next_region_var(RegionVariableOrigin::MiscVariable(span)); let region = fcx.next_region_var(RegionVariableOrigin::MiscVariable(span));
Some(EarlyBinder(tcx.type_of(va_list_did)).subst(tcx, &[region.into()])) Some(tcx.bound_type_of(va_list_did).subst(tcx, &[region.into()]))
} else { } else {
None None
}; };
@ -655,7 +655,7 @@ fn check_opaque_meets_bounds<'tcx>(
span: Span, span: Span,
origin: &hir::OpaqueTyOrigin, origin: &hir::OpaqueTyOrigin,
) { ) {
let hidden_type = EarlyBinder(tcx.type_of(def_id)).subst(tcx, substs); let hidden_type = tcx.bound_type_of(def_id.to_def_id()).subst(tcx, substs);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let defining_use_anchor = match *origin { let defining_use_anchor = match *origin {

View File

@ -1066,7 +1066,7 @@ crate fn compare_const_impl<'tcx>(
// 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_c.def_id); let impl_ty = tcx.type_of(impl_c.def_id);
let trait_ty = EarlyBinder(tcx.type_of(trait_c.def_id)).subst(tcx, trait_to_impl_substs); let trait_ty = tcx.bound_type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs);
let mut cause = ObligationCause::new( let mut cause = ObligationCause::new(
impl_c_span, impl_c_span,
impl_c_hir_id, impl_c_hir_id,

View File

@ -838,12 +838,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let def_kind = self.tcx.def_kind(def_id); let def_kind = self.tcx.def_kind(def_id);
let item_ty = if let DefKind::Variant = def_kind { let item_ty = if let DefKind::Variant = def_kind {
self.tcx.type_of(self.tcx.parent(def_id)) self.tcx.bound_type_of(self.tcx.parent(def_id))
} else { } else {
self.tcx.type_of(def_id) self.tcx.bound_type_of(def_id)
}; };
let substs = self.infcx.fresh_substs_for_item(span, def_id); let substs = self.infcx.fresh_substs_for_item(span, def_id);
let ty = EarlyBinder(item_ty).subst(self.tcx, substs); let ty = item_ty.subst(self.tcx, substs);
self.write_resolution(hir_id, Ok((def_kind, def_id))); self.write_resolution(hir_id, Ok((def_kind, def_id)));
self.add_required_obligations_with_code( self.add_required_obligations_with_code(
@ -1401,12 +1401,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If we have a default, then we it doesn't matter that we're not // If we have a default, then we it doesn't matter that we're not
// inferring the type arguments: we provide the default where any // inferring the type arguments: we provide the default where any
// is missing. // is missing.
let default = tcx.type_of(param.def_id); let default = tcx.bound_type_of(param.def_id);
self.fcx self.fcx
.normalize_ty( .normalize_ty(self.span, default.subst(tcx, substs.unwrap()))
self.span,
EarlyBinder(default).subst(tcx, substs.unwrap()),
)
.into() .into()
} else { } else {
// If no type arguments were provided, we have to infer them. // If no type arguments were provided, we have to infer them.

View File

@ -11,7 +11,7 @@ use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, EarlyBinder, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -129,7 +129,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv }, ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
)); ));
let va_list_ty = EarlyBinder(tcx.type_of(did)).subst(tcx, &[region.into()]); let va_list_ty = tcx.bound_type_of(did).subst(tcx, &[region.into()]);
(tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) (tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
}) })
}; };

View File

@ -15,14 +15,14 @@ crate struct BlanketImplFinder<'a, 'tcx> {
impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
crate fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> { crate fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> {
let param_env = self.cx.tcx.param_env(item_def_id); let param_env = self.cx.tcx.param_env(item_def_id);
let ty = self.cx.tcx.type_of(item_def_id); let ty = self.cx.tcx.bound_type_of(item_def_id);
trace!("get_blanket_impls({:?})", ty); trace!("get_blanket_impls({:?})", ty);
let mut impls = Vec::new(); let mut impls = Vec::new();
self.cx.with_all_traits(|cx, all_traits| { self.cx.with_all_traits(|cx, all_traits| {
for &trait_def_id in all_traits { for &trait_def_id in all_traits {
if !cx.cache.access_levels.is_public(trait_def_id) if !cx.cache.access_levels.is_public(trait_def_id)
|| cx.generated_synthetics.get(&(ty, trait_def_id)).is_some() || cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
{ {
continue; continue;
} }
@ -38,7 +38,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
let is_param = matches!(trait_ref.self_ty().kind(), ty::Param(_)); let is_param = matches!(trait_ref.self_ty().kind(), ty::Param(_));
let may_apply = is_param && cx.tcx.infer_ctxt().enter(|infcx| { let may_apply = is_param && cx.tcx.infer_ctxt().enter(|infcx| {
let substs = infcx.fresh_substs_for_item(DUMMY_SP, item_def_id); let substs = infcx.fresh_substs_for_item(DUMMY_SP, item_def_id);
let ty = EarlyBinder(ty).subst(infcx.tcx, substs); let ty = ty.subst(infcx.tcx, substs);
let param_env = EarlyBinder(param_env).subst(infcx.tcx, substs); let param_env = EarlyBinder(param_env).subst(infcx.tcx, substs);
let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
@ -99,7 +99,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
continue; continue;
} }
cx.generated_synthetics.insert((ty, trait_def_id)); cx.generated_synthetics.insert((ty.0, trait_def_id));
impls.push(Item { impls.push(Item {
name: None, name: None,
@ -116,7 +116,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
// FIXME(eddyb) compute both `trait_` and `for_` from // FIXME(eddyb) compute both `trait_` and `for_` from
// the post-inference `trait_ref`, as it's more accurate. // the post-inference `trait_ref`, as it's more accurate.
trait_: Some(trait_ref.clean(cx)), trait_: Some(trait_ref.clean(cx)),
for_: ty.clean(cx), for_: ty.0.clean(cx),
items: cx.tcx items: cx.tcx
.associated_items(impl_def_id) .associated_items(impl_def_id)
.in_definition_order() .in_definition_order()

View File

@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::binding::BindingMode;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, ClosureKind, EarlyBinder, Ty, TypeFoldable}; use rustc_middle::ty::{self, ClosureKind, Ty, TypeFoldable};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
if check_inputs(cx, body.params, args); if check_inputs(cx, body.params, args);
let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap();
let substs = cx.typeck_results().node_substs(body.value.hir_id); let substs = cx.typeck_results().node_substs(body.value.hir_id);
let call_ty = EarlyBinder(cx.tcx.type_of(method_def_id)).subst(cx.tcx, substs); let call_ty = cx.tcx.bound_type_of(method_def_id).subst(cx.tcx, substs);
if check_sig(cx, closure_ty, call_ty); if check_sig(cx, closure_ty, call_ty);
then { then {
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| { span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| {

View File

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint;
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, EarlyBinder, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::iter; use std::iter;
@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
ExprKind::MethodCall(path, arguments, _) => { ExprKind::MethodCall(path, arguments, _) => {
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
let substs = cx.typeck_results().node_substs(e.hir_id); let substs = cx.typeck_results().node_substs(e.hir_id);
let method_type = EarlyBinder(cx.tcx.type_of(def_id)).subst(cx.tcx, substs); let method_type = cx.tcx.bound_type_of(def_id).subst(cx.tcx, substs);
check_arguments(cx, arguments, method_type, path.ident.as_str(), "method"); check_arguments(cx, arguments, method_type, path.ident.as_str(), "method");
}, },
_ => (), _ => (),

View File

@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
use rustc_hir::Expr; use rustc_hir::Expr;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::{self, EarlyBinder, IntTy, Ty, TypeAndMut, UintTy}; use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy};
use rustc_span::Span; use rustc_span::Span;
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
@ -307,7 +307,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
.non_enum_variant() .non_enum_variant()
.fields .fields
.iter() .iter()
.map(|f| EarlyBinder(cx.tcx.type_of(f.did)).subst(cx.tcx, substs)); .map(|f| cx.tcx.bound_type_of(f.did).subst(cx.tcx, substs));
let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else { let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else {
return ReducedTy::TypeErasure; return ReducedTy::TypeErasure;
}; };