Skip to content

Commit 2fd4c27

Browse files
committed
add is_async_fn query
1 parent 5283791 commit 2fd4c27

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

src/librustc/query/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ rustc_queries! {
244244
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
245245
}
246246

247+
query is_async_fn(key: DefId) -> hir::IsAsync {
248+
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
249+
}
250+
247251
/// Returns `true` if calls to the function may be promoted.
248252
///
249253
/// This is either because the function is e.g., a tuple-struct or tuple-variant

src/librustc_metadata/cstore_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
133133
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
134134
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
135135
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
136+
is_async_fn { cdata.fn_asyncness(def_id.index) }
136137
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
137138
static_mutability => { cdata.static_mutability(def_id.index) }
138139
def_kind => { cdata.def_kind(def_id.index) }

src/librustc_metadata/decoder.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,15 @@ impl<'a, 'tcx> CrateMetadata {
12081208
constness == hir::Constness::Const
12091209
}
12101210

1211+
pub fn is_async_fn(&self, id: DefIndex) -> bool {
1212+
let asyncness = match self.entry(id).kind {
1213+
EntryKind::Fn(data) => data.decode(self).asyncness,
1214+
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
1215+
_ => hir::IsAsync::NotAsync,
1216+
};
1217+
asyncness == hir::IsAsync::Async
1218+
}
1219+
12111220
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
12121221
match self.entry(id).kind {
12131222
EntryKind::ForeignImmStatic |

src/librustc_metadata/encoder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ impl EncodeContext<'tcx> {
885885
}
886886
};
887887
FnData {
888+
asyncness: hir::IsAsync::NotAsync,
888889
constness: hir::Constness::NotConst,
889890
param_names,
890891
sig: self.lazy(&tcx.fn_sig(def_id)),
@@ -982,6 +983,7 @@ impl EncodeContext<'tcx> {
982983
ty::AssocKind::Method => {
983984
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
984985
FnData {
986+
asyncness: sig.header.asyncness,
985987
constness: sig.header.constness,
986988
param_names: self.encode_fn_param_names_for_body(body),
987989
sig: self.lazy(&tcx.fn_sig(def_id)),
@@ -1128,6 +1130,7 @@ impl EncodeContext<'tcx> {
11281130
}
11291131
hir::ItemKind::Fn(_, header, .., body) => {
11301132
let data = FnData {
1133+
asyncness: header.asyncness,
11311134
constness: header.constness,
11321135
param_names: self.encode_fn_param_names_for_body(body),
11331136
sig: self.lazy(tcx.fn_sig(def_id)),
@@ -1675,6 +1678,7 @@ impl EncodeContext<'tcx> {
16751678
let kind = match nitem.node {
16761679
hir::ForeignItemKind::Fn(_, ref names, _) => {
16771680
let data = FnData {
1681+
asyncness: hir::IsAsync::NotAsync,
16781682
constness: hir::Constness::NotConst,
16791683
param_names: self.encode_fn_param_names(names),
16801684
sig: self.lazy(tcx.fn_sig(def_id)),

src/librustc_metadata/schema.rs

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ pub struct MacroDef {
295295

296296
#[derive(RustcEncodable, RustcDecodable)]
297297
pub struct FnData<'tcx> {
298+
pub asyncness: hir::IsAsync,
298299
pub constness: hir::Constness,
299300
pub param_names: Lazy<[ast::Name]>,
300301
pub sig: Lazy<ty::PolyFnSig<'tcx>>,

0 commit comments

Comments
 (0)