refactor(rustc_middle): Substs -> GenericArg
This commit is contained in:
parent
df5c2cf9bc
commit
e55583c4b8
466 changed files with 4574 additions and 4604 deletions
|
@ -7,8 +7,8 @@ use rustc_middle::mir::{
|
|||
Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, SourceInfo, Statement,
|
||||
StatementKind, Terminator, TerminatorKind, UserTypeProjection,
|
||||
};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
|
||||
|
||||
use crate::{
|
||||
|
@ -49,11 +49,11 @@ struct ConstraintGeneration<'cg, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
|
||||
/// We sometimes have `substs` within an rvalue, or within a
|
||||
/// We sometimes have `args` within an rvalue, or within a
|
||||
/// call. Make them live at the location where they appear.
|
||||
fn visit_substs(&mut self, substs: &SubstsRef<'tcx>, location: Location) {
|
||||
self.add_regular_live_constraint(*substs, location);
|
||||
self.super_substs(substs);
|
||||
fn visit_args(&mut self, args: &GenericArgsRef<'tcx>, location: Location) {
|
||||
self.add_regular_live_constraint(*args, location);
|
||||
self.super_args(args);
|
||||
}
|
||||
|
||||
/// We sometimes have `region` within an rvalue, or within a
|
||||
|
|
|
@ -702,11 +702,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
.iter()
|
||||
.copied()
|
||||
.find_map(find_fn_kind_from_did),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => tcx
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx
|
||||
.explicit_item_bounds(def_id)
|
||||
.subst_iter_copied(tcx, substs)
|
||||
.arg_iter_copied(tcx, args)
|
||||
.find_map(|(clause, span)| find_fn_kind_from_did((clause, span))),
|
||||
ty::Closure(_, substs) => match substs.as_closure().kind() {
|
||||
ty::Closure(_, args) => match args.as_closure().kind() {
|
||||
ty::ClosureKind::Fn => Some(hir::Mutability::Not),
|
||||
ty::ClosureKind::FnMut => Some(hir::Mutability::Mut),
|
||||
_ => None,
|
||||
|
@ -1448,11 +1448,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
// Get closure's arguments
|
||||
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else {
|
||||
let ty::Closure(_, args) = typeck_results.expr_ty(closure_expr).kind() else {
|
||||
/* hir::Closure can be a generator too */
|
||||
return;
|
||||
};
|
||||
let sig = substs.as_closure().sig();
|
||||
let sig = args.as_closure().sig();
|
||||
let tupled_params =
|
||||
tcx.erase_late_bound_regions(sig.inputs().iter().next().unwrap().map_bound(|&b| b));
|
||||
let ty::Tuple(params) = tupled_params.kind() else { return };
|
||||
|
@ -2676,7 +2676,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
kind: TerminatorKind::Call { call_source: CallSource::OverloadedOperator, .. },
|
||||
..
|
||||
}),
|
||||
Some((method_did, method_substs)),
|
||||
Some((method_did, method_args)),
|
||||
) = (
|
||||
&self.body[loan.reserve_location.block].terminator,
|
||||
rustc_middle::util::find_self_call(
|
||||
|
@ -2689,7 +2689,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
if tcx.is_diagnostic_item(sym::deref_method, method_did) {
|
||||
let deref_target =
|
||||
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
|
||||
Instance::resolve(tcx, self.param_env, deref_target, method_substs)
|
||||
Instance::resolve(tcx, self.param_env, deref_target, method_args)
|
||||
.transpose()
|
||||
});
|
||||
if let Some(Ok(instance)) = deref_target {
|
||||
|
@ -2856,11 +2856,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
if is_closure {
|
||||
None
|
||||
} else {
|
||||
let ty = self.infcx.tcx.type_of(self.mir_def_id()).subst_identity();
|
||||
let ty = self.infcx.tcx.type_of(self.mir_def_id()).instantiate_identity();
|
||||
match ty.kind() {
|
||||
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
|
||||
self.mir_def_id(),
|
||||
self.infcx.tcx.fn_sig(self.mir_def_id()).subst_identity(),
|
||||
self.infcx.tcx.fn_sig(self.mir_def_id()).instantiate_identity(),
|
||||
),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -2902,7 +2902,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
);
|
||||
// Check if our `target` was captured by a closure.
|
||||
if let Rvalue::Aggregate(
|
||||
box AggregateKind::Closure(def_id, substs),
|
||||
box AggregateKind::Closure(def_id, args),
|
||||
operands,
|
||||
) = rvalue
|
||||
{
|
||||
|
@ -2933,7 +2933,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
// into a place then we should annotate the closure in
|
||||
// case it ends up being assigned into the return place.
|
||||
annotated_closure =
|
||||
self.annotate_fn_sig(def_id, substs.as_closure().sig());
|
||||
self.annotate_fn_sig(def_id, args.as_closure().sig());
|
||||
debug!(
|
||||
"annotate_argument_and_return_for_borrow: \
|
||||
annotated_closure={:?} assigned_from_local={:?} \
|
||||
|
|
|
@ -168,17 +168,17 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
|||
let local_decl = &body.local_decls[dropped_local];
|
||||
let mut ty = local_decl.ty;
|
||||
if local_decl.source_info.span.desugaring_kind() == Some(DesugaringKind::ForLoop) {
|
||||
if let ty::Adt(adt, substs) = local_decl.ty.kind() {
|
||||
if let ty::Adt(adt, args) = local_decl.ty.kind() {
|
||||
if tcx.is_diagnostic_item(sym::Option, adt.did()) {
|
||||
// in for loop desugaring, only look at the `Some(..)` inner type
|
||||
ty = substs.type_at(0);
|
||||
ty = args.type_at(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
let (dtor_desc, type_desc) = match ty.kind() {
|
||||
// If type is an ADT that implements Drop, then
|
||||
// simplify output by reporting just the ADT name.
|
||||
ty::Adt(adt, _substs) if adt.has_dtor(tcx) && !adt.is_box() => {
|
||||
ty::Adt(adt, _args) if adt.has_dtor(tcx) && !adt.is_box() => {
|
||||
("`Drop` code", format!("type `{}`", tcx.def_path_str(adt.did())))
|
||||
}
|
||||
|
||||
|
|
|
@ -732,18 +732,18 @@ impl<'tcx> BorrowedContentSource<'tcx> {
|
|||
|
||||
fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Self> {
|
||||
match *func.kind() {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
ty::FnDef(def_id, args) => {
|
||||
let trait_id = tcx.trait_of_item(def_id)?;
|
||||
|
||||
let lang_items = tcx.lang_items();
|
||||
if Some(trait_id) == lang_items.deref_trait()
|
||||
|| Some(trait_id) == lang_items.deref_mut_trait()
|
||||
{
|
||||
Some(BorrowedContentSource::OverloadedDeref(substs.type_at(0)))
|
||||
Some(BorrowedContentSource::OverloadedDeref(args.type_at(0)))
|
||||
} else if Some(trait_id) == lang_items.index_trait()
|
||||
|| Some(trait_id) == lang_items.index_mut_trait()
|
||||
{
|
||||
Some(BorrowedContentSource::OverloadedIndex(substs.type_at(0)))
|
||||
Some(BorrowedContentSource::OverloadedIndex(args.type_at(0)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -847,7 +847,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
kind: TerminatorKind::Call { fn_span, call_source, .. }, ..
|
||||
}) = &self.body[location.block].terminator
|
||||
{
|
||||
let Some((method_did, method_substs)) = rustc_middle::util::find_self_call(
|
||||
let Some((method_did, method_args)) = rustc_middle::util::find_self_call(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
target_temp,
|
||||
|
@ -860,7 +860,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self.infcx.tcx,
|
||||
self.param_env,
|
||||
method_did,
|
||||
method_substs,
|
||||
method_args,
|
||||
*fn_span,
|
||||
call_source.from_hir_call(),
|
||||
Some(self.infcx.tcx.fn_arg_names(method_did)[0]),
|
||||
|
@ -1039,7 +1039,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
});
|
||||
}
|
||||
}
|
||||
CallKind::Normal { self_arg, desugaring, method_did, method_substs } => {
|
||||
CallKind::Normal { self_arg, desugaring, method_did, method_args } => {
|
||||
let self_arg = self_arg.unwrap();
|
||||
let tcx = self.infcx.tcx;
|
||||
if let Some((CallDesugaringKind::ForLoopIntoIter, _)) = desugaring {
|
||||
|
@ -1106,13 +1106,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
// Erase and shadow everything that could be passed to the new infcx.
|
||||
let ty = moved_place.ty(self.body, tcx).ty;
|
||||
|
||||
if let ty::Adt(def, substs) = ty.kind()
|
||||
if let ty::Adt(def, args) = ty.kind()
|
||||
&& Some(def.did()) == tcx.lang_items().pin_type()
|
||||
&& let ty::Ref(_, _, hir::Mutability::Mut) = substs.type_at(0).kind()
|
||||
&& let ty::Ref(_, _, hir::Mutability::Mut) = args.type_at(0).kind()
|
||||
&& let self_ty = self.infcx.instantiate_binder_with_fresh_vars(
|
||||
fn_call_span,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
tcx.fn_sig(method_did).subst(tcx, method_substs).input(0),
|
||||
tcx.fn_sig(method_did).instantiate(tcx, method_args).input(0),
|
||||
)
|
||||
&& self.infcx.can_eq(self.param_env, ty, self_ty)
|
||||
{
|
||||
|
@ -1161,7 +1161,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
let parent_self_ty =
|
||||
matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. })
|
||||
.then_some(parent_did)
|
||||
.and_then(|did| match tcx.type_of(did).subst_identity().kind() {
|
||||
.and_then(|did| match tcx.type_of(did).instantiate_identity().kind() {
|
||||
ty::Adt(def, ..) => Some(def.did()),
|
||||
_ => None,
|
||||
});
|
||||
|
|
|
@ -324,10 +324,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
ty::Array(..) | ty::Slice(..) => {
|
||||
self.cannot_move_out_of_interior_noncopy(span, ty, None)
|
||||
}
|
||||
ty::Closure(def_id, closure_substs)
|
||||
ty::Closure(def_id, closure_args)
|
||||
if def_id.as_local() == Some(self.mir_def_id()) && upvar_field.is_some() =>
|
||||
{
|
||||
let closure_kind_ty = closure_substs.as_closure().kind_ty();
|
||||
let closure_kind_ty = closure_args.as_closure().kind_ty();
|
||||
let closure_kind = match closure_kind_ty.to_opt_closure_kind() {
|
||||
Some(kind @ (ty::ClosureKind::Fn | ty::ClosureKind::FnMut)) => kind,
|
||||
Some(ty::ClosureKind::FnOnce) => {
|
||||
|
|
|
@ -22,7 +22,7 @@ use rustc_infer::infer::{
|
|||
};
|
||||
use rustc_middle::hir::place::PlaceBase;
|
||||
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::GenericArgs;
|
||||
use rustc_middle::ty::TypeVisitor;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty};
|
||||
use rustc_middle::ty::{Region, TyCtxt};
|
||||
|
@ -183,9 +183,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
|
||||
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref()
|
||||
&& let ty::BoundRegionKind::BrEnv = free_region.bound_region
|
||||
&& let DefiningTy::Closure(_, substs) = self.regioncx.universal_regions().defining_ty
|
||||
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
|
||||
{
|
||||
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
|
||||
return args.as_closure().kind() == ty::ClosureKind::FnMut;
|
||||
}
|
||||
|
||||
false
|
||||
|
@ -502,12 +502,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
.to_string(),
|
||||
)
|
||||
}
|
||||
ty::Adt(adt, substs) => {
|
||||
let generic_arg = substs[param_index as usize];
|
||||
let identity_substs =
|
||||
InternalSubsts::identity_for_item(self.infcx.tcx, adt.did());
|
||||
let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_substs);
|
||||
let base_generic_arg = identity_substs[param_index as usize];
|
||||
ty::Adt(adt, args) => {
|
||||
let generic_arg = args[param_index as usize];
|
||||
let identity_args =
|
||||
GenericArgs::identity_for_item(self.infcx.tcx, adt.did());
|
||||
let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_args);
|
||||
let base_generic_arg = identity_args[param_index as usize];
|
||||
let adt_desc = adt.descr();
|
||||
|
||||
let desc = format!(
|
||||
|
@ -520,12 +520,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
}
|
||||
ty::FnDef(def_id, _) => {
|
||||
let name = self.infcx.tcx.item_name(*def_id);
|
||||
let identity_substs =
|
||||
InternalSubsts::identity_for_item(self.infcx.tcx, *def_id);
|
||||
let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, *def_id);
|
||||
let desc = format!("a function pointer to `{name}`");
|
||||
let note = format!(
|
||||
"the function `{name}` is invariant over the parameter `{}`",
|
||||
identity_substs[param_index as usize]
|
||||
identity_args[param_index as usize]
|
||||
);
|
||||
(desc, note)
|
||||
}
|
||||
|
@ -573,7 +572,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
|
||||
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
|
||||
output_ty = self.infcx.tcx.type_of(def_id).subst_identity()
|
||||
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity()
|
||||
};
|
||||
|
||||
debug!("report_fnmut_error: output_ty={:?}", output_ty);
|
||||
|
@ -899,14 +898,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
let tcx = self.infcx.tcx;
|
||||
|
||||
let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
|
||||
let (fn_did, substs) = match func_ty.kind() {
|
||||
ty::FnDef(fn_did, substs) => (fn_did, substs),
|
||||
let (fn_did, args) = match func_ty.kind() {
|
||||
ty::FnDef(fn_did, args) => (fn_did, args),
|
||||
_ => return,
|
||||
};
|
||||
debug!(?fn_did, ?substs);
|
||||
debug!(?fn_did, ?args);
|
||||
|
||||
// Only suggest this on function calls, not closures
|
||||
let ty = tcx.type_of(fn_did).subst_identity();
|
||||
let ty = tcx.type_of(fn_did).instantiate_identity();
|
||||
debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind());
|
||||
if let ty::Closure(_, _) = ty.kind() {
|
||||
return;
|
||||
|
@ -916,7 +915,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
tcx,
|
||||
self.param_env,
|
||||
*fn_did,
|
||||
self.infcx.resolve_vars_if_possible(substs),
|
||||
self.infcx.resolve_vars_if_possible(args),
|
||||
) {
|
||||
instance
|
||||
} else {
|
||||
|
|
|
@ -5,8 +5,8 @@ use rustc_errors::Diagnostic;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_middle::ty::print::RegionHighlightMode;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::{self, RegionVid, Ty};
|
||||
use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
|
@ -321,7 +321,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
ty::BoundRegionKind::BrEnv => {
|
||||
let def_ty = self.regioncx.universal_regions().defining_ty;
|
||||
|
||||
let DefiningTy::Closure(_, substs) = def_ty else {
|
||||
let DefiningTy::Closure(_, args) = def_ty else {
|
||||
// Can't have BrEnv in functions, constants or generators.
|
||||
bug!("BrEnv outside of closure.");
|
||||
};
|
||||
|
@ -332,7 +332,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
};
|
||||
let region_name = self.synthesize_region_name();
|
||||
|
||||
let closure_kind_ty = substs.as_closure().kind_ty();
|
||||
let closure_kind_ty = args.as_closure().kind_ty();
|
||||
let note = match closure_kind_ty.to_opt_closure_kind() {
|
||||
Some(ty::ClosureKind::Fn) => {
|
||||
"closure implements `Fn`, so references to captured variables \
|
||||
|
@ -510,10 +510,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
// Match up something like `Foo<'1>`
|
||||
(
|
||||
ty::Adt(_adt_def, substs),
|
||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)),
|
||||
) => {
|
||||
(ty::Adt(_adt_def, args), hir::TyKind::Path(hir::QPath::Resolved(None, path))) => {
|
||||
match path.res {
|
||||
// Type parameters of the type alias have no reason to
|
||||
// be the same as those of the ADT.
|
||||
|
@ -523,7 +520,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
_ => {
|
||||
if let Some(last_segment) = path.segments.last() {
|
||||
if let Some(highlight) = self.match_adt_and_segment(
|
||||
substs,
|
||||
args,
|
||||
needle_fr,
|
||||
last_segment,
|
||||
search_stack,
|
||||
|
@ -560,22 +557,22 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
None
|
||||
}
|
||||
|
||||
/// We've found an enum/struct/union type with the substitutions
|
||||
/// `substs` and -- in the HIR -- a path type with the final
|
||||
/// We've found an enum/struct/union type with the generic args
|
||||
/// `args` and -- in the HIR -- a path type with the final
|
||||
/// segment `last_segment`. Try to find a `'_` to highlight in
|
||||
/// the generic args (or, if not, to produce new zipped pairs of
|
||||
/// types+hir to search through).
|
||||
fn match_adt_and_segment<'hir>(
|
||||
&self,
|
||||
substs: SubstsRef<'tcx>,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
needle_fr: RegionVid,
|
||||
last_segment: &'hir hir::PathSegment<'hir>,
|
||||
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
|
||||
) -> Option<RegionNameHighlight> {
|
||||
// Did the user give explicit arguments? (e.g., `Foo<..>`)
|
||||
let args = last_segment.args.as_ref()?;
|
||||
let explicit_args = last_segment.args.as_ref()?;
|
||||
let lifetime =
|
||||
self.try_match_adt_and_generic_args(substs, needle_fr, args, search_stack)?;
|
||||
self.try_match_adt_and_generic_args(args, needle_fr, explicit_args, search_stack)?;
|
||||
if lifetime.is_anonymous() {
|
||||
None
|
||||
} else {
|
||||
|
@ -583,19 +580,19 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// We've found an enum/struct/union type with the substitutions
|
||||
/// `substs` and -- in the HIR -- a path with the generic
|
||||
/// arguments `args`. If `needle_fr` appears in the args, return
|
||||
/// We've found an enum/struct/union type with the generic args
|
||||
/// `args` and -- in the HIR -- a path with the generic
|
||||
/// arguments `hir_args`. If `needle_fr` appears in the args, return
|
||||
/// the `hir::Lifetime` that corresponds to it. If not, push onto
|
||||
/// `search_stack` the types+hir to search through.
|
||||
fn try_match_adt_and_generic_args<'hir>(
|
||||
&self,
|
||||
substs: SubstsRef<'tcx>,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
needle_fr: RegionVid,
|
||||
args: &'hir hir::GenericArgs<'hir>,
|
||||
hir_args: &'hir hir::GenericArgs<'hir>,
|
||||
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
|
||||
) -> Option<&'hir hir::Lifetime> {
|
||||
for (kind, hir_arg) in iter::zip(substs, args.args) {
|
||||
for (kind, hir_arg) in iter::zip(args, hir_args.args) {
|
||||
match (kind.unpack(), hir_arg) {
|
||||
(GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => {
|
||||
if r.as_var() == needle_fr {
|
||||
|
@ -849,9 +846,10 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
return None;
|
||||
};
|
||||
|
||||
let found = tcx.any_free_region_meets(&tcx.type_of(region_parent).subst_identity(), |r| {
|
||||
*r == ty::ReEarlyBound(region)
|
||||
});
|
||||
let found = tcx
|
||||
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
|
||||
*r == ty::ReEarlyBound(region)
|
||||
});
|
||||
|
||||
Some(RegionName {
|
||||
name: self.synthesize_region_name(),
|
||||
|
|
|
@ -301,7 +301,7 @@ fn do_mir_borrowck<'tcx>(
|
|||
let movable_generator =
|
||||
// The first argument is the generator type passed by value
|
||||
if let Some(local) = body.local_decls.raw.get(1)
|
||||
// Get the interior types and substs which typeck computed
|
||||
// Get the interior types and args which typeck computed
|
||||
&& let ty::Generator(_, _, hir::Movability::Static) = local.ty.kind()
|
||||
{
|
||||
false
|
||||
|
|
|
@ -1115,7 +1115,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
) -> Option<ClosureOutlivesSubject<'tcx>> {
|
||||
let tcx = infcx.tcx;
|
||||
|
||||
// Opaque types' substs may include useless lifetimes.
|
||||
// Opaque types' args may include useless lifetimes.
|
||||
// We will replace them with ReStatic.
|
||||
struct OpaqueFolder<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
@ -1127,19 +1127,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
use ty::TypeSuperFoldable as _;
|
||||
let tcx = self.tcx;
|
||||
let &ty::Alias(ty::Opaque, ty::AliasTy { substs, def_id, .. }) = t.kind() else {
|
||||
let &ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else {
|
||||
return t.super_fold_with(self);
|
||||
};
|
||||
let substs =
|
||||
std::iter::zip(substs, tcx.variances_of(def_id)).map(|(arg, v)| {
|
||||
match (arg.unpack(), v) {
|
||||
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => {
|
||||
tcx.lifetimes.re_static.into()
|
||||
}
|
||||
_ => arg.fold_with(self),
|
||||
let args = std::iter::zip(args, tcx.variances_of(def_id)).map(|(arg, v)| {
|
||||
match (arg.unpack(), v) {
|
||||
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => {
|
||||
tcx.lifetimes.re_static.into()
|
||||
}
|
||||
});
|
||||
Ty::new_opaque(tcx, def_id, tcx.mk_substs_from_iter(substs))
|
||||
_ => arg.fold_with(self),
|
||||
}
|
||||
});
|
||||
Ty::new_opaque(tcx, def_id, tcx.mk_args_from_iter(args))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ use rustc_infer::infer::InferCtxt;
|
|||
use rustc_infer::infer::TyCtxtInferExt as _;
|
||||
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||
use rustc_middle::traits::DefiningAnchor;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
|
||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{GenericArgKind, GenericArgs};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
|
@ -38,15 +38,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
/// back to concrete lifetimes: `'static`, `ReEarlyBound` or `ReFree`.
|
||||
///
|
||||
/// First we map all the lifetimes in the concrete type to an equal
|
||||
/// universal region that occurs in the concrete type's substs, in this case
|
||||
/// this would result in `&'1 i32`. We only consider regions in the substs
|
||||
/// universal region that occurs in the concrete type's args, in this case
|
||||
/// this would result in `&'1 i32`. We only consider regions in the args
|
||||
/// in case there is an equal region that does not. For example, this should
|
||||
/// be allowed:
|
||||
/// `fn f<'a: 'b, 'b: 'a>(x: *mut &'b i32) -> impl Sized + 'a { x }`
|
||||
///
|
||||
/// Then we map the regions in both the type and the subst to their
|
||||
/// `external_name` giving `concrete_type = &'a i32`,
|
||||
/// `substs = ['static, 'a]`. This will then allow
|
||||
/// `args = ['static, 'a]`. This will then allow
|
||||
/// `infer_opaque_definition_from_instantiation` to determine that
|
||||
/// `_Return<'_a> = &'_a i32`.
|
||||
///
|
||||
|
@ -73,8 +73,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
debug!(?member_constraints);
|
||||
|
||||
for (opaque_type_key, concrete_type) in opaque_ty_decls {
|
||||
let substs = opaque_type_key.substs;
|
||||
debug!(?concrete_type, ?substs);
|
||||
let args = opaque_type_key.args;
|
||||
debug!(?concrete_type, ?args);
|
||||
|
||||
let mut subst_regions = vec![self.universal_regions.fr_static];
|
||||
|
||||
|
@ -95,7 +95,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
ty::Region::new_error_with_message(
|
||||
infcx.tcx,
|
||||
concrete_type.span,
|
||||
"opaque type with non-universal region substs",
|
||||
"opaque type with non-universal region args",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -110,17 +110,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
}
|
||||
debug!(?subst_regions);
|
||||
|
||||
// Next, insert universal regions from substs, so we can translate regions that appear
|
||||
// in them but are not subject to member constraints, for instance closure substs.
|
||||
let universal_substs = infcx.tcx.fold_regions(substs, |region, _| {
|
||||
// Next, insert universal regions from args, so we can translate regions that appear
|
||||
// in them but are not subject to member constraints, for instance closure args.
|
||||
let universal_args = infcx.tcx.fold_regions(args, |region, _| {
|
||||
if let ty::RePlaceholder(..) = region.kind() {
|
||||
// Higher kinded regions don't need remapping, they don't refer to anything outside of this the substs.
|
||||
// Higher kinded regions don't need remapping, they don't refer to anything outside of this the args.
|
||||
return region;
|
||||
}
|
||||
let vid = self.to_region_vid(region);
|
||||
to_universal_region(vid, &mut subst_regions)
|
||||
});
|
||||
debug!(?universal_substs);
|
||||
debug!(?universal_args);
|
||||
debug!(?subst_regions);
|
||||
|
||||
// Deduplicate the set of regions while keeping the chosen order.
|
||||
|
@ -139,7 +139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
debug!(?universal_concrete_type);
|
||||
|
||||
let opaque_type_key =
|
||||
OpaqueTypeKey { def_id: opaque_type_key.def_id, substs: universal_substs };
|
||||
OpaqueTypeKey { def_id: opaque_type_key.def_id, args: universal_args };
|
||||
let ty = infcx.infer_opaque_definition_from_instantiation(
|
||||
opaque_type_key,
|
||||
universal_concrete_type,
|
||||
|
@ -175,7 +175,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
|
||||
/// Map the regions in the type to named regions. This is similar to what
|
||||
/// `infer_opaque_types` does, but can infer any universal region, not only
|
||||
/// ones from the substs for the opaque type. It also doesn't double check
|
||||
/// ones from the args for the opaque type. It also doesn't double check
|
||||
/// that the regions produced are in fact equal to the named region they are
|
||||
/// replaced with. This is fine because this function is only to improve the
|
||||
/// region names in error messages.
|
||||
|
@ -238,7 +238,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
/// # Parameters
|
||||
///
|
||||
/// - `def_id`, the `impl Trait` type
|
||||
/// - `substs`, the substs used to instantiate this opaque type
|
||||
/// - `args`, the args used to instantiate this opaque type
|
||||
/// - `instantiated_ty`, the inferred type C1 -- fully resolved, lifted version of
|
||||
/// `opaque_defn.concrete_ty`
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
|
@ -309,11 +309,11 @@ fn check_opaque_type_well_formed<'tcx>(
|
|||
})
|
||||
.build();
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let identity_args = GenericArgs::identity_for_item(tcx, def_id);
|
||||
|
||||
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
|
||||
// the bounds that the function supplies.
|
||||
let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), identity_substs);
|
||||
let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), identity_args);
|
||||
ocx.eq(&ObligationCause::misc(definition_span, def_id), param_env, opaque_ty, definition_ty)
|
||||
.map_err(|err| {
|
||||
infcx
|
||||
|
@ -384,7 +384,7 @@ fn check_opaque_type_parameter_valid(
|
|||
}
|
||||
let opaque_generics = tcx.generics_of(opaque_type_key.def_id);
|
||||
let mut seen_params: FxIndexMap<_, Vec<_>> = FxIndexMap::default();
|
||||
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
|
||||
for (i, arg) in opaque_type_key.args.iter().enumerate() {
|
||||
let arg_is_param = match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
|
||||
GenericArgKind::Lifetime(lt) => {
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_infer::infer::NllRegionVariableOrigin;
|
|||
use rustc_middle::mir::visit::{MutVisitor, TyContext};
|
||||
use rustc_middle::mir::Constant;
|
||||
use rustc_middle::mir::{Body, Location, Promoted};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
|
@ -94,10 +94,10 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
|
|||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
|
||||
*substs = self.renumber_regions(*substs, || RegionCtxt::Location(location));
|
||||
fn visit_args(&mut self, args: &mut GenericArgsRef<'tcx>, location: Location) {
|
||||
*args = self.renumber_regions(*args, || RegionCtxt::Location(location));
|
||||
|
||||
debug!(?substs);
|
||||
debug!(?args);
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelega
|
|||
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
|
||||
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
|
||||
use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::GenericArgKind;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_middle::ty::{TypeFoldable, TypeVisitableExt};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
@ -89,20 +89,20 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
|
|||
|
||||
/// Given an instance of the closure type, this method instantiates the "extra" requirements
|
||||
/// that we computed for the closure. This has the effect of adding new outlives obligations
|
||||
/// to existing region variables in `closure_substs`.
|
||||
/// to existing region variables in `closure_args`.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn apply_closure_requirements(
|
||||
&mut self,
|
||||
closure_requirements: &ClosureRegionRequirements<'tcx>,
|
||||
closure_def_id: DefId,
|
||||
closure_substs: ty::SubstsRef<'tcx>,
|
||||
closure_args: ty::GenericArgsRef<'tcx>,
|
||||
) {
|
||||
// Extract the values of the free regions in `closure_substs`
|
||||
// Extract the values of the free regions in `closure_args`
|
||||
// into a vector. These are the regions that we will be
|
||||
// relating to one another.
|
||||
let closure_mapping = &UniversalRegions::closure_mapping(
|
||||
self.tcx,
|
||||
closure_substs,
|
||||
closure_args,
|
||||
closure_requirements.num_external_vids,
|
||||
closure_def_id.expect_local(),
|
||||
);
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::def_use::{self, DefUse};
|
|||
use crate::location::{LocationIndex, LocationTable};
|
||||
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{Body, Local, Location, Place};
|
||||
use rustc_middle::ty::subst::GenericArg;
|
||||
use rustc_middle::ty::GenericArg;
|
||||
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
|
||||
|
||||
use super::TypeChecker;
|
||||
|
|
|
@ -30,12 +30,12 @@ use rustc_middle::traits::query::NoSolution;
|
|||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||
use rustc_middle::ty::cast::CastTy;
|
||||
use rustc_middle::ty::subst::{SubstsRef, UserSubsts};
|
||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
|
||||
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArgsRef, UserArgs};
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
@ -389,15 +389,12 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
|||
} else {
|
||||
self.cx.ascribe_user_type(
|
||||
constant.literal.ty(),
|
||||
UserType::TypeOf(
|
||||
uv.def,
|
||||
UserSubsts { substs: uv.substs, user_self_ty: None },
|
||||
),
|
||||
UserType::TypeOf(uv.def, UserArgs { args: uv.args, user_self_ty: None }),
|
||||
locations.span(&self.cx.body),
|
||||
);
|
||||
}
|
||||
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
|
||||
let unnormalized_ty = tcx.type_of(static_def_id).subst_identity();
|
||||
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
|
||||
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
|
||||
let literal_ty = constant.literal.ty().builtin_deref(true).unwrap().ty;
|
||||
|
||||
|
@ -411,11 +408,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
if let ty::FnDef(def_id, substs) = *constant.literal.ty().kind() {
|
||||
if let ty::FnDef(def_id, args) = *constant.literal.ty().kind() {
|
||||
// const_trait_impl: use a non-const param env when checking that a FnDef type is well formed.
|
||||
// this is because the well-formedness of the function does not need to be proved to have `const`
|
||||
// impls for trait bounds.
|
||||
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);
|
||||
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
|
||||
let prev = self.cx.param_env;
|
||||
self.cx.param_env = prev.without_const();
|
||||
self.cx.normalize_and_prove_instantiated_predicates(
|
||||
|
@ -666,7 +663,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
})
|
||||
}
|
||||
ProjectionElem::Downcast(maybe_name, index) => match base_ty.kind() {
|
||||
ty::Adt(adt_def, _substs) if adt_def.is_enum() => {
|
||||
ty::Adt(adt_def, _args) if adt_def.is_enum() => {
|
||||
if index.as_usize() >= adt_def.variants().len() {
|
||||
PlaceTy::from_ty(span_mirbug_and_err!(
|
||||
self,
|
||||
|
@ -776,16 +773,16 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
) -> Result<Ty<'tcx>, FieldAccessError> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
let (variant, substs) = match base_ty {
|
||||
let (variant, args) = match base_ty {
|
||||
PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() {
|
||||
ty::Adt(adt_def, substs) => (adt_def.variant(variant_index), substs),
|
||||
ty::Generator(def_id, substs, _) => {
|
||||
let mut variants = substs.as_generator().state_tys(def_id, tcx);
|
||||
ty::Adt(adt_def, args) => (adt_def.variant(variant_index), args),
|
||||
ty::Generator(def_id, args, _) => {
|
||||
let mut variants = args.as_generator().state_tys(def_id, tcx);
|
||||
let Some(mut variant) = variants.nth(variant_index.into()) else {
|
||||
bug!(
|
||||
"variant_index of generator out of range: {:?}/{:?}",
|
||||
variant_index,
|
||||
substs.as_generator().state_tys(def_id, tcx).count()
|
||||
args.as_generator().state_tys(def_id, tcx).count()
|
||||
);
|
||||
};
|
||||
return match variant.nth(field.index()) {
|
||||
|
@ -796,11 +793,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
_ => bug!("can't have downcast of non-adt non-generator type"),
|
||||
},
|
||||
PlaceTy { ty, variant_index: None } => match *ty.kind() {
|
||||
ty::Adt(adt_def, substs) if !adt_def.is_enum() => {
|
||||
(adt_def.variant(FIRST_VARIANT), substs)
|
||||
ty::Adt(adt_def, args) if !adt_def.is_enum() => {
|
||||
(adt_def.variant(FIRST_VARIANT), args)
|
||||
}
|
||||
ty::Closure(_, substs) => {
|
||||
return match substs
|
||||
ty::Closure(_, args) => {
|
||||
return match args
|
||||
.as_closure()
|
||||
.tupled_upvars_ty()
|
||||
.tuple_fields()
|
||||
|
@ -808,17 +805,17 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
{
|
||||
Some(&ty) => Ok(ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: substs.as_closure().upvar_tys().count(),
|
||||
field_count: args.as_closure().upvar_tys().count(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
ty::Generator(_, substs, _) => {
|
||||
ty::Generator(_, args, _) => {
|
||||
// Only prefix fields (upvars and current state) are
|
||||
// accessible without a variant index.
|
||||
return match substs.as_generator().prefix_tys().nth(field.index()) {
|
||||
return match args.as_generator().prefix_tys().nth(field.index()) {
|
||||
Some(ty) => Ok(ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: substs.as_generator().prefix_tys().count(),
|
||||
field_count: args.as_generator().prefix_tys().count(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
@ -840,7 +837,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
};
|
||||
|
||||
if let Some(field) = variant.fields.get(field) {
|
||||
Ok(self.cx.normalize(field.ty(tcx, substs), location))
|
||||
Ok(self.cx.normalize(field.ty(tcx, args), location))
|
||||
} else {
|
||||
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
|
||||
}
|
||||
|
@ -1065,7 +1062,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
|
||||
ocx.infcx.add_item_bounds_for_hidden_type(
|
||||
opaque_type_key.def_id.to_def_id(),
|
||||
opaque_type_key.substs,
|
||||
opaque_type_key.args,
|
||||
cause,
|
||||
param_env,
|
||||
hidden_ty.ty,
|
||||
|
@ -1770,32 +1767,32 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let tcx = self.tcx();
|
||||
|
||||
match *ak {
|
||||
AggregateKind::Adt(adt_did, variant_index, substs, _, active_field_index) => {
|
||||
AggregateKind::Adt(adt_did, variant_index, args, _, active_field_index) => {
|
||||
let def = tcx.adt_def(adt_did);
|
||||
let variant = &def.variant(variant_index);
|
||||
let adj_field_index = active_field_index.unwrap_or(field_index);
|
||||
if let Some(field) = variant.fields.get(adj_field_index) {
|
||||
Ok(self.normalize(field.ty(tcx, substs), location))
|
||||
Ok(self.normalize(field.ty(tcx, args), location))
|
||||
} else {
|
||||
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
|
||||
}
|
||||
}
|
||||
AggregateKind::Closure(_, substs) => {
|
||||
match substs.as_closure().upvar_tys().nth(field_index.as_usize()) {
|
||||
AggregateKind::Closure(_, args) => {
|
||||
match args.as_closure().upvar_tys().nth(field_index.as_usize()) {
|
||||
Some(ty) => Ok(ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: substs.as_closure().upvar_tys().count(),
|
||||
field_count: args.as_closure().upvar_tys().count(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
AggregateKind::Generator(_, substs, _) => {
|
||||
AggregateKind::Generator(_, args, _) => {
|
||||
// It doesn't make sense to look at a field beyond the prefix;
|
||||
// these require a variant index, and are not initialized in
|
||||
// aggregate rvalues.
|
||||
match substs.as_generator().prefix_tys().nth(field_index.as_usize()) {
|
||||
match args.as_generator().prefix_tys().nth(field_index.as_usize()) {
|
||||
Some(ty) => Ok(ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: substs.as_generator().prefix_tys().count(),
|
||||
field_count: args.as_generator().prefix_tys().count(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -1821,8 +1818,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let def_id = uv.def;
|
||||
if tcx.def_kind(def_id) == DefKind::InlineConst {
|
||||
let def_id = def_id.expect_local();
|
||||
let predicates =
|
||||
self.prove_closure_bounds(tcx, def_id, uv.substs, location);
|
||||
let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location);
|
||||
self.normalize_and_prove_instantiated_predicates(
|
||||
def_id.to_def_id(),
|
||||
predicates,
|
||||
|
@ -1939,7 +1935,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
|
||||
CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(unsafety)) => {
|
||||
let sig = match op.ty(body, tcx).kind() {
|
||||
ty::Closure(_, substs) => substs.as_closure().sig(),
|
||||
ty::Closure(_, args) => args.as_closure().sig(),
|
||||
_ => bug!(),
|
||||
};
|
||||
let ty_fn_ptr_from =
|
||||
|
@ -2591,8 +2587,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
);
|
||||
|
||||
let (def_id, instantiated_predicates) = match *aggregate_kind {
|
||||
AggregateKind::Adt(adt_did, _, substs, _, _) => {
|
||||
(adt_did, tcx.predicates_of(adt_did).instantiate(tcx, substs))
|
||||
AggregateKind::Adt(adt_did, _, args, _, _) => {
|
||||
(adt_did, tcx.predicates_of(adt_did).instantiate(tcx, args))
|
||||
}
|
||||
|
||||
// For closures, we have some **extra requirements** we
|
||||
|
@ -2614,9 +2610,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
// desugaring. A closure gets desugared to a struct, and
|
||||
// these extra requirements are basically like where
|
||||
// clauses on the struct.
|
||||
AggregateKind::Closure(def_id, substs)
|
||||
| AggregateKind::Generator(def_id, substs, _) => {
|
||||
(def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), substs, location))
|
||||
AggregateKind::Closure(def_id, args) | AggregateKind::Generator(def_id, args, _) => {
|
||||
(def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
|
||||
}
|
||||
|
||||
AggregateKind::Array(_) | AggregateKind::Tuple => {
|
||||
|
@ -2635,7 +2630,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
&mut self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
substs: SubstsRef<'tcx>,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
location: Location,
|
||||
) -> ty::InstantiatedPredicates<'tcx> {
|
||||
if let Some(closure_requirements) = &tcx.mir_borrowck(def_id).closure_requirements {
|
||||
|
@ -2653,26 +2648,26 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
.apply_closure_requirements(
|
||||
&closure_requirements,
|
||||
def_id.to_def_id(),
|
||||
substs,
|
||||
args,
|
||||
);
|
||||
}
|
||||
|
||||
// Now equate closure substs to regions inherited from `typeck_root_def_id`. Fixes #98589.
|
||||
// Now equate closure args to regions inherited from `typeck_root_def_id`. Fixes #98589.
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(self.body.source.def_id());
|
||||
let typeck_root_substs = ty::InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
|
||||
let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id);
|
||||
|
||||
let parent_substs = match tcx.def_kind(def_id) {
|
||||
DefKind::Closure => substs.as_closure().parent_substs(),
|
||||
DefKind::Generator => substs.as_generator().parent_substs(),
|
||||
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
|
||||
let parent_args = match tcx.def_kind(def_id) {
|
||||
DefKind::Closure => args.as_closure().parent_args(),
|
||||
DefKind::Generator => args.as_generator().parent_args(),
|
||||
DefKind::InlineConst => args.as_inline_const().parent_args(),
|
||||
other => bug!("unexpected item {:?}", other),
|
||||
};
|
||||
let parent_substs = tcx.mk_substs(parent_substs);
|
||||
let parent_args = tcx.mk_args(parent_args);
|
||||
|
||||
assert_eq!(typeck_root_substs.len(), parent_substs.len());
|
||||
if let Err(_) = self.eq_substs(
|
||||
typeck_root_substs,
|
||||
parent_substs,
|
||||
assert_eq!(typeck_root_args.len(), parent_args.len());
|
||||
if let Err(_) = self.eq_args(
|
||||
typeck_root_args,
|
||||
parent_args,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::BoringNoLocation,
|
||||
) {
|
||||
|
@ -2680,12 +2675,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
self,
|
||||
def_id,
|
||||
"could not relate closure to parent {:?} != {:?}",
|
||||
typeck_root_substs,
|
||||
parent_substs
|
||||
typeck_root_args,
|
||||
parent_args
|
||||
);
|
||||
}
|
||||
|
||||
tcx.predicates_of(def_id).instantiate(tcx, substs)
|
||||
tcx.predicates_of(def_id).instantiate(tcx, args)
|
||||
}
|
||||
|
||||
#[instrument(skip(self, body), level = "debug")]
|
||||
|
|
|
@ -42,10 +42,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Add sufficient constraints to ensure `a == b`. See also [Self::relate_types].
|
||||
pub(super) fn eq_substs(
|
||||
pub(super) fn eq_args(
|
||||
&mut self,
|
||||
a: ty::SubstsRef<'tcx>,
|
||||
b: ty::SubstsRef<'tcx>,
|
||||
a: ty::GenericArgsRef<'tcx>,
|
||||
b: ty::GenericArgsRef<'tcx>,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
) -> Result<(), NoSolution> {
|
||||
|
|
|
@ -22,8 +22,8 @@ use rustc_hir::BodyOwnerKind;
|
|||
use rustc_index::IndexVec;
|
||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{InternalSubsts, SubstsRef};
|
||||
use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::Symbol;
|
||||
use std::iter;
|
||||
|
@ -88,26 +88,26 @@ pub struct UniversalRegions<'tcx> {
|
|||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum DefiningTy<'tcx> {
|
||||
/// The MIR is a closure. The signature is found via
|
||||
/// `ClosureSubsts::closure_sig_ty`.
|
||||
Closure(DefId, SubstsRef<'tcx>),
|
||||
/// `ClosureArgs::closure_sig_ty`.
|
||||
Closure(DefId, GenericArgsRef<'tcx>),
|
||||
|
||||
/// The MIR is a generator. The signature is that generators take
|
||||
/// no parameters and return the result of
|
||||
/// `ClosureSubsts::generator_return_ty`.
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
|
||||
/// `ClosureArgs::generator_return_ty`.
|
||||
Generator(DefId, GenericArgsRef<'tcx>, hir::Movability),
|
||||
|
||||
/// The MIR is a fn item with the given `DefId` and substs. The signature
|
||||
/// The MIR is a fn item with the given `DefId` and args. The signature
|
||||
/// of the function can be bound then with the `fn_sig` query.
|
||||
FnDef(DefId, SubstsRef<'tcx>),
|
||||
FnDef(DefId, GenericArgsRef<'tcx>),
|
||||
|
||||
/// The MIR represents some form of constant. The signature then
|
||||
/// is that it has no inputs and a single return value, which is
|
||||
/// the value of the constant.
|
||||
Const(DefId, SubstsRef<'tcx>),
|
||||
Const(DefId, GenericArgsRef<'tcx>),
|
||||
|
||||
/// The MIR represents an inline const. The signature has no inputs and a
|
||||
/// single return value found via `InlineConstSubsts::ty`.
|
||||
InlineConst(DefId, SubstsRef<'tcx>),
|
||||
/// single return value found via `InlineConstArgs::ty`.
|
||||
InlineConst(DefId, GenericArgsRef<'tcx>),
|
||||
}
|
||||
|
||||
impl<'tcx> DefiningTy<'tcx> {
|
||||
|
@ -117,9 +117,9 @@ impl<'tcx> DefiningTy<'tcx> {
|
|||
/// match up with the upvar order in the HIR, typesystem, and MIR.
|
||||
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
||||
match self {
|
||||
DefiningTy::Closure(_, substs) => Either::Left(substs.as_closure().upvar_tys()),
|
||||
DefiningTy::Generator(_, substs, _) => {
|
||||
Either::Right(Either::Left(substs.as_generator().upvar_tys()))
|
||||
DefiningTy::Closure(_, args) => Either::Left(args.as_closure().upvar_tys()),
|
||||
DefiningTy::Generator(_, args, _) => {
|
||||
Either::Right(Either::Left(args.as_generator().upvar_tys()))
|
||||
}
|
||||
DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => {
|
||||
Either::Right(Either::Right(iter::empty()))
|
||||
|
@ -164,9 +164,9 @@ struct UniversalRegionIndices<'tcx> {
|
|||
/// used because trait matching and type-checking will feed us
|
||||
/// region constraints that reference those regions and we need to
|
||||
/// be able to map them to our internal `RegionVid`. This is
|
||||
/// basically equivalent to an `InternalSubsts`, except that it also
|
||||
/// basically equivalent to an `GenericArgs`, except that it also
|
||||
/// contains an entry for `ReStatic` -- it might be nice to just
|
||||
/// use a substs, and then handle `ReStatic` another way.
|
||||
/// use a args, and then handle `ReStatic` another way.
|
||||
indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
|
||||
|
||||
/// The vid assigned to `'static`. Used only for diagnostics.
|
||||
|
@ -243,13 +243,13 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||
/// `V[1]: V[2]`.
|
||||
pub fn closure_mapping(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
closure_substs: SubstsRef<'tcx>,
|
||||
closure_args: GenericArgsRef<'tcx>,
|
||||
expected_num_vars: usize,
|
||||
closure_def_id: LocalDefId,
|
||||
) -> IndexVec<RegionVid, ty::Region<'tcx>> {
|
||||
let mut region_mapping = IndexVec::with_capacity(expected_num_vars);
|
||||
region_mapping.push(tcx.lifetimes.re_static);
|
||||
tcx.for_each_free_region(&closure_substs, |fr| {
|
||||
tcx.for_each_free_region(&closure_args, |fr| {
|
||||
region_mapping.push(fr);
|
||||
});
|
||||
|
||||
|
@ -334,11 +334,11 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||
/// state.
|
||||
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
|
||||
match self.defining_ty {
|
||||
DefiningTy::Closure(def_id, substs) => {
|
||||
DefiningTy::Closure(def_id, args) => {
|
||||
err.note(format!(
|
||||
"defining type: {} with closure substs {:#?}",
|
||||
tcx.def_path_str_with_substs(def_id, substs),
|
||||
&substs[tcx.generics_of(def_id).parent_count..],
|
||||
"defining type: {} with closure args {:#?}",
|
||||
tcx.def_path_str_with_args(def_id, args),
|
||||
&args[tcx.generics_of(def_id).parent_count..],
|
||||
));
|
||||
|
||||
// FIXME: It'd be nice to print the late-bound regions
|
||||
|
@ -350,11 +350,11 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||
err.note(format!("late-bound region is {:?}", self.to_region_vid(r)));
|
||||
});
|
||||
}
|
||||
DefiningTy::Generator(def_id, substs, _) => {
|
||||
DefiningTy::Generator(def_id, args, _) => {
|
||||
err.note(format!(
|
||||
"defining type: {} with generator substs {:#?}",
|
||||
tcx.def_path_str_with_substs(def_id, substs),
|
||||
&substs[tcx.generics_of(def_id).parent_count..],
|
||||
"defining type: {} with generator args {:#?}",
|
||||
tcx.def_path_str_with_args(def_id, args),
|
||||
&args[tcx.generics_of(def_id).parent_count..],
|
||||
));
|
||||
|
||||
// FIXME: As above, we'd like to print out the region
|
||||
|
@ -364,22 +364,19 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||
err.note(format!("late-bound region is {:?}", self.to_region_vid(r)));
|
||||
});
|
||||
}
|
||||
DefiningTy::FnDef(def_id, substs) => {
|
||||
err.note(format!(
|
||||
"defining type: {}",
|
||||
tcx.def_path_str_with_substs(def_id, substs),
|
||||
));
|
||||
DefiningTy::FnDef(def_id, args) => {
|
||||
err.note(format!("defining type: {}", tcx.def_path_str_with_args(def_id, args),));
|
||||
}
|
||||
DefiningTy::Const(def_id, substs) => {
|
||||
DefiningTy::Const(def_id, args) => {
|
||||
err.note(format!(
|
||||
"defining constant type: {}",
|
||||
tcx.def_path_str_with_substs(def_id, substs),
|
||||
tcx.def_path_str_with_args(def_id, args),
|
||||
));
|
||||
}
|
||||
DefiningTy::InlineConst(def_id, substs) => {
|
||||
DefiningTy::InlineConst(def_id, args) => {
|
||||
err.note(format!(
|
||||
"defining inline constant type: {}",
|
||||
tcx.def_path_str_with_substs(def_id, substs),
|
||||
tcx.def_path_str_with_args(def_id, args),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -501,8 +498,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
.as_var();
|
||||
|
||||
let region = ty::Region::new_var(self.infcx.tcx, reg_vid);
|
||||
let va_list_ty =
|
||||
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
|
||||
let va_list_ty = self
|
||||
.infcx
|
||||
.tcx
|
||||
.type_of(va_list_did)
|
||||
.instantiate(self.infcx.tcx, &[region.into()]);
|
||||
|
||||
unnormalized_input_tys = self.infcx.tcx.mk_type_list_from_iter(
|
||||
unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)),
|
||||
|
@ -522,7 +522,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
debug!("build: local regions = {}..{}", first_local_index, num_universals);
|
||||
|
||||
let yield_ty = match defining_ty {
|
||||
DefiningTy::Generator(_, substs, _) => Some(substs.as_generator().yield_ty()),
|
||||
DefiningTy::Generator(_, args, _) => Some(args.as_generator().yield_ty()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -548,7 +548,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
|
||||
match tcx.hir().body_owner_kind(self.mir_def) {
|
||||
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
|
||||
let defining_ty = tcx.type_of(self.mir_def).subst_identity();
|
||||
let defining_ty = tcx.type_of(self.mir_def).instantiate_identity();
|
||||
|
||||
debug!("defining_ty (pre-replacement): {:?}", defining_ty);
|
||||
|
||||
|
@ -556,11 +556,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, defining_ty);
|
||||
|
||||
match *defining_ty.kind() {
|
||||
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs),
|
||||
ty::Generator(def_id, substs, movability) => {
|
||||
DefiningTy::Generator(def_id, substs, movability)
|
||||
ty::Closure(def_id, args) => DefiningTy::Closure(def_id, args),
|
||||
ty::Generator(def_id, args, movability) => {
|
||||
DefiningTy::Generator(def_id, args, movability)
|
||||
}
|
||||
ty::FnDef(def_id, substs) => DefiningTy::FnDef(def_id, substs),
|
||||
ty::FnDef(def_id, args) => DefiningTy::FnDef(def_id, args),
|
||||
_ => span_bug!(
|
||||
tcx.def_span(self.mir_def),
|
||||
"expected defining type for `{:?}`: `{:?}`",
|
||||
|
@ -571,11 +571,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
BodyOwnerKind::Const | BodyOwnerKind::Static(..) => {
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
|
||||
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
|
||||
if self.mir_def.to_def_id() == typeck_root_def_id {
|
||||
let substs =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
|
||||
DefiningTy::Const(self.mir_def.to_def_id(), substs)
|
||||
let args =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_args);
|
||||
DefiningTy::Const(self.mir_def.to_def_id(), args)
|
||||
} else {
|
||||
// FIXME this line creates a dependency between borrowck and typeck.
|
||||
//
|
||||
|
@ -584,18 +584,18 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
// into borrowck, which is ICE #78174.
|
||||
//
|
||||
// As a workaround, inline consts have an additional generic param (`ty`
|
||||
// below), so that `type_of(inline_const_def_id).substs(substs)` uses the
|
||||
// below), so that `type_of(inline_const_def_id).args(args)` uses the
|
||||
// proper type with NLL infer vars.
|
||||
let ty = tcx
|
||||
.typeck(self.mir_def)
|
||||
.node_type(tcx.local_def_id_to_hir_id(self.mir_def));
|
||||
let substs = InlineConstSubsts::new(
|
||||
let args = InlineConstArgs::new(
|
||||
tcx,
|
||||
InlineConstSubstsParts { parent_substs: identity_substs, ty },
|
||||
InlineConstArgsParts { parent_args: identity_args, ty },
|
||||
)
|
||||
.substs;
|
||||
let substs = self.infcx.replace_free_regions_with_nll_infer_vars(FR, substs);
|
||||
DefiningTy::InlineConst(self.mir_def.to_def_id(), substs)
|
||||
.args;
|
||||
let args = self.infcx.replace_free_regions_with_nll_infer_vars(FR, args);
|
||||
DefiningTy::InlineConst(self.mir_def.to_def_id(), args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -612,29 +612,29 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
) -> UniversalRegionIndices<'tcx> {
|
||||
let tcx = self.infcx.tcx;
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
|
||||
let fr_substs = match defining_ty {
|
||||
DefiningTy::Closure(_, substs)
|
||||
| DefiningTy::Generator(_, substs, _)
|
||||
| DefiningTy::InlineConst(_, substs) => {
|
||||
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
|
||||
let fr_args = match defining_ty {
|
||||
DefiningTy::Closure(_, args)
|
||||
| DefiningTy::Generator(_, args, _)
|
||||
| DefiningTy::InlineConst(_, args) => {
|
||||
// In the case of closures, we rely on the fact that
|
||||
// the first N elements in the ClosureSubsts are
|
||||
// the first N elements in the ClosureArgs are
|
||||
// inherited from the `typeck_root_def_id`.
|
||||
// Therefore, when we zip together (below) with
|
||||
// `identity_substs`, we will get only those regions
|
||||
// `identity_args`, we will get only those regions
|
||||
// that correspond to early-bound regions declared on
|
||||
// the `typeck_root_def_id`.
|
||||
assert!(substs.len() >= identity_substs.len());
|
||||
assert_eq!(substs.regions().count(), identity_substs.regions().count());
|
||||
substs
|
||||
assert!(args.len() >= identity_args.len());
|
||||
assert_eq!(args.regions().count(), identity_args.regions().count());
|
||||
args
|
||||
}
|
||||
|
||||
DefiningTy::FnDef(_, substs) | DefiningTy::Const(_, substs) => substs,
|
||||
DefiningTy::FnDef(_, args) | DefiningTy::Const(_, args) => args,
|
||||
};
|
||||
|
||||
let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
|
||||
let subst_mapping =
|
||||
iter::zip(identity_substs.regions(), fr_substs.regions().map(|r| r.as_var()));
|
||||
iter::zip(identity_args.regions(), fr_args.regions().map(|r| r.as_var()));
|
||||
|
||||
UniversalRegionIndices { indices: global_mapping.chain(subst_mapping).collect(), fr_static }
|
||||
}
|
||||
|
@ -646,9 +646,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
) -> ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>> {
|
||||
let tcx = self.infcx.tcx;
|
||||
match defining_ty {
|
||||
DefiningTy::Closure(def_id, substs) => {
|
||||
DefiningTy::Closure(def_id, args) => {
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let closure_sig = substs.as_closure().sig();
|
||||
let closure_sig = args.as_closure().sig();
|
||||
let inputs_and_output = closure_sig.inputs_and_output();
|
||||
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
|
||||
inputs_and_output
|
||||
|
@ -661,7 +661,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
kind: ty::BrEnv,
|
||||
};
|
||||
let env_region = ty::Region::new_late_bound(tcx, ty::INNERMOST, br);
|
||||
let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
|
||||
let closure_ty = tcx.closure_env_ty(def_id, args, env_region).unwrap();
|
||||
|
||||
// The "inputs" of the closure in the
|
||||
// signature appear as a tuple. The MIR side
|
||||
|
@ -681,18 +681,18 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
)
|
||||
}
|
||||
|
||||
DefiningTy::Generator(def_id, substs, movability) => {
|
||||
DefiningTy::Generator(def_id, args, movability) => {
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let resume_ty = substs.as_generator().resume_ty();
|
||||
let output = substs.as_generator().return_ty();
|
||||
let generator_ty = Ty::new_generator(tcx, def_id, substs, movability);
|
||||
let resume_ty = args.as_generator().resume_ty();
|
||||
let output = args.as_generator().return_ty();
|
||||
let generator_ty = Ty::new_generator(tcx, def_id, args, movability);
|
||||
let inputs_and_output =
|
||||
self.infcx.tcx.mk_type_list(&[generator_ty, resume_ty, output]);
|
||||
ty::Binder::dummy(inputs_and_output)
|
||||
}
|
||||
|
||||
DefiningTy::FnDef(def_id, _) => {
|
||||
let sig = tcx.fn_sig(def_id).subst_identity();
|
||||
let sig = tcx.fn_sig(def_id).instantiate_identity();
|
||||
let sig = indices.fold_to_region_vids(tcx, sig);
|
||||
sig.inputs_and_output()
|
||||
}
|
||||
|
@ -701,14 +701,14 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
// For a constant body, there are no inputs, and one
|
||||
// "output" (the type of the constant).
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let ty = tcx.type_of(self.mir_def).subst_identity();
|
||||
let ty = tcx.type_of(self.mir_def).instantiate_identity();
|
||||
let ty = indices.fold_to_region_vids(tcx, ty);
|
||||
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
|
||||
}
|
||||
|
||||
DefiningTy::InlineConst(def_id, substs) => {
|
||||
DefiningTy::InlineConst(def_id, args) => {
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let ty = substs.as_inline_const().ty();
|
||||
let ty = args.as_inline_const().ty();
|
||||
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue