refactor(rustc_middle): Substs -> GenericArg
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//! as well as errors when attempting to call a non-const function in a const
|
||||
//! context.
|
||||
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::GenericArgsRef;
|
||||
use crate::ty::{AssocItemContainer, Instance, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{lang_items, LangItem};
|
||||
@@ -43,7 +43,7 @@ pub enum CallKind<'tcx> {
|
||||
self_arg: Option<Ident>,
|
||||
desugaring: Option<(CallDesugaringKind, Ty<'tcx>)>,
|
||||
method_did: DefId,
|
||||
method_substs: SubstsRef<'tcx>,
|
||||
method_args: GenericArgsRef<'tcx>,
|
||||
},
|
||||
/// A call to `Fn(..)::call(..)`, desugared from `my_closure(a, b, c)`
|
||||
FnCall { fn_trait_id: DefId, self_ty: Ty<'tcx> },
|
||||
@@ -63,7 +63,7 @@ pub fn call_kind<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
method_did: DefId,
|
||||
method_substs: SubstsRef<'tcx>,
|
||||
method_args: GenericArgsRef<'tcx>,
|
||||
fn_call_span: Span,
|
||||
from_hir_call: bool,
|
||||
self_arg: Option<Ident>,
|
||||
@@ -92,19 +92,19 @@ pub fn call_kind<'tcx>(
|
||||
// an FnOnce call, an operator (e.g. `<<`), or a
|
||||
// deref coercion.
|
||||
let kind = if let Some(trait_id) = fn_call {
|
||||
Some(CallKind::FnCall { fn_trait_id: trait_id, self_ty: method_substs.type_at(0) })
|
||||
Some(CallKind::FnCall { fn_trait_id: trait_id, self_ty: method_args.type_at(0) })
|
||||
} else if let Some(trait_id) = operator {
|
||||
Some(CallKind::Operator { self_arg, trait_id, self_ty: method_substs.type_at(0) })
|
||||
Some(CallKind::Operator { self_arg, trait_id, self_ty: method_args.type_at(0) })
|
||||
} else if is_deref {
|
||||
let deref_target = tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
|
||||
Instance::resolve(tcx, param_env, deref_target, method_substs).transpose()
|
||||
Instance::resolve(tcx, param_env, deref_target, method_args).transpose()
|
||||
});
|
||||
if let Some(Ok(instance)) = deref_target {
|
||||
let deref_target_ty = instance.ty(tcx, param_env);
|
||||
Some(CallKind::DerefCoercion {
|
||||
deref_target: tcx.def_span(instance.def_id()),
|
||||
deref_target_ty,
|
||||
self_ty: method_substs.type_at(0),
|
||||
self_ty: method_args.type_at(0),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
@@ -119,24 +119,24 @@ pub fn call_kind<'tcx>(
|
||||
let desugaring = if Some(method_did) == tcx.lang_items().into_iter_fn()
|
||||
&& fn_call_span.desugaring_kind() == Some(DesugaringKind::ForLoop)
|
||||
{
|
||||
Some((CallDesugaringKind::ForLoopIntoIter, method_substs.type_at(0)))
|
||||
Some((CallDesugaringKind::ForLoopIntoIter, method_args.type_at(0)))
|
||||
} else if fn_call_span.desugaring_kind() == Some(DesugaringKind::QuestionMark) {
|
||||
if Some(method_did) == tcx.lang_items().branch_fn() {
|
||||
Some((CallDesugaringKind::QuestionBranch, method_substs.type_at(0)))
|
||||
Some((CallDesugaringKind::QuestionBranch, method_args.type_at(0)))
|
||||
} else if Some(method_did) == tcx.lang_items().from_residual_fn() {
|
||||
Some((CallDesugaringKind::QuestionFromResidual, method_substs.type_at(0)))
|
||||
Some((CallDesugaringKind::QuestionFromResidual, method_args.type_at(0)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else if Some(method_did) == tcx.lang_items().from_output_fn()
|
||||
&& fn_call_span.desugaring_kind() == Some(DesugaringKind::TryBlock)
|
||||
{
|
||||
Some((CallDesugaringKind::TryBlockFromOutput, method_substs.type_at(0)))
|
||||
Some((CallDesugaringKind::TryBlockFromOutput, method_args.type_at(0)))
|
||||
} else if fn_call_span.is_desugaring(DesugaringKind::Await) {
|
||||
Some((CallDesugaringKind::Await, method_substs.type_at(0)))
|
||||
Some((CallDesugaringKind::Await, method_args.type_at(0)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
CallKind::Normal { self_arg, desugaring, method_did, method_substs }
|
||||
CallKind::Normal { self_arg, desugaring, method_did, method_args }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::mir::*;
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::GenericArgsRef;
|
||||
use crate::ty::{self, TyCtxt};
|
||||
use rustc_span::def_id::DefId;
|
||||
|
||||
@@ -11,21 +11,21 @@ pub fn find_self_call<'tcx>(
|
||||
body: &Body<'tcx>,
|
||||
local: Local,
|
||||
block: BasicBlock,
|
||||
) -> Option<(DefId, SubstsRef<'tcx>)> {
|
||||
) -> Option<(DefId, GenericArgsRef<'tcx>)> {
|
||||
debug!("find_self_call(local={:?}): terminator={:?}", local, &body[block].terminator);
|
||||
if let Some(Terminator { kind: TerminatorKind::Call { func, args, .. }, .. }) =
|
||||
&body[block].terminator
|
||||
{
|
||||
debug!("find_self_call: func={:?}", func);
|
||||
if let Operand::Constant(box Constant { literal, .. }) = func {
|
||||
if let ty::FnDef(def_id, substs) = *literal.ty().kind() {
|
||||
if let ty::FnDef(def_id, fn_args) = *literal.ty().kind() {
|
||||
if let Some(ty::AssocItem { fn_has_self_parameter: true, .. }) =
|
||||
tcx.opt_associated_item(def_id)
|
||||
{
|
||||
debug!("find_self_call: args={:?}", args);
|
||||
debug!("find_self_call: args={:?}", fn_args);
|
||||
if let [Operand::Move(self_place) | Operand::Copy(self_place), ..] = **args {
|
||||
if self_place.as_local() == Some(local) {
|
||||
return Some((def_id, substs));
|
||||
return Some((def_id, fn_args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user