1
Fork 0

Introduce EarlyBinder

This commit is contained in:
Jack Huey 2022-05-08 01:17:58 -04:00
parent ecd44958e0
commit 319575ae8c
66 changed files with 339 additions and 234 deletions

View file

@ -13,7 +13,9 @@ use rustc_middle::mir::{
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
}; };
use rustc_middle::ty::{self, subst::Subst, suggest_constraining_type_params, PredicateKind, Ty}; use rustc_middle::ty::{
self, subst::Subst, suggest_constraining_type_params, EarlyBinder, PredicateKind, Ty,
};
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
@ -336,7 +338,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let find_fn_kind_from_did = |predicates: &[(ty::Predicate<'tcx>, Span)], substs| { let find_fn_kind_from_did = |predicates: &[(ty::Predicate<'tcx>, Span)], substs| {
predicates.iter().find_map(|(pred, _)| { predicates.iter().find_map(|(pred, _)| {
let pred = if let Some(substs) = substs { let pred = if let Some(substs) = substs {
pred.subst(tcx, substs).kind().skip_binder() EarlyBinder(*pred).subst(tcx, substs).kind().skip_binder()
} else { } else {
pred.kind().skip_binder() pred.kind().skip_binder()
}; };

View file

@ -23,7 +23,9 @@ 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::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt}; use rustc_middle::ty::{
self, EarlyBinder, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt,
};
use std::iter; use std::iter;
use crate::nll::ToRegionVid; use crate::nll::ToRegionVid;
@ -477,8 +479,8 @@ 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 = let va_list_ty = EarlyBinder(self.infcx.tcx.type_of(va_list_did))
self.infcx.tcx.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(
unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)), unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)),

View file

@ -13,7 +13,7 @@ use rustc_middle::mir::pretty::display_allocation;
use rustc_middle::traits::Reveal; use rustc_middle::traits::Reveal;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, subst::Subst, TyCtxt}; use rustc_middle::ty::{self, subst::Subst, EarlyBinder, TyCtxt};
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
use rustc_target::abi::{self, Abi}; use rustc_target::abi::{self, Abi};
use std::borrow::Cow; use std::borrow::Cow;
@ -47,7 +47,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
"Unexpected DefKind: {:?}", "Unexpected DefKind: {:?}",
ecx.tcx.def_kind(cid.instance.def_id()) ecx.tcx.def_kind(cid.instance.def_id())
); );
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?; let layout = ecx.layout_of(EarlyBinder(body.return_ty()).subst(tcx, cid.instance.substs))?;
assert!(!layout.is_unsized()); assert!(!layout.is_unsized());
let ret = ecx.allocate(layout, MemoryKind::Stack)?; let ret = ecx.allocate(layout, MemoryKind::Stack)?;

View file

@ -5,6 +5,7 @@ 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::{
@ -93,9 +94,9 @@ 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 = self let loc_ty = EarlyBinder(
.tcx self.tcx.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None)),
.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

View file

@ -70,7 +70,7 @@ use rustc_middle::ty::{
self, self,
error::TypeError, error::TypeError,
subst::{GenericArgKind, Subst, SubstsRef}, subst::{GenericArgKind, Subst, SubstsRef},
Binder, List, Region, Ty, TyCtxt, TypeFoldable, Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable,
}; };
use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span}; use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span};
use rustc_target::spec::abi; use rustc_target::spec::abi;
@ -961,12 +961,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
for (def_id, actual) in iter::zip(default_params, substs.iter().rev()) { for (def_id, actual) in iter::zip(default_params, substs.iter().rev()) {
match actual.unpack() { match actual.unpack() {
GenericArgKind::Const(c) => { GenericArgKind::Const(c) => {
if self.tcx.const_param_default(def_id).subst(self.tcx, substs) != c { if EarlyBinder(self.tcx.const_param_default(def_id)).subst(self.tcx, substs)
!= c
{
break; break;
} }
} }
GenericArgKind::Type(ty) => { GenericArgKind::Type(ty) => {
if self.tcx.type_of(def_id).subst(self.tcx, substs) != ty { if EarlyBinder(self.tcx.type_of(def_id)).subst(self.tcx, substs) != ty {
break; break;
} }
} }
@ -1383,8 +1385,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => { (ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1); let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2); let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
let mut values = self.cmp_fn_sig(&sig1, &sig2); let mut values = self.cmp_fn_sig(&sig1, &sig2);
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did1, substs1)); let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did1, substs1));
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did2, substs2)); let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did2, substs2));
@ -1395,7 +1397,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
(ty::FnDef(did1, substs1), ty::FnPtr(sig2)) => { (ty::FnDef(did1, substs1), ty::FnPtr(sig2)) => {
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1); let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
let mut values = self.cmp_fn_sig(&sig1, sig2); let mut values = self.cmp_fn_sig(&sig1, sig2);
values.0.push_highlighted(format!( values.0.push_highlighted(format!(
" {{{}}}", " {{{}}}",
@ -1405,7 +1407,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
(ty::FnPtr(sig1), ty::FnDef(did2, substs2)) => { (ty::FnPtr(sig1), ty::FnDef(did2, substs2)) => {
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2); let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
let mut values = self.cmp_fn_sig(sig1, &sig2); let mut values = self.cmp_fn_sig(sig1, &sig2);
values.1.push_normal(format!( values.1.push_normal(format!(
" {{{}}}", " {{{}}}",
@ -1850,7 +1852,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let bounds = self.tcx.explicit_item_bounds(*def_id); let bounds = self.tcx.explicit_item_bounds(*def_id);
for (predicate, _) in bounds { for (predicate, _) in bounds {
let predicate = predicate.subst(self.tcx, substs); let predicate = EarlyBinder(*predicate).subst(self.tcx, substs);
let output = predicate let output = predicate
.kind() .kind()
.map_bound(|kind| match kind { .map_bound(|kind| match kind {

View file

@ -9,7 +9,7 @@ use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::subst::{GenericArgKind, Subst}; use rustc_middle::ty::subst::{GenericArgKind, Subst};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor, self, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor,
}; };
use rustc_span::Span; use rustc_span::Span;
@ -565,7 +565,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
for (predicate, _) in item_bounds { for (predicate, _) in item_bounds {
debug!(?predicate); debug!(?predicate);
let predicate = predicate.subst(tcx, substs); let predicate = EarlyBinder(*predicate).subst(tcx, substs);
let predicate = predicate.fold_with(&mut BottomUpFolder { let predicate = predicate.fold_with(&mut BottomUpFolder {
tcx, tcx,

View file

@ -4,7 +4,7 @@ use rustc_data_structures::captures::Captures;
use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::sso::SsoHashSet;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a` /// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
/// obligation into a series of `'a: 'b` constraints and "verifys", as /// obligation into a series of `'a: 'b` constraints and "verifys", as
@ -290,7 +290,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
debug!("projection_bounds(projection_ty={:?})", projection_ty); debug!("projection_bounds(projection_ty={:?})", projection_ty);
let tcx = self.tcx; let tcx = self.tcx;
self.region_bounds_declared_on_associated_item(projection_ty.item_def_id) self.region_bounds_declared_on_associated_item(projection_ty.item_def_id)
.map(move |r| r.subst(tcx, projection_ty.substs)) .map(move |r| EarlyBinder(r).subst(tcx, projection_ty.substs))
} }
/// Given the `DefId` of an associated item, returns any region /// Given the `DefId` of an associated item, returns any region

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, List, Ty, TyCtxt}; use crate::ty::{self, EarlyBinder, 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 = tcx.type_of(def_id).subst(tcx, substs); let ty = EarlyBinder(tcx.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, Ty, TyCtxt}; use crate::ty::{self, EarlyBinder, Ty, TyCtxt};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_target::abi::VariantIdx; use rustc_target::abi::VariantIdx;
@ -202,7 +202,9 @@ impl<'tcx> Rvalue<'tcx> {
Rvalue::Aggregate(ref ak, ref ops) => match **ak { Rvalue::Aggregate(ref ak, ref ops) => match **ak {
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, _, _) => tcx.type_of(did).subst(tcx, substs), AggregateKind::Adt(did, _, substs, _, _) => {
EarlyBinder(tcx.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) => {
tcx.mk_generator(did, substs, movability) tcx.mk_generator(did, substs, movability)

View file

@ -19,10 +19,11 @@ 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, ExistentialPredicate, FloatTy, ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, EarlyBinder, ExistentialPredicate,
FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid,
ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, Region, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy,
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut,
UintTy,
}; };
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
@ -1604,7 +1605,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,
self.type_of(self.require_lang_item(LangItem::PanicLocation, None)) EarlyBinder(self.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())),
) )
} }
@ -2333,7 +2334,7 @@ impl<'tcx> TyCtxt<'tcx> {
ty_param.into() ty_param.into()
} else { } else {
assert!(has_default); assert!(has_default);
self.type_of(param.def_id).subst(self, substs).into() EarlyBinder(self.type_of(param.def_id)).subst(self, substs).into()
} }
} }
}); });

View file

@ -1,6 +1,7 @@
use crate::middle::resolve_lifetime::ObjectLifetimeDefault; use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
use crate::ty; use crate::ty;
use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::EarlyBinder;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -229,7 +230,11 @@ impl<'tcx> GenericPredicates<'tcx> {
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
) -> InstantiatedPredicates<'tcx> { ) -> InstantiatedPredicates<'tcx> {
InstantiatedPredicates { InstantiatedPredicates {
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(), predicates: self
.predicates
.iter()
.map(|(p, _)| EarlyBinder(*p).subst(tcx, substs))
.collect(),
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(), spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
} }
} }
@ -243,7 +248,9 @@ impl<'tcx> GenericPredicates<'tcx> {
if let Some(def_id) = self.parent { if let Some(def_id) = self.parent {
tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs); tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
} }
instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p.subst(tcx, substs))); instantiated
.predicates
.extend(self.predicates.iter().map(|(p, _)| EarlyBinder(*p).subst(tcx, substs)));
instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp)); instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp));
} }

View file

@ -1,7 +1,7 @@
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::subst::{InternalSubsts, Subst}; use crate::ty::subst::{InternalSubsts, Subst};
use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable}; use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt, TypeFoldable};
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::Namespace; use rustc_hir::def::Namespace;
use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::def_id::{CrateNum, DefId};
@ -557,7 +557,11 @@ impl<'tcx> Instance<'tcx> {
where where
T: TypeFoldable<'tcx> + Copy, T: TypeFoldable<'tcx> + Copy,
{ {
if let Some(substs) = self.substs_for_mir_body() { v.subst(tcx, substs) } else { *v } if let Some(substs) = self.substs_for_mir_body() {
EarlyBinder(*v).subst(tcx, substs)
} else {
*v
}
} }
#[inline(always)] #[inline(always)]

View file

@ -2,7 +2,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::mir::{GeneratorLayout, GeneratorSavedLocal}; use crate::mir::{GeneratorLayout, GeneratorSavedLocal};
use crate::ty::normalize_erasing_regions::NormalizationError; use crate::ty::normalize_erasing_regions::NormalizationError;
use crate::ty::subst::Subst; use crate::ty::subst::Subst;
use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable}; use crate::ty::{self, subst::SubstsRef, EarlyBinder, ReprOptions, Ty, TyCtxt, TypeFoldable};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_attr as attr; use rustc_attr as attr;
use rustc_hir as hir; use rustc_hir as hir;
@ -1706,7 +1706,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
) -> Result<Layout<'tcx>, LayoutError<'tcx>> { ) -> Result<Layout<'tcx>, LayoutError<'tcx>> {
use SavedLocalEligibility::*; use SavedLocalEligibility::*;
let tcx = self.tcx; let tcx = self.tcx;
let subst_field = |ty: Ty<'tcx>| ty.subst(tcx, substs); let subst_field = |ty: Ty<'tcx>| EarlyBinder(ty).subst(tcx, substs);
let Some(info) = tcx.generator_layout(def_id) else { let Some(info) = tcx.generator_layout(def_id) else {
return Err(LayoutError::Unknown(ty)); return Err(LayoutError::Unknown(ty));
@ -2749,8 +2749,9 @@ impl<'tcx> ty::Instance<'tcx> {
// `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping // `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
// track of a polymorphization `ParamEnv` to allow normalizing later. // track of a polymorphization `ParamEnv` to allow normalizing later.
let mut sig = match *ty.kind() { let mut sig = match *ty.kind() {
ty::FnDef(def_id, substs) => tcx ty::FnDef(def_id, substs) => EarlyBinder(
.normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id)) tcx.normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id)),
)
.subst(tcx, substs), .subst(tcx, substs),
_ => unreachable!(), _ => unreachable!(),
}; };

View file

@ -78,7 +78,7 @@ pub use self::sty::RegionKind::*;
pub use self::sty::TyKind::*; pub use self::sty::TyKind::*;
pub use self::sty::{ pub use self::sty::{
Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind,
CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBoundRegion, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBinder, EarlyBoundRegion,
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig,
GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, InlineConstSubstsParts, ParamConst, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, InlineConstSubstsParts, ParamConst,
ParamTy, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, ParamTy, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig,
@ -736,7 +736,7 @@ impl<'tcx> Predicate<'tcx> {
let shifted_pred = let shifted_pred =
tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder()); tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder());
// 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1> // 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1>
let new = shifted_pred.subst(tcx, trait_ref.skip_binder().substs); let new = EarlyBinder(shifted_pred).subst(tcx, trait_ref.skip_binder().substs);
// 3) ['x] + ['b] -> ['x, 'b] // 3) ['x] + ['b] -> ['x, 'b]
let bound_vars = let bound_vars =
tcx.mk_bound_variable_kinds(trait_bound_vars.iter().chain(pred_bound_vars)); tcx.mk_bound_variable_kinds(trait_bound_vars.iter().chain(pred_bound_vars));
@ -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> {
tcx.type_of(self.did).subst(tcx, subst) EarlyBinder(tcx.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

@ -11,7 +11,7 @@ use crate::mir;
use crate::traits::query::NoSolution; use crate::traits::query::NoSolution;
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder}; use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder};
use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::{self, Ty, TyCtxt}; use crate::ty::{self, EarlyBinder, Ty, TyCtxt};
#[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)] #[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)]
pub enum NormalizationError<'tcx> { pub enum NormalizationError<'tcx> {
@ -133,7 +133,7 @@ impl<'tcx> TyCtxt<'tcx> {
param_env={:?})", param_env={:?})",
param_substs, value, param_env, param_substs, value, param_env,
); );
let substituted = value.subst(self, param_substs); let substituted = EarlyBinder(value).subst(self, param_substs);
self.normalize_erasing_regions(param_env, substituted) self.normalize_erasing_regions(param_env, substituted)
} }
@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
param_env={:?})", param_env={:?})",
param_substs, value, param_env, param_substs, value, param_env,
); );
let substituted = value.subst(self, param_substs); let substituted = EarlyBinder(value).subst(self, param_substs);
self.try_normalize_erasing_regions(param_env, substituted) self.try_normalize_erasing_regions(param_env, substituted)
} }
} }

View file

@ -1,5 +1,5 @@
use crate::ty::subst::{GenericArg, Subst}; use crate::ty::subst::{GenericArg, Subst};
use crate::ty::{self, DefIdTree, Ty, TyCtxt}; use crate::ty::{self, DefIdTree, EarlyBinder, Ty, TyCtxt};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::sso::SsoHashSet;
@ -118,8 +118,8 @@ pub trait Printer<'tcx>: Sized {
let mut self_ty = self.tcx().type_of(def_id); let mut self_ty = self.tcx().type_of(def_id);
let mut impl_trait_ref = self.tcx().impl_trait_ref(def_id); let mut impl_trait_ref = self.tcx().impl_trait_ref(def_id);
if substs.len() >= generics.count() { if substs.len() >= generics.count() {
self_ty = self_ty.subst(self.tcx(), substs); self_ty = EarlyBinder(self_ty).subst(self.tcx(), substs);
impl_trait_ref = impl_trait_ref.subst(self.tcx(), substs); impl_trait_ref = EarlyBinder(impl_trait_ref).subst(self.tcx(), substs);
} }
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,7 +203,8 @@ pub trait Printer<'tcx>: Sized {
has_default has_default
&& substs[param.index as usize] && substs[param.index as usize]
== GenericArg::from( == GenericArg::from(
self.tcx().type_of(param.def_id).subst(self.tcx(), substs), EarlyBinder(self.tcx().type_of(param.def_id))
.subst(self.tcx(), substs),
) )
} }
ty::GenericParamDefKind::Const { has_default } => { ty::GenericParamDefKind::Const { has_default } => {

View file

@ -1,6 +1,8 @@
use crate::mir::interpret::{AllocRange, ConstValue, GlobalAlloc, Pointer, Provenance, Scalar}; use crate::mir::interpret::{AllocRange, ConstValue, GlobalAlloc, Pointer, Provenance, Scalar};
use crate::ty::subst::{GenericArg, GenericArgKind, Subst}; use crate::ty::subst::{GenericArg, GenericArgKind, Subst};
use crate::ty::{self, ConstInt, DefIdTree, ParamConst, ScalarInt, Term, Ty, TyCtxt, TypeFoldable}; use crate::ty::{
self, ConstInt, DefIdTree, EarlyBinder, ParamConst, ScalarInt, Term, Ty, TyCtxt, TypeFoldable,
};
use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::ieee::{Double, Single};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::sso::SsoHashSet;
@ -587,7 +589,7 @@ pub trait PrettyPrinter<'tcx>:
p!(")") p!(")")
} }
ty::FnDef(def_id, substs) => { ty::FnDef(def_id, substs) => {
let sig = self.tcx().fn_sig(def_id).subst(self.tcx(), substs); let sig = EarlyBinder(self.tcx().fn_sig(def_id)).subst(self.tcx(), substs);
p!(print(sig), " {{", print_value_path(def_id, substs), "}}"); p!(print(sig), " {{", print_value_path(def_id, substs), "}}");
} }
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)), ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
@ -781,7 +783,7 @@ pub trait PrettyPrinter<'tcx>:
let mut is_sized = false; let mut is_sized = false;
for (predicate, _) in bounds { for (predicate, _) in bounds {
let predicate = predicate.subst(self.tcx(), substs); let predicate = EarlyBinder(*predicate).subst(self.tcx(), substs);
let bound_predicate = predicate.kind(); let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {

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, ImplSubject, Term, Ty, TyCtxt, TypeFoldable}; use crate::ty::{self, EarlyBinder, 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,7 +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.get_or_insert_with(|| tcx.type_of(ty_def_id).subst(tcx, a_subst)); let ty = *cached_ty
.get_or_insert_with(|| EarlyBinder(tcx.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

@ -713,7 +713,9 @@ impl<'tcx> GeneratorSubsts<'tcx> {
) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'tcx>> { ) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
let layout = tcx.generator_layout(def_id).unwrap(); let layout = tcx.generator_layout(def_id).unwrap();
layout.variant_fields.iter().map(move |variant| { layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| layout.field_tys[*field].subst(tcx, self.substs)) variant
.iter()
.map(move |field| EarlyBinder(layout.field_tys[*field]).subst(tcx, self.substs))
}) })
} }
@ -1068,6 +1070,45 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
} }
} }
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Encodable, Decodable, HashStable)]
pub struct EarlyBinder<T>(pub T);
impl<T> EarlyBinder<T> {
pub fn as_ref(&self) -> EarlyBinder<&T> {
EarlyBinder(&self.0)
}
pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<U>
where
F: FnOnce(&T) -> U,
{
self.as_ref().map_bound(f)
}
pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<U>
where
F: FnOnce(T) -> U,
{
let value = f(self.0);
EarlyBinder(value)
}
pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<U>, E>
where
F: FnOnce(T) -> Result<U, E>,
{
let value = f(self.0)?;
Ok(EarlyBinder(value))
}
}
impl<T> EarlyBinder<Option<T>> {
pub fn transpose(self) -> Option<EarlyBinder<T>> {
self.0.map(|v| EarlyBinder(v))
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
#[derive(HashStable)] #[derive(HashStable)]
pub enum BoundVariableKind { pub enum BoundVariableKind {
@ -2139,7 +2180,7 @@ impl<'tcx> Ty<'tcx> {
pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> { pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
match self.kind() { match self.kind() {
FnDef(def_id, substs) => tcx.fn_sig(*def_id).subst(tcx, substs), FnDef(def_id, substs) => EarlyBinder(tcx.fn_sig(*def_id)).subst(tcx, substs),
FnPtr(f) => *f, FnPtr(f) => *f,
Error(_) => { Error(_) => {
// ignore errors (#54954) // ignore errors (#54954)
@ -2306,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();
(tcx.type_of(dyn_metadata).subst(tcx, &[tail.into()]), false) (EarlyBinder(tcx.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

@ -4,7 +4,7 @@ use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts}; use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt}; use crate::ty::{self, EarlyBinder, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_data_structures::intern::{Interned, WithStableHash}; use rustc_data_structures::intern::{Interned, WithStableHash};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -500,13 +500,17 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
// Just call `foo.subst(tcx, substs)` to perform a substitution across `foo`. // Just call `foo.subst(tcx, substs)` to perform a substitution across `foo`.
pub trait Subst<'tcx>: Sized { pub trait Subst<'tcx>: Sized {
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self; type Inner;
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self::Inner;
} }
impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T { impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for EarlyBinder<T> {
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> T { type Inner = T;
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self::Inner {
let mut folder = SubstFolder { tcx, substs, binders_passed: 0 }; let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
self.fold_with(&mut folder) self.0.fold_with(&mut folder)
} }
} }

View file

@ -6,7 +6,8 @@ use crate::ty::layout::IntegerExt;
use crate::ty::query::TyCtxtAt; use crate::ty::query::TyCtxtAt;
use crate::ty::subst::{GenericArgKind, Subst, SubstsRef}; use crate::ty::subst::{GenericArgKind, Subst, SubstsRef};
use crate::ty::{ use crate::ty::{
self, Const, DebruijnIndex, DefIdTree, List, ReEarlyBound, Ty, TyCtxt, TyKind::*, TypeFoldable, self, Const, DebruijnIndex, DefIdTree, EarlyBinder, List, ReEarlyBound, Ty, TyCtxt, TyKind::*,
TypeFoldable,
}; };
use rustc_apfloat::Float as _; use rustc_apfloat::Float as _;
use rustc_ast as ast; use rustc_ast as ast;
@ -623,7 +624,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
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.type_of(def_id);
let concrete_ty = generic_ty.subst(self.tcx, substs); let concrete_ty = EarlyBinder(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, Ty, TyCtxt}; use rustc_middle::ty::{self, adjustment::PointerCast, EarlyBinder, 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;
@ -835,7 +835,7 @@ fn trait_method<'tcx>(
.expect("trait method not found"); .expect("trait method not found");
let method_ty = tcx.type_of(item.def_id); let method_ty = tcx.type_of(item.def_id);
let method_ty = method_ty.subst(tcx, substs); let method_ty = EarlyBinder(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, Ty, TyCtxt, TypeFoldable, TypeckResults}; use rustc_middle::ty::{self, EarlyBinder, 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,7 +177,8 @@ 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));
tcx.type_of(va_list_did).subst(tcx, &[tcx.lifetimes.re_erased.into()]) EarlyBinder(tcx.type_of(va_list_did))
.subst(tcx, &[tcx.lifetimes.re_erased.into()])
} else { } else {
fn_sig.inputs()[index] fn_sig.inputs()[index]
}; };

View file

@ -18,7 +18,9 @@ use rustc_middle::mir::{
}; };
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{
self, ConstKind, EarlyBinder, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable,
};
use rustc_span::{def_id::DefId, Span}; use rustc_span::{def_id::DefId, Span};
use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout}; use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -374,7 +376,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
); );
let ret = ecx let ret = ecx
.layout_of(body.return_ty().subst(tcx, substs)) .layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
.ok() .ok()
// Don't bother allocating memory for ZST types which have no values // Don't bother allocating memory for ZST types which have no values
// or for large values. // or for large values.

View file

@ -18,7 +18,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable, self, ConstInt, ConstKind, EarlyBinder, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable,
}; };
use rustc_session::lint; use rustc_session::lint;
use rustc_span::{def_id::DefId, Span}; use rustc_span::{def_id::DefId, Span};
@ -370,7 +370,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
); );
let ret = ecx let ret = ecx
.layout_of(body.return_ty().subst(tcx, substs)) .layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
.ok() .ok()
// Don't bother allocating memory for ZST types which have no values // Don't bother allocating memory for ZST types which have no values
// or for large values. // or for large values.

View file

@ -6,7 +6,7 @@ use rustc_middle::mir::*;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, self,
subst::{GenericArgKind, Subst, SubstsRef}, subst::{GenericArgKind, Subst, SubstsRef},
PredicateKind, Ty, TyCtxt, EarlyBinder, PredicateKind, Ty, TyCtxt,
}; };
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES; use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
use rustc_span::{symbol::sym, Span}; use rustc_span::{symbol::sym, Span};
@ -90,7 +90,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
// If the inner type matches the type bound by `Pointer` // If the inner type matches the type bound by `Pointer`
if inner_ty == bound_ty { if inner_ty == bound_ty {
// Do a substitution using the parameters from the callsite // Do a substitution using the parameters from the callsite
let subst_ty = inner_ty.subst(self.tcx, substs_ref); let subst_ty = EarlyBinder(inner_ty).subst(self.tcx, substs_ref);
if let Some((fn_id, fn_substs)) = if let Some((fn_id, fn_substs)) =
FunctionItemRefChecker::is_fn_ref(subst_ty) FunctionItemRefChecker::is_fn_ref(subst_ty)
{ {

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, Ty, TyCtxt}; use rustc_middle::ty::{self, AdtDef, EarlyBinder, Ty, TyCtxt};
use rustc_mir_dataflow::impls::{ use rustc_mir_dataflow::impls::{
MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive,
}; };
@ -245,9 +245,7 @@ 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 = self let ty = EarlyBinder(self.tcx.type_of(self.state_adt_ref.variant(idx).fields[0].did))
.tcx
.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

@ -8,7 +8,7 @@ use rustc_middle::mir::visit::*;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{self, ConstKind, EarlyBinder, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span}; use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -260,7 +260,7 @@ impl<'tcx> Inliner<'tcx> {
return None; return None;
} }
let fn_sig = self.tcx.fn_sig(def_id).subst(self.tcx, substs); let fn_sig = EarlyBinder(self.tcx.fn_sig(def_id)).subst(self.tcx, substs);
return Some(CallSite { return Some(CallSite {
callee, callee,

View file

@ -4,7 +4,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
use rustc_target::abi::VariantIdx; use rustc_target::abi::VariantIdx;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
@ -70,7 +70,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
// of this function. Is this intentional? // of this function. Is this intentional?
if let Some(ty::Generator(gen_def_id, substs, _)) = ty.map(Ty::kind) { if let Some(ty::Generator(gen_def_id, substs, _)) = ty.map(Ty::kind) {
let body = tcx.optimized_mir(*gen_def_id).generator_drop().unwrap(); let body = tcx.optimized_mir(*gen_def_id).generator_drop().unwrap();
let body = body.clone().subst(tcx, substs); let body = EarlyBinder(body.clone()).subst(tcx, substs);
debug!("make_shim({:?}) = {:?}", instance, body); debug!("make_shim({:?}) = {:?}", instance, body);
return body; return body;
} }
@ -151,7 +151,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
} else { } else {
InternalSubsts::identity_for_item(tcx, def_id) InternalSubsts::identity_for_item(tcx, def_id)
}; };
let sig = tcx.fn_sig(def_id).subst(tcx, substs); let sig = EarlyBinder(tcx.fn_sig(def_id)).subst(tcx, substs);
let sig = tcx.erase_late_bound_regions(sig); let sig = tcx.erase_late_bound_regions(sig);
let span = tcx.def_span(def_id); let span = tcx.def_span(def_id);
@ -343,7 +343,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
// otherwise going to be TySelf and we can't index // otherwise going to be TySelf and we can't index
// or access fields of a Place of type TySelf. // or access fields of a Place of type TySelf.
let substs = tcx.mk_substs_trait(self_ty, &[]); let substs = tcx.mk_substs_trait(self_ty, &[]);
let sig = tcx.fn_sig(def_id).subst(tcx, substs); let sig = EarlyBinder(tcx.fn_sig(def_id)).subst(tcx, substs);
let sig = tcx.erase_late_bound_regions(sig); let sig = tcx.erase_late_bound_regions(sig);
let span = tcx.def_span(def_id); let span = tcx.def_span(def_id);
@ -541,7 +541,7 @@ fn build_call_shim<'tcx>(
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body()); assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
if let Some(sig_substs) = sig_substs { if let Some(sig_substs) = sig_substs {
sig = sig.subst(tcx, sig_substs); sig = EarlyBinder(sig).subst(tcx, sig_substs);
} }
if let CallKind::Indirect(fnty) = call_kind { if let CallKind::Indirect(fnty) = call_kind {

View file

@ -9,7 +9,9 @@ use rustc_middle::mir::interpret::ConstValue;
use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::print::{Print, Printer}; use rustc_middle::ty::print::{Print, Printer};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{self, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeFoldable, UintTy}; use rustc_middle::ty::{
self, EarlyBinder, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeFoldable, UintTy,
};
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
use rustc_target::abi::call::FnAbi; use rustc_target::abi::call::FnAbi;
use rustc_target::abi::Integer; use rustc_target::abi::Integer;
@ -297,7 +299,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
let mut param_env = self.tcx.param_env_reveal_all_normalized(impl_def_id); let mut param_env = self.tcx.param_env_reveal_all_normalized(impl_def_id);
if !substs.is_empty() { if !substs.is_empty() {
param_env = param_env.subst(self.tcx, substs); param_env = EarlyBinder(param_env).subst(self.tcx, substs);
} }
match &mut impl_trait_ref { match &mut impl_trait_ref {

View file

@ -23,7 +23,7 @@ use rustc_middle::traits::specialization_graph::OverlapMode;
use rustc_middle::ty::fast_reject::{self, TreatParams}; use rustc_middle::ty::fast_reject::{self, TreatParams};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, ImplSubject, Ty, TyCtxt};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use std::fmt::Debug; use std::fmt::Debug;
@ -135,8 +135,8 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
let header = ty::ImplHeader { let header = ty::ImplHeader {
impl_def_id, impl_def_id,
self_ty: tcx.type_of(impl_def_id).subst(tcx, impl_substs), self_ty: EarlyBinder(tcx.type_of(impl_def_id)).subst(tcx, impl_substs),
trait_ref: 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

@ -19,7 +19,7 @@ use rustc_middle::mir::interpret::{
use rustc_middle::thir; use rustc_middle::thir;
use rustc_middle::thir::abstract_const::{self, Node, NodeId, NotConstEvaluatable}; use rustc_middle::thir::abstract_const::{self, Node, NodeId, NotConstEvaluatable};
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::{self, DelaySpanBugEmitted, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, DelaySpanBugEmitted, EarlyBinder, TyCtxt, TypeFoldable};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::Span; use rustc_span::Span;
@ -263,8 +263,10 @@ impl<'tcx> AbstractConst<'tcx> {
pub fn root(self, tcx: TyCtxt<'tcx>) -> Node<'tcx> { pub fn root(self, tcx: TyCtxt<'tcx>) -> Node<'tcx> {
let node = self.inner.last().copied().unwrap(); let node = self.inner.last().copied().unwrap();
match node { match node {
Node::Leaf(leaf) => Node::Leaf(leaf.subst(tcx, self.substs)), Node::Leaf(leaf) => Node::Leaf(EarlyBinder(leaf).subst(tcx, self.substs)),
Node::Cast(kind, operand, ty) => Node::Cast(kind, operand, ty.subst(tcx, self.substs)), Node::Cast(kind, operand, ty) => {
Node::Cast(kind, operand, EarlyBinder(ty).subst(tcx, self.substs))
}
// Don't perform substitution on the following as they can't directly contain generic params // Don't perform substitution on the following as they can't directly contain generic params
Node::Binop(_, _, _) | Node::UnaryOp(_, _) | Node::FunctionCall(_, _) => node, Node::Binop(_, _, _) | Node::UnaryOp(_, _) | Node::FunctionCall(_, _) => node,
} }

View file

@ -5,7 +5,7 @@ use crate::infer::InferCtxt;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::{self, GenericParamDefKind}; use rustc_middle::ty::{self, EarlyBinder, GenericParamDefKind};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use std::iter; use std::iter;
@ -45,7 +45,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| { self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| {
let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id); let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
let impl_trait_ref = tcx.impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs); let impl_trait_ref =
EarlyBinder(tcx.impl_trait_ref(def_id).unwrap()).subst(tcx, impl_substs);
let impl_self_ty = impl_trait_ref.self_ty(); let impl_self_ty = impl_trait_ref.self_ty();

View file

@ -18,7 +18,7 @@ use rustc_errors::{FatalError, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst}; use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeVisitor};
use rustc_middle::ty::{Predicate, ToPredicate}; use rustc_middle::ty::{Predicate, ToPredicate};
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY; use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
@ -531,7 +531,7 @@ fn receiver_for_self_ty<'tcx>(
if param.index == 0 { self_ty.into() } else { tcx.mk_param_from_def(param) } if param.index == 0 { self_ty.into() } else { tcx.mk_param_from_def(param) }
}); });
let result = receiver_ty.subst(tcx, substs); let result = EarlyBinder(receiver_ty).subst(tcx, substs);
debug!( debug!(
"receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}", "receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}",
receiver_ty, self_ty, method_def_id, result receiver_ty, self_ty, method_def_id, result

View file

@ -31,7 +31,7 @@ use rustc_infer::infer::resolve::OpportunisticRegionResolver;
use rustc_middle::traits::select::OverflowError; use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::fold::{MaxUniverse, TypeFoldable, TypeFolder}; use rustc_middle::ty::fold::{MaxUniverse, TypeFoldable, TypeFolder};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, Term, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, Term, ToPredicate, Ty, TyCtxt};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -516,7 +516,7 @@ 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().type_of(def_id);
let concrete_ty = generic_ty.subst(self.tcx(), substs); let concrete_ty = EarlyBinder(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;
@ -1276,8 +1276,10 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
// Check whether the self-type is itself a projection. // Check whether the self-type is itself a projection.
// If so, extract what we know from the trait and try to come up with a good answer. // If so, extract what we know from the trait and try to come up with a good answer.
let bounds = match *obligation.predicate.self_ty().kind() { let bounds = match *obligation.predicate.self_ty().kind() {
ty::Projection(ref data) => tcx.item_bounds(data.item_def_id).subst(tcx, data.substs), ty::Projection(ref data) => {
ty::Opaque(def_id, substs) => tcx.item_bounds(def_id).subst(tcx, substs), EarlyBinder(tcx.item_bounds(data.item_def_id)).subst(tcx, data.substs)
}
ty::Opaque(def_id, substs) => EarlyBinder(tcx.item_bounds(def_id)).subst(tcx, substs),
ty::Infer(ty::TyVar(_)) => { ty::Infer(ty::TyVar(_)) => {
// If the self-type is an inference variable, then it MAY wind up // If the self-type is an inference variable, then it MAY wind up
// being a projected type, so induce an ambiguity. // being a projected type, so induce an ambiguity.
@ -2032,7 +2034,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
Progress { term: err.into(), obligations: nested } Progress { term: err.into(), obligations: nested }
} else { } else {
assoc_ty_own_obligations(selcx, obligation, &mut nested); assoc_ty_own_obligations(selcx, obligation, &mut nested);
Progress { term: term.subst(tcx, substs), obligations: nested } Progress { term: EarlyBinder(term).subst(tcx, substs), obligations: nested }
} }
} }

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, Ty, TyCtxt, TypeVisitor}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitor};
use std::ops::ControlFlow; use std::ops::ControlFlow;
@ -218,7 +218,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
} }
let generic_ty = self.tcx().type_of(def_id); let generic_ty = self.tcx().type_of(def_id);
let concrete_ty = generic_ty.subst(self.tcx(), substs); let concrete_ty = EarlyBinder(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

@ -12,7 +12,7 @@ use rustc_index::bit_set::GrowableBitSet;
use rustc_infer::infer::InferOk; use rustc_infer::infer::InferOk;
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType; use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::{self, GenericParamDefKind, Ty}; use rustc_middle::ty::{self, EarlyBinder, GenericParamDefKind, Ty};
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate}; use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
@ -174,7 +174,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
}; };
let candidate_predicate = tcx.item_bounds(def_id)[idx].subst(tcx, substs); let candidate_predicate = EarlyBinder(tcx.item_bounds(def_id)[idx]).subst(tcx, substs);
let candidate = candidate_predicate let candidate = candidate_predicate
.to_opt_poly_trait_pred() .to_opt_poly_trait_pred()
.expect("projection candidate is not a trait predicate") .expect("projection candidate is not a trait predicate")
@ -501,9 +501,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// higher-ranked things. // higher-ranked things.
// Prevent, e.g., `dyn Iterator<Item = str>`. // Prevent, e.g., `dyn Iterator<Item = str>`.
for bound in self.tcx().item_bounds(assoc_type) { for bound in self.tcx().item_bounds(assoc_type) {
let subst_bound = let subst_bound = if defs.count() == 0 {
if defs.count() == 0 { EarlyBinder(bound).subst(tcx, trait_predicate.trait_ref.substs)
bound.subst(tcx, trait_predicate.trait_ref.substs)
} else { } else {
let mut substs = smallvec::SmallVec::with_capacity(defs.count()); let mut substs = smallvec::SmallVec::with_capacity(defs.count());
substs.extend(trait_predicate.trait_ref.substs.iter()); substs.extend(trait_predicate.trait_ref.substs.iter());
@ -512,9 +511,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
bound.kind().bound_vars().len() + defs.count(), bound.kind().bound_vars().len() + defs.count(),
); );
bound_vars.extend(bound.kind().bound_vars().into_iter()); bound_vars.extend(bound.kind().bound_vars().into_iter());
InternalSubsts::fill_single(&mut substs, defs, &mut |param, _| match param InternalSubsts::fill_single(
.kind &mut substs,
{ defs,
&mut |param, _| match param.kind {
GenericParamDefKind::Type { .. } => { GenericParamDefKind::Type { .. } => {
let kind = ty::BoundTyKind::Param(param.name); let kind = ty::BoundTyKind::Param(param.name);
let bound_var = ty::BoundVariableKind::Ty(kind); let bound_var = ty::BoundVariableKind::Ty(kind);
@ -553,12 +553,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}) })
.into() .into()
} }
}); },
);
let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter()); let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter());
let assoc_ty_substs = tcx.intern_substs(&substs); let assoc_ty_substs = tcx.intern_substs(&substs);
let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter()); let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter());
let bound = bound.kind().skip_binder().subst(tcx, assoc_ty_substs); let bound = EarlyBinder(bound.kind().skip_binder()).subst(tcx, assoc_ty_substs);
tcx.mk_predicate(ty::Binder::bind_with_vars(bound, bound_vars)) tcx.mk_predicate(ty::Binder::bind_with_vars(bound, bound_vars))
}; };
let normalized_bound = normalize_with_depth_to( let normalized_bound = normalize_with_depth_to(
@ -1029,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 = tail_field_ty.subst(tcx, substs_a); let source_tail = EarlyBinder(tail_field_ty).subst(tcx, substs_a);
let target_tail = tail_field_ty.subst(tcx, substs_b); let target_tail = EarlyBinder(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

@ -38,7 +38,7 @@ use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef}; use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
use rustc_middle::ty::{self, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate}; use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -1341,7 +1341,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
); );
} }
}; };
let bounds = tcx.item_bounds(def_id).subst(tcx, substs); let bounds = EarlyBinder(tcx.item_bounds(def_id)).subst(tcx, substs);
// The bounds returned by `item_bounds` may contain duplicates after // The bounds returned by `item_bounds` may contain duplicates after
// normalization, so try to deduplicate when possible to avoid // normalization, so try to deduplicate when possible to avoid
@ -1795,11 +1795,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Adt(def, substs) => { ty::Adt(def, substs) => {
let sized_crit = def.sized_constraint(self.tcx()); let sized_crit = def.sized_constraint(self.tcx());
// (*) binder moved here // (*) binder moved here
Where( Where(obligation.predicate.rebind({
obligation.predicate.rebind({ sized_crit.iter().map(|ty| EarlyBinder(*ty).subst(self.tcx(), substs)).collect()
sized_crit.iter().map(|ty| ty.subst(self.tcx(), substs)).collect() }))
}),
)
} }
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None, ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None,
@ -1962,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![self.tcx().type_of(def_id).subst(self.tcx(), substs)]) t.rebind(vec![EarlyBinder(self.tcx().type_of(def_id)).subst(self.tcx(), substs)])
} }
} }
} }
@ -2083,7 +2081,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id); let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
let impl_trait_ref = impl_trait_ref.subst(self.tcx(), impl_substs); let impl_trait_ref = EarlyBinder(impl_trait_ref).subst(self.tcx(), impl_substs);
debug!(?impl_trait_ref); debug!(?impl_trait_ref);
@ -2332,7 +2330,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
param_env, param_env,
cause.clone(), cause.clone(),
recursion_depth, recursion_depth,
predicate.subst(tcx, substs), EarlyBinder(*predicate).subst(tcx, substs),
&mut obligations, &mut obligations,
); );
obligations.push(Obligation { cause, recursion_depth, param_env, predicate }); obligations.push(Obligation { cause, recursion_depth, param_env, predicate });

View file

@ -20,7 +20,7 @@ use rustc_errors::{struct_span_err, EmissionGuarantee};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::{self, ImplSubject, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, ImplSubject, TyCtxt};
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK; use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS; use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -84,8 +84,8 @@ pub fn translate_substs<'a, 'tcx>(
"translate_substs({:?}, {:?}, {:?}, {:?})", "translate_substs({:?}, {:?}, {:?}, {:?})",
param_env, source_impl, source_substs, target_node param_env, source_impl, source_substs, target_node
); );
let source_trait_ref = let source_trait_ref = EarlyBinder(infcx.tcx.impl_trait_ref(source_impl).unwrap())
infcx.tcx.impl_trait_ref(source_impl).unwrap().subst(infcx.tcx, &source_substs); .subst(infcx.tcx, &source_substs);
// translate the Self and Param parts of the substitution, since those // translate the Self and Param parts of the substitution, since those
// vary across impls // vary across impls

View file

@ -6,7 +6,7 @@ use smallvec::SmallVec;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef}; use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, EarlyBinder, ImplSubject, ToPredicate, Ty, TyCtxt, TypeFoldable};
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext}; use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
pub use rustc_infer::traits::{self, util::*}; pub use rustc_infer::traits::{self, util::*};
@ -201,7 +201,7 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
impl_substs: SubstsRef<'tcx>, impl_substs: SubstsRef<'tcx>,
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) { ) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
let subject = selcx.tcx().impl_subject(impl_def_id); let subject = selcx.tcx().impl_subject(impl_def_id);
let subject = subject.subst(selcx.tcx(), impl_substs); let subject = EarlyBinder(subject).subst(selcx.tcx(), impl_substs);
let Normalized { value: subject, obligations: normalization_obligations1 } = let Normalized { value: subject, obligations: normalization_obligations1 } =
super::normalize(selcx, param_env, ObligationCause::dummy(), subject); super::normalize(selcx, param_env, ObligationCause::dummy(), subject);

View file

@ -8,7 +8,9 @@
use rustc_middle::traits::ChalkRustInterner as RustInterner; use rustc_middle::traits::ChalkRustInterner as RustInterner;
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::{self, AssocItemContainer, AssocKind, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{
self, AssocItemContainer, AssocKind, EarlyBinder, Ty, TyCtxt, TypeFoldable,
};
use rustc_ast::ast; use rustc_ast::ast;
use rustc_attr as attr; use rustc_attr as attr;
@ -41,7 +43,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
let predicates = self.interner.tcx.predicates_defined_on(def_id).predicates; let predicates = self.interner.tcx.predicates_defined_on(def_id).predicates;
predicates predicates
.iter() .iter()
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars)) .map(|(wc, _)| EarlyBinder(*wc).subst(self.interner.tcx, bound_vars))
.filter_map(|wc| LowerInto::< .filter_map(|wc| LowerInto::<
Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>
>::lower_into(wc, self.interner)).collect() >::lower_into(wc, self.interner)).collect()
@ -55,7 +57,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
.tcx .tcx
.explicit_item_bounds(def_id) .explicit_item_bounds(def_id)
.iter() .iter()
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars)) .map(|(bound, _)| EarlyBinder(*bound).subst(self.interner.tcx, &bound_vars))
.filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, self.interner)) .filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, self.interner))
.collect() .collect()
} }
@ -272,15 +274,17 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars( let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars(
self.interner, self.interner,
self.interner.tcx, self.interner.tcx,
sig.inputs_and_output().subst(self.interner.tcx, bound_vars), EarlyBinder(sig.inputs_and_output()).subst(self.interner.tcx, bound_vars),
); );
let argument_types = inputs_and_output[..inputs_and_output.len() - 1] let argument_types = inputs_and_output[..inputs_and_output.len() - 1]
.iter() .iter()
.map(|t| t.subst(self.interner.tcx, &bound_vars).lower_into(self.interner)) .map(|t| {
EarlyBinder(*t).subst(self.interner.tcx, &bound_vars).lower_into(self.interner)
})
.collect(); .collect();
let return_type = inputs_and_output[inputs_and_output.len() - 1] let return_type = EarlyBinder(inputs_and_output[inputs_and_output.len() - 1])
.subst(self.interner.tcx, &bound_vars) .subst(self.interner.tcx, &bound_vars)
.lower_into(self.interner); .lower_into(self.interner);
@ -307,7 +311,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let binders = binders_for(self.interner, bound_vars); let binders = binders_for(self.interner, bound_vars);
let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl"); let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars); let trait_ref = EarlyBinder(trait_ref).subst(self.interner.tcx, bound_vars);
let where_clauses = self.where_clauses_for(def_id, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars);
@ -352,7 +356,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let bound_vars = bound_vars_for_item(self.interner.tcx, *impl_def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, *impl_def_id);
let self_ty = trait_ref.self_ty(); let self_ty = trait_ref.self_ty();
let self_ty = self_ty.subst(self.interner.tcx, bound_vars); let self_ty = EarlyBinder(self_ty).subst(self.interner.tcx, bound_vars);
let lowered_ty = self_ty.lower_into(self.interner); let lowered_ty = self_ty.lower_into(self.interner);
parameters[0].assert_ty_ref(self.interner).could_match( parameters[0].assert_ty_ref(self.interner).could_match(
@ -460,10 +464,7 @@ 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 = self let ty = EarlyBinder(self.interner.tcx.type_of(def_id))
.interner
.tcx
.type_of(def_id)
.subst(self.interner.tcx, bound_vars) .subst(self.interner.tcx, bound_vars)
.lower_into(self.interner); .lower_into(self.interner);
@ -506,7 +507,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
.tcx .tcx
.explicit_item_bounds(opaque_ty_id.0) .explicit_item_bounds(opaque_ty_id.0)
.iter() .iter()
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars)) .map(|(bound, _)| EarlyBinder(*bound).subst(self.interner.tcx, &bound_vars))
.map(|bound| { .map(|bound| {
bound.fold_with(&mut ReplaceOpaqueTyFolder { bound.fold_with(&mut ReplaceOpaqueTyFolder {
tcx: self.interner.tcx, tcx: self.interner.tcx,

View file

@ -5,7 +5,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::TraitEngineExt as _; use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, ParamEnvAnd, Ty, TyCtxt};
use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_trait_selection::traits::query::dropck_outlives::trivial_dropck_outlives; use rustc_trait_selection::traits::query::dropck_outlives::trivial_dropck_outlives;
use rustc_trait_selection::traits::query::dropck_outlives::{ use rustc_trait_selection::traits::query::dropck_outlives::{
@ -271,9 +271,15 @@ fn dtorck_constraint_for_ty<'tcx>(
tcx.at(span).adt_dtorck_constraint(def.did())?; tcx.at(span).adt_dtorck_constraint(def.did())?;
// FIXME: we can try to recursively `dtorck_constraint_on_ty` // FIXME: we can try to recursively `dtorck_constraint_on_ty`
// there, but that needs some way to handle cycles. // there, but that needs some way to handle cycles.
constraints.dtorck_types.extend(dtorck_types.iter().map(|t| t.subst(tcx, substs))); constraints
constraints.outlives.extend(outlives.iter().map(|t| t.subst(tcx, substs))); .dtorck_types
constraints.overflows.extend(overflows.iter().map(|t| t.subst(tcx, substs))); .extend(dtorck_types.iter().map(|t| EarlyBinder(*t).subst(tcx, substs)));
constraints
.outlives
.extend(outlives.iter().map(|t| EarlyBinder(*t).subst(tcx, substs)));
constraints
.overflows
.extend(overflows.iter().map(|t| EarlyBinder(*t).subst(tcx, substs)));
} }
// Objects must be alive in order for their destructor // Objects must be alive in order for their destructor

View file

@ -6,7 +6,9 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _; use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts}; use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
use rustc_middle::ty::{self, FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable, Variance}; use rustc_middle::ty::{
self, EarlyBinder, FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable, Variance,
};
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Predicate, ToPredicate}; use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Predicate, ToPredicate};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtBuilderExt; use rustc_trait_selection::infer::InferCtxtBuilderExt;
@ -115,7 +117,7 @@ impl<'me, 'tcx> AscribeUserTypeCx<'me, 'tcx> {
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
value.subst(self.tcx(), substs) EarlyBinder(value).subst(self.tcx(), substs)
} }
fn relate_mir_and_user_ty( fn relate_mir_and_user_ty(

View file

@ -5,7 +5,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::util::{needs_drop_components, AlwaysRequiresDrop}; use rustc_middle::ty::util::{needs_drop_components, AlwaysRequiresDrop};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
use rustc_session::Limit; use rustc_session::Limit;
use rustc_span::{sym, DUMMY_SP}; use rustc_span::{sym, DUMMY_SP};
@ -204,7 +204,7 @@ fn drop_tys_helper<'tcx>(
match subty.kind() { match subty.kind() {
ty::Adt(adt_id, subst) => { ty::Adt(adt_id, subst) => {
for subty in tcx.adt_drop_tys(adt_id.did())? { for subty in tcx.adt_drop_tys(adt_id.did())? {
vec.push(subty.subst(tcx, subst)); vec.push(EarlyBinder(subty).subst(tcx, subst));
} }
} }
_ => vec.push(subty), _ => vec.push(subty),
@ -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 = tcx.type_of(field.did).subst(tcx, substs); let r = EarlyBinder(tcx.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

@ -2,7 +2,9 @@ use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
@ -33,7 +35,7 @@ fn sized_constraint_for_ty<'tcx>(
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys); debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
adt_tys adt_tys
.iter() .iter()
.map(|ty| ty.subst(tcx, substs)) .map(|ty| EarlyBinder(*ty).subst(tcx, substs))
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty)) .flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
.collect() .collect()
} }
@ -442,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 = tcx.type_of(field.did).subst(tcx, substs); let ty = EarlyBinder(tcx.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

@ -26,7 +26,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{GenericArg, GenericArgs}; use rustc_hir::{GenericArg, GenericArgs};
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, Const, DefIdTree, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, Const, DefIdTree, EarlyBinder, Ty, TyCtxt, TypeFoldable};
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;
@ -523,7 +523,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.astconv self.astconv
.normalize_ty( .normalize_ty(
self.span, self.span,
tcx.at(self.span).type_of(param.def_id).subst(tcx, substs), EarlyBinder(tcx.at(self.span).type_of(param.def_id))
.subst(tcx, substs),
) )
.into() .into()
} }
@ -543,7 +544,9 @@ 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).type_of(param.def_id);
if !infer_args && has_default { if !infer_args && has_default {
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into() EarlyBinder(tcx.const_param_default(param.def_id))
.subst(tcx, substs.unwrap())
.into()
} else { } else {
if infer_args { if infer_args {
self.astconv.ct_infer(ty, Some(param), self.span).into() self.astconv.ct_infer(ty, Some(param), self.span).into()
@ -1292,7 +1295,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
item_segment: &hir::PathSegment<'_>, item_segment: &hir::PathSegment<'_>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let substs = self.ast_path_substs_for_ty(span, did, item_segment); let substs = self.ast_path_substs_for_ty(span, did, item_segment);
self.normalize_ty(span, self.tcx().at(span).type_of(did).subst(self.tcx(), substs)) self.normalize_ty(
span,
EarlyBinder(self.tcx().at(span).type_of(did)).subst(self.tcx(), substs),
)
} }
fn conv_object_ty_poly_trait_ref( fn conv_object_ty_poly_trait_ref(
@ -2441,7 +2447,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
true, true,
None, None,
); );
self.normalize_ty(span, tcx.at(span).type_of(def_id).subst(tcx, substs)) self.normalize_ty(
span,
EarlyBinder(tcx.at(span).type_of(def_id)).subst(tcx, substs),
)
} }
hir::TyKind::Array(ref ty, ref length) => { hir::TyKind::Array(ref ty, ref length) => {
let length = match length { let length = match length {
@ -2684,7 +2693,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
trait_ref.def_id, trait_ref.def_id,
)?; )?;
let fn_sig = tcx.fn_sig(assoc.def_id).subst( let fn_sig = EarlyBinder(tcx.fn_sig(assoc.def_id)).subst(
tcx, tcx,
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)), trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
); );

View file

@ -18,7 +18,7 @@ use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
}; };
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeFoldable};
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use rustc_target::spec::abi; use rustc_target::spec::abi;
@ -339,7 +339,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let (fn_sig, def_id) = match *callee_ty.kind() { let (fn_sig, def_id) = match *callee_ty.kind() {
ty::FnDef(def_id, subst) => { ty::FnDef(def_id, subst) => {
let fn_sig = self.tcx.fn_sig(def_id).subst(self.tcx, subst); let fn_sig = EarlyBinder(self.tcx.fn_sig(def_id)).subst(self.tcx, subst);
// Unit testing: function items annotated with // Unit testing: function items annotated with
// `#[rustc_evaluate_where_clauses]` trigger special output // `#[rustc_evaluate_where_clauses]` trigger special output

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, ParamEnv, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, 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(tcx.type_of(va_list_did).subst(tcx, &[region.into()])) Some(EarlyBinder(tcx.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 = tcx.type_of(def_id).subst(tcx, substs); let hidden_type = EarlyBinder(tcx.type_of(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

@ -12,7 +12,7 @@ use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_infer::infer::{InferOk, InferResult}; use rustc_infer::infer::{InferOk, InferResult};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, EarlyBinder, Ty};
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -180,7 +180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::PredicateKind::Projection(proj_predicate) => self ty::PredicateKind::Projection(proj_predicate) => self
.deduce_sig_from_projection( .deduce_sig_from_projection(
Some(*span), Some(*span),
pred.kind().rebind(proj_predicate.subst(self.tcx, substs)), pred.kind().rebind(EarlyBinder(proj_predicate).subst(self.tcx, substs)),
), ),
_ => None, _ => None,
}); });
@ -677,7 +677,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// where R is the return type we are expecting. This type `T` // where R is the return type we are expecting. This type `T`
// will be our output. // will be our output.
let output_ty = item_bounds.iter().find_map(|&(predicate, span)| { let output_ty = item_bounds.iter().find_map(|&(predicate, span)| {
let bound_predicate = predicate.subst(self.tcx, substs).kind(); let bound_predicate = EarlyBinder(predicate).subst(self.tcx, substs).kind();
if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() { if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() {
self.deduce_future_output_from_projection( self.deduce_future_output_from_projection(
span, span,

View file

@ -10,7 +10,7 @@ use rustc_infer::traits::util;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::util::ExplicitSelf; use rustc_middle::ty::util::ExplicitSelf;
use rustc_middle::ty::{self, DefIdTree}; use rustc_middle::ty::{self, DefIdTree, EarlyBinder};
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt}; use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
@ -267,7 +267,7 @@ fn compare_predicate_entailment<'tcx>(
// First liberate late bound regions and subst placeholders // First liberate late bound regions and subst placeholders
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id)); let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs); let trait_sig = EarlyBinder(trait_sig).subst(tcx, trait_to_placeholder_substs);
let trait_sig = let trait_sig =
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig); inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
// Add the resulting inputs and output as well-formed. // Add the resulting inputs and output as well-formed.
@ -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 = tcx.type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs); let trait_ty = EarlyBinder(tcx.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,
@ -1456,7 +1456,7 @@ pub fn check_type_bounds<'tcx>(
.iter() .iter()
.map(|&(bound, span)| { .map(|&(bound, span)| {
debug!(?bound); debug!(?bound);
let concrete_ty_bound = bound.subst(tcx, rebased_substs); let concrete_ty_bound = EarlyBinder(bound).subst(tcx, rebased_substs);
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound); debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound) traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound)

View file

@ -8,7 +8,7 @@ use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, Predicate, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
use rustc_trait_selection::traits::query::dropck_outlives::AtExt; use rustc_trait_selection::traits::query::dropck_outlives::AtExt;
@ -84,7 +84,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
let drop_impl_span = tcx.def_span(drop_impl_did); let drop_impl_span = tcx.def_span(drop_impl_did);
let fresh_impl_substs = let fresh_impl_substs =
infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did.to_def_id()); infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did.to_def_id());
let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs); let fresh_impl_self_ty = EarlyBinder(drop_impl_ty).subst(tcx, fresh_impl_substs);
let cause = &ObligationCause::misc(drop_impl_span, drop_impl_hir_id); let cause = &ObligationCause::misc(drop_impl_span, drop_impl_hir_id);
match infcx.at(cause, impl_param_env).eq(named_type, fresh_impl_self_ty) { match infcx.at(cause, impl_param_env).eq(named_type, fresh_impl_self_ty) {

View file

@ -23,8 +23,8 @@ use rustc_middle::ty::subst::{
self, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSelfTy, UserSubsts, self, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSelfTy, UserSubsts,
}; };
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, CanonicalUserType, DefIdTree, GenericParamDefKind, ToPolyTraitRef, ToPredicate, self, AdtKind, CanonicalUserType, DefIdTree, EarlyBinder, GenericParamDefKind, ToPolyTraitRef,
Ty, UserType, ToPredicate, Ty, UserType,
}; };
use rustc_session::lint; use rustc_session::lint;
use rustc_span::hygiene::DesugaringKind; use rustc_span::hygiene::DesugaringKind;
@ -347,7 +347,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
debug!("instantiate_type_scheme(value={:?}, substs={:?})", value, substs); debug!("instantiate_type_scheme(value={:?}, substs={:?})", value, substs);
let value = value.subst(self.tcx, substs); let value = EarlyBinder(value).subst(self.tcx, substs);
let result = self.normalize_associated_types_in(span, value); let result = self.normalize_associated_types_in(span, value);
debug!("instantiate_type_scheme = {:?}", result); debug!("instantiate_type_scheme = {:?}", result);
result result
@ -843,7 +843,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.type_of(def_id) self.tcx.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 = item_ty.subst(self.tcx, substs); let ty = EarlyBinder(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(
@ -1044,8 +1044,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) { ) {
let (sig, did, substs) = match (&expected.kind(), &found.kind()) { let (sig, did, substs) = match (&expected.kind(), &found.kind()) {
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => { (ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1); let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2); let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
if sig1 != sig2 { if sig1 != sig2 {
return; return;
} }
@ -1056,7 +1056,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(sig1, *did1, substs1) (sig1, *did1, substs1)
} }
(ty::FnDef(did, substs), ty::FnPtr(sig2)) => { (ty::FnDef(did, substs), ty::FnPtr(sig2)) => {
let sig1 = self.tcx.fn_sig(*did).subst(self.tcx, substs); let sig1 = EarlyBinder(self.tcx.fn_sig(*did)).subst(self.tcx, substs);
if sig1 != *sig2 { if sig1 != *sig2 {
return; return;
} }
@ -1403,7 +1403,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// is missing. // is missing.
let default = tcx.type_of(param.def_id); let default = tcx.type_of(param.def_id);
self.fcx self.fcx
.normalize_ty(self.span, default.subst(tcx, substs.unwrap())) .normalize_ty(
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.
@ -1415,7 +1418,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
GenericParamDefKind::Const { has_default } => { GenericParamDefKind::Const { has_default } => {
if !infer_args && has_default { if !infer_args && has_default {
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into() EarlyBinder(tcx.const_param_default(param.def_id))
.subst(tcx, substs.unwrap())
.into()
} else { } else {
self.fcx.var_for_def(self.span, param) self.fcx.var_for_def(self.span, param)
} }

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, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, 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 = tcx.type_of(did).subst(tcx, &[region.into()]); let va_list_ty = EarlyBinder(tcx.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

@ -11,7 +11,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::{self, Subst, SubstsRef}; use rustc_middle::ty::subst::{self, Subst, SubstsRef};
use rustc_middle::ty::{self, GenericParamDefKind, Ty}; use rustc_middle::ty::{self, EarlyBinder, GenericParamDefKind, Ty};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
@ -462,7 +462,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let sig = self.tcx.fn_sig(def_id); let sig = self.tcx.fn_sig(def_id);
let sig = sig.subst(self.tcx, all_substs); let sig = EarlyBinder(sig).subst(self.tcx, all_substs);
debug!("type scheme substituted, sig={:?}", sig); debug!("type scheme substituted, sig={:?}", sig);
let sig = self.replace_bound_vars_with_fresh_vars(sig); let sig = self.replace_bound_vars_with_fresh_vars(sig);

View file

@ -21,7 +21,7 @@ use rustc_infer::infer::{self, InferOk};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef}; use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable}; use rustc_middle::ty::{self, EarlyBinder, ToPredicate, Ty, TypeFoldable};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
@ -461,7 +461,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// `instantiate_type_scheme` can normalize associated types that // `instantiate_type_scheme` can normalize associated types that
// may reference those regions. // may reference those regions.
let fn_sig = tcx.fn_sig(def_id); let fn_sig = tcx.fn_sig(def_id);
let fn_sig = fn_sig.subst(self.tcx, substs); let fn_sig = EarlyBinder(fn_sig).subst(self.tcx, substs);
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0; let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
let InferOk { value, obligations: o } = if is_op { let InferOk { value, obligations: o } = if is_op {

View file

@ -21,7 +21,7 @@ use rustc_middle::middle::stability;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, EarlyBinder, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::lev_distance::{ use rustc_span::lev_distance::{
@ -711,7 +711,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} }
let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id); let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
let impl_ty = impl_ty.subst(self.tcx, impl_substs); let impl_ty = EarlyBinder(impl_ty).subst(self.tcx, impl_substs);
debug!("impl_ty: {:?}", impl_ty); debug!("impl_ty: {:?}", impl_ty);
@ -904,7 +904,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let fty = self.tcx.fn_sig(method.def_id); let fty = self.tcx.fn_sig(method.def_id);
self.probe(|_| { self.probe(|_| {
let substs = self.fresh_substs_for_item(self.span, method.def_id); let substs = self.fresh_substs_for_item(self.span, method.def_id);
let fty = fty.subst(self.tcx, substs); let fty = EarlyBinder(fty).subst(self.tcx, substs);
let (fty, _) = let (fty, _) =
self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty); self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
@ -1785,7 +1785,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
assert_eq!(substs.len(), generics.parent_count as usize); assert_eq!(substs.len(), generics.parent_count as usize);
let xform_fn_sig = if generics.params.is_empty() { let xform_fn_sig = if generics.params.is_empty() {
fn_sig.subst(self.tcx, substs) EarlyBinder(fn_sig).subst(self.tcx, substs)
} else { } else {
let substs = InternalSubsts::for_item(self.tcx, method, |param, _| { let substs = InternalSubsts::for_item(self.tcx, method, |param, _| {
let i = param.index as usize; let i = param.index as usize;
@ -1803,7 +1803,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} }
} }
}); });
fn_sig.subst(self.tcx, substs) EarlyBinder(fn_sig).subst(self.tcx, substs)
}; };
self.erase_late_bound_regions(xform_fn_sig) self.erase_late_bound_regions(xform_fn_sig)

View file

@ -21,7 +21,8 @@ use rustc_middle::hir::nested_filter;
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst}; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst};
use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitor, self, AdtKind, EarlyBinder, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable,
TypeVisitor,
}; };
use rustc_session::parse::feature_err; use rustc_session::parse::feature_err;
use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::symbol::{sym, Ident, Symbol};
@ -1388,7 +1389,7 @@ fn check_where_clauses<'tcx, 'fcx>(
} }
let mut param_count = CountParams::default(); let mut param_count = CountParams::default();
let has_region = pred.visit_with(&mut param_count).is_break(); let has_region = pred.visit_with(&mut param_count).is_break();
let substituted_pred = pred.subst(tcx, substs); let substituted_pred = EarlyBinder(pred).subst(tcx, substs);
// Don't check non-defaulted params, dependent defaults (including lifetimes) // Don't check non-defaulted params, dependent defaults (including lifetimes)
// or preds with multiple params. // or preds with multiple params.
if substituted_pred.has_param_types_or_consts() if substituted_pred.has_param_types_or_consts()

View file

@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use super::explicit::ExplicitPredicatesMap; use super::explicit::ExplicitPredicatesMap;
@ -137,7 +137,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
// `unsubstituted_predicate` is `U: 'b` in the // `unsubstituted_predicate` is `U: 'b` in the
// example above. So apply the substitution to // example above. So apply the substitution to
// get `T: 'a` (or `predicate`): // get `T: 'a` (or `predicate`):
let predicate = unsubstituted_predicate.subst(tcx, substs); let predicate = EarlyBinder(*unsubstituted_predicate).subst(tcx, substs);
insert_outlives_predicate( insert_outlives_predicate(
tcx, tcx,
predicate.0, predicate.0,
@ -287,7 +287,7 @@ pub fn check_explicit_predicates<'tcx>(
continue; continue;
} }
let predicate = outlives_predicate.subst(tcx, substs); let predicate = EarlyBinder(*outlives_predicate).subst(tcx, substs);
debug!("predicate = {:?}", &predicate); debug!("predicate = {:?}", &predicate);
insert_outlives_predicate(tcx, predicate.0, predicate.1, span, required_predicates); insert_outlives_predicate(tcx, predicate.0, predicate.1, span, required_predicates);
} }

View file

@ -38,11 +38,11 @@ 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 = ty.subst(infcx.tcx, substs); let ty = EarlyBinder(ty).subst(infcx.tcx, substs);
let param_env = 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);
let trait_ref = trait_ref.subst(infcx.tcx, impl_substs); let trait_ref = EarlyBinder(trait_ref).subst(infcx.tcx, impl_substs);
// Require the type the impl is implemented on to match // Require the type the impl is implemented on to match
// our type, and ignore the impl if there was a mismatch. // our type, and ignore the impl if there was a mismatch.

View file

@ -21,7 +21,7 @@ use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::middle::resolve_lifetime as rl;
use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{self, AdtKind, DefIdTree, Lift, Ty, TyCtxt}; use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Lift, Ty, TyCtxt};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::hygiene::{AstPass, MacroKind};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
@ -1634,7 +1634,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
.tcx .tcx
.explicit_item_bounds(def_id) .explicit_item_bounds(def_id)
.iter() .iter()
.map(|(bound, _)| bound.subst(cx.tcx, substs)) .map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, substs))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mut regions = vec![]; let mut regions = vec![];
let mut has_sized = false; let mut has_sized = false;

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, Ty, TypeFoldable}; use rustc_middle::ty::{self, ClosureKind, EarlyBinder, 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 = cx.tcx.type_of(method_def_id).subst(cx.tcx, substs); let call_ty = EarlyBinder(cx.tcx.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

@ -5,7 +5,7 @@ use rustc_hir::{Body, FnDecl, HirId};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
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::{Opaque, PredicateKind::Trait}; use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
let preds = cx.tcx.explicit_item_bounds(id); let preds = cx.tcx.explicit_item_bounds(id);
let mut is_future = false; let mut is_future = false;
for &(p, _span) in preds { for &(p, _span) in preds {
let p = p.subst(cx.tcx, subst); let p = EarlyBinder(p).subst(cx.tcx, subst);
if let Some(trait_pred) = p.to_opt_poly_trait_pred() { if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
is_future = true; is_future = true;

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, Ty}; use rustc_middle::ty::{self, EarlyBinder, 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 = cx.tcx.type_of(def_id).subst(cx.tcx, substs); let method_type = EarlyBinder(cx.tcx.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, IntTy, Ty, TypeAndMut, UintTy}; use rustc_middle::ty::{self, EarlyBinder, 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| cx.tcx.type_of(f.did).subst(cx.tcx, substs)); .map(|f| EarlyBinder(cx.tcx.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;
}; };

View file

@ -9,7 +9,7 @@ use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind,
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::interpret::Scalar;
use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use std::cmp::Ordering::{self, Equal}; use std::cmp::Ordering::{self, Equal};
@ -420,7 +420,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
let substs = if self.substs.is_empty() { let substs = if self.substs.is_empty() {
substs substs
} else { } else {
substs.subst(self.lcx.tcx, self.substs) EarlyBinder(substs).subst(self.lcx.tcx, self.substs)
}; };
let result = self let result = self

View file

@ -13,7 +13,7 @@ use rustc_lint::LateContext;
use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::mir::interpret::{ConstValue, Scalar};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtDef, Binder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr, self, AdtDef, Binder, EarlyBinder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr,
}; };
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::{sym, Span, Symbol, DUMMY_SP}; use rustc_span::{sym, Span, Symbol, DUMMY_SP};
@ -520,7 +520,7 @@ pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<ExprFnS
let ty = cx.typeck_results().expr_ty_adjusted(expr).peel_refs(); let ty = cx.typeck_results().expr_ty_adjusted(expr).peel_refs();
match *ty.kind() { match *ty.kind() {
ty::Closure(_, subs) => Some(ExprFnSig::Closure(subs.as_closure().sig())), ty::Closure(_, subs) => Some(ExprFnSig::Closure(subs.as_closure().sig())),
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst(cx.tcx, subs))), ty::FnDef(id, subs) => Some(ExprFnSig::Sig(EarlyBinder(cx.tcx.fn_sig(id)).subst(cx.tcx, subs))),
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig)),
ty::Dynamic(bounds, _) => { ty::Dynamic(bounds, _) => {
let lang_items = cx.tcx.lang_items(); let lang_items = cx.tcx.lang_items();