1
Fork 0

add is_async_fn query

This commit is contained in:
csmoe 2019-09-19 03:02:08 +00:00
parent 528379121c
commit 2fd4c27c32
5 changed files with 19 additions and 0 deletions

View file

@ -244,6 +244,10 @@ rustc_queries! {
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.
///
/// This is either because the function is e.g., a tuple-struct or tuple-variant

View file

@ -133,6 +133,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
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_async_fn { cdata.fn_asyncness(def_id.index) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
static_mutability => { cdata.static_mutability(def_id.index) }
def_kind => { cdata.def_kind(def_id.index) }

View file

@ -1208,6 +1208,15 @@ impl<'a, 'tcx> CrateMetadata {
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 {
match self.entry(id).kind {
EntryKind::ForeignImmStatic |

View file

@ -885,6 +885,7 @@ impl EncodeContext<'tcx> {
}
};
FnData {
asyncness: hir::IsAsync::NotAsync,
constness: hir::Constness::NotConst,
param_names,
sig: self.lazy(&tcx.fn_sig(def_id)),
@ -982,6 +983,7 @@ impl EncodeContext<'tcx> {
ty::AssocKind::Method => {
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
FnData {
asyncness: sig.header.asyncness,
constness: sig.header.constness,
param_names: self.encode_fn_param_names_for_body(body),
sig: self.lazy(&tcx.fn_sig(def_id)),
@ -1128,6 +1130,7 @@ impl EncodeContext<'tcx> {
}
hir::ItemKind::Fn(_, header, .., body) => {
let data = FnData {
asyncness: header.asyncness,
constness: header.constness,
param_names: self.encode_fn_param_names_for_body(body),
sig: self.lazy(tcx.fn_sig(def_id)),
@ -1675,6 +1678,7 @@ impl EncodeContext<'tcx> {
let kind = match nitem.node {
hir::ForeignItemKind::Fn(_, ref names, _) => {
let data = FnData {
asyncness: hir::IsAsync::NotAsync,
constness: hir::Constness::NotConst,
param_names: self.encode_fn_param_names(names),
sig: self.lazy(tcx.fn_sig(def_id)),

View file

@ -295,6 +295,7 @@ pub struct MacroDef {
#[derive(RustcEncodable, RustcDecodable)]
pub struct FnData<'tcx> {
pub asyncness: hir::IsAsync,
pub constness: hir::Constness,
pub param_names: Lazy<[ast::Name]>,
pub sig: Lazy<ty::PolyFnSig<'tcx>>,