Skip to content

Commit 9ffb1ce

Browse files
committed
append asyncness info to functions
1 parent 2fd4c27 commit 9ffb1ce

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ 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 {
247+
query is_async_fn(key: DefId) -> bool {
248248
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
249249
}
250250

src/librustc/ty/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3349,13 +3349,28 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
33493349
}
33503350
}
33513351

3352+
fn is_async_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
3353+
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
3354+
let node = tcx.hir().get(hir_id);
3355+
if let Some(fn_like) = hir::map::blocks::FnLikeNode::from_node(node) {
3356+
fn_like.asyncness() == hir::IsAsync::Async
3357+
} else {
3358+
false
3359+
}
3360+
} else {
3361+
false
3362+
}
3363+
}
3364+
3365+
33523366
pub fn provide(providers: &mut ty::query::Providers<'_>) {
33533367
context::provide(providers);
33543368
erase_regions::provide(providers);
33553369
layout::provide(providers);
33563370
util::provide(providers);
33573371
constness::provide(providers);
33583372
*providers = ty::query::Providers {
3373+
is_async_fn,
33593374
associated_item,
33603375
associated_item_def_ids,
33613376
adt_sized_constraint,

src/librustc_metadata/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +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) }
136+
is_async_fn => { cdata.is_async_fn(def_id.index) }
137137
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
138138
static_mutability => { cdata.static_mutability(def_id.index) }
139139
def_kind => { cdata.def_kind(def_id.index) }

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl EncodeContext<'tcx> {
875875
EntryKind::AssocConst(container, const_qualif, rendered_const)
876876
}
877877
ty::AssocKind::Method => {
878-
let fn_data = if let hir::TraitItemKind::Method(_, ref m) = ast_item.node {
878+
let fn_data = if let hir::TraitItemKind::Method(method_sig, m) = &ast_item.node {
879879
let param_names = match *m {
880880
hir::TraitMethod::Required(ref names) => {
881881
self.encode_fn_param_names(names)
@@ -885,7 +885,7 @@ impl EncodeContext<'tcx> {
885885
}
886886
};
887887
FnData {
888-
asyncness: hir::IsAsync::NotAsync,
888+
asyncness: method_sig.header.asyncness,
889889
constness: hir::Constness::NotConst,
890890
param_names,
891891
sig: self.lazy(&tcx.fn_sig(def_id)),

src/librustdoc/clean/inline.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
217217
} else {
218218
hir::Constness::NotConst
219219
};
220-
220+
let asyncness = if cx.tcx.is_async_fn(did) {
221+
hir::IsAsync::Async
222+
} else {
223+
hir::IsAsync::NotAsync
224+
};
221225
let predicates = cx.tcx.predicates_of(did);
222226
let (generics, decl) = clean::enter_impl_trait(cx, || {
223227
((cx.tcx.generics_of(did), &predicates).clean(cx), (did, sig).clean(cx))
@@ -230,7 +234,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
230234
unsafety: sig.unsafety(),
231235
abi: sig.abi(),
232236
constness,
233-
asyncness: hir::IsAsync::NotAsync,
237+
asyncness,
234238
},
235239
all_types,
236240
ret_types,

src/librustdoc/clean/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,11 @@ impl Clean<Item> for ty::AssocItem {
24032403
} else {
24042404
hir::Constness::NotConst
24052405
};
2406+
let asyncness = if cx.tcx.is_async_fn(self.def_id) {
2407+
hir::IsAsync::Async
2408+
} else {
2409+
hir::IsAsync::NotAsync
2410+
};
24062411
let defaultness = match self.container {
24072412
ty::ImplContainer(_) => Some(self.defaultness),
24082413
ty::TraitContainer(_) => None,
@@ -2414,7 +2419,7 @@ impl Clean<Item> for ty::AssocItem {
24142419
unsafety: sig.unsafety(),
24152420
abi: sig.abi(),
24162421
constness,
2417-
asyncness: hir::IsAsync::NotAsync,
2422+
asyncness,
24182423
},
24192424
defaultness,
24202425
all_types,

0 commit comments

Comments
 (0)