add is_async_fn query
This commit is contained in:
parent
528379121c
commit
2fd4c27c32
5 changed files with 19 additions and 0 deletions
|
@ -244,6 +244,10 @@ rustc_queries! {
|
||||||
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query is_async_fn(key: DefId) -> hir::IsAsync {
|
||||||
|
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if calls to the function may be promoted.
|
/// Returns `true` if calls to the function may be promoted.
|
||||||
///
|
///
|
||||||
/// This is either because the function is e.g., a tuple-struct or tuple-variant
|
/// This is either because the function is e.g., a tuple-struct or tuple-variant
|
||||||
|
|
|
@ -133,6 +133,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
|
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
|
||||||
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
||||||
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
|
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
|
||||||
|
is_async_fn { cdata.fn_asyncness(def_id.index) }
|
||||||
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||||
static_mutability => { cdata.static_mutability(def_id.index) }
|
static_mutability => { cdata.static_mutability(def_id.index) }
|
||||||
def_kind => { cdata.def_kind(def_id.index) }
|
def_kind => { cdata.def_kind(def_id.index) }
|
||||||
|
|
|
@ -1208,6 +1208,15 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
constness == hir::Constness::Const
|
constness == hir::Constness::Const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_async_fn(&self, id: DefIndex) -> bool {
|
||||||
|
let asyncness = match self.entry(id).kind {
|
||||||
|
EntryKind::Fn(data) => data.decode(self).asyncness,
|
||||||
|
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
|
||||||
|
_ => hir::IsAsync::NotAsync,
|
||||||
|
};
|
||||||
|
asyncness == hir::IsAsync::Async
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
|
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
|
||||||
match self.entry(id).kind {
|
match self.entry(id).kind {
|
||||||
EntryKind::ForeignImmStatic |
|
EntryKind::ForeignImmStatic |
|
||||||
|
|
|
@ -885,6 +885,7 @@ impl EncodeContext<'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
FnData {
|
FnData {
|
||||||
|
asyncness: hir::IsAsync::NotAsync,
|
||||||
constness: hir::Constness::NotConst,
|
constness: hir::Constness::NotConst,
|
||||||
param_names,
|
param_names,
|
||||||
sig: self.lazy(&tcx.fn_sig(def_id)),
|
sig: self.lazy(&tcx.fn_sig(def_id)),
|
||||||
|
@ -982,6 +983,7 @@ impl EncodeContext<'tcx> {
|
||||||
ty::AssocKind::Method => {
|
ty::AssocKind::Method => {
|
||||||
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
|
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
|
||||||
FnData {
|
FnData {
|
||||||
|
asyncness: sig.header.asyncness,
|
||||||
constness: sig.header.constness,
|
constness: sig.header.constness,
|
||||||
param_names: self.encode_fn_param_names_for_body(body),
|
param_names: self.encode_fn_param_names_for_body(body),
|
||||||
sig: self.lazy(&tcx.fn_sig(def_id)),
|
sig: self.lazy(&tcx.fn_sig(def_id)),
|
||||||
|
@ -1128,6 +1130,7 @@ impl EncodeContext<'tcx> {
|
||||||
}
|
}
|
||||||
hir::ItemKind::Fn(_, header, .., body) => {
|
hir::ItemKind::Fn(_, header, .., body) => {
|
||||||
let data = FnData {
|
let data = FnData {
|
||||||
|
asyncness: header.asyncness,
|
||||||
constness: header.constness,
|
constness: header.constness,
|
||||||
param_names: self.encode_fn_param_names_for_body(body),
|
param_names: self.encode_fn_param_names_for_body(body),
|
||||||
sig: self.lazy(tcx.fn_sig(def_id)),
|
sig: self.lazy(tcx.fn_sig(def_id)),
|
||||||
|
@ -1675,6 +1678,7 @@ impl EncodeContext<'tcx> {
|
||||||
let kind = match nitem.node {
|
let kind = match nitem.node {
|
||||||
hir::ForeignItemKind::Fn(_, ref names, _) => {
|
hir::ForeignItemKind::Fn(_, ref names, _) => {
|
||||||
let data = FnData {
|
let data = FnData {
|
||||||
|
asyncness: hir::IsAsync::NotAsync,
|
||||||
constness: hir::Constness::NotConst,
|
constness: hir::Constness::NotConst,
|
||||||
param_names: self.encode_fn_param_names(names),
|
param_names: self.encode_fn_param_names(names),
|
||||||
sig: self.lazy(tcx.fn_sig(def_id)),
|
sig: self.lazy(tcx.fn_sig(def_id)),
|
||||||
|
|
|
@ -295,6 +295,7 @@ pub struct MacroDef {
|
||||||
|
|
||||||
#[derive(RustcEncodable, RustcDecodable)]
|
#[derive(RustcEncodable, RustcDecodable)]
|
||||||
pub struct FnData<'tcx> {
|
pub struct FnData<'tcx> {
|
||||||
|
pub asyncness: hir::IsAsync,
|
||||||
pub constness: hir::Constness,
|
pub constness: hir::Constness,
|
||||||
pub param_names: Lazy<[ast::Name]>,
|
pub param_names: Lazy<[ast::Name]>,
|
||||||
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
|
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue