Skip to content

Commit

Permalink
append asyncness info to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Sep 19, 2019
1 parent 2fd4c27 commit 9ffb1ce
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ rustc_queries! {
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
}

query is_async_fn(key: DefId) -> hir::IsAsync {
query is_async_fn(key: DefId) -> bool {
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
}

Expand Down
15 changes: 15 additions & 0 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3349,13 +3349,28 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
}
}

fn is_async_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let node = tcx.hir().get(hir_id);
if let Some(fn_like) = hir::map::blocks::FnLikeNode::from_node(node) {
fn_like.asyncness() == hir::IsAsync::Async
} else {
false
}
} else {
false
}
}


pub fn provide(providers: &mut ty::query::Providers<'_>) {
context::provide(providers);
erase_regions::provide(providers);
layout::provide(providers);
util::provide(providers);
constness::provide(providers);
*providers = ty::query::Providers {
is_async_fn,
associated_item,
associated_item_def_ids,
adt_sized_constraint,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +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_async_fn => { cdata.is_async_fn(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) }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ impl EncodeContext<'tcx> {
EntryKind::AssocConst(container, const_qualif, rendered_const)
}
ty::AssocKind::Method => {
let fn_data = if let hir::TraitItemKind::Method(_, ref m) = ast_item.node {
let fn_data = if let hir::TraitItemKind::Method(method_sig, m) = &ast_item.node {
let param_names = match *m {
hir::TraitMethod::Required(ref names) => {
self.encode_fn_param_names(names)
Expand All @@ -885,7 +885,7 @@ impl EncodeContext<'tcx> {
}
};
FnData {
asyncness: hir::IsAsync::NotAsync,
asyncness: method_sig.header.asyncness,
constness: hir::Constness::NotConst,
param_names,
sig: self.lazy(&tcx.fn_sig(def_id)),
Expand Down
8 changes: 6 additions & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
} else {
hir::Constness::NotConst
};

let asyncness = if cx.tcx.is_async_fn(did) {
hir::IsAsync::Async
} else {
hir::IsAsync::NotAsync
};
let predicates = cx.tcx.predicates_of(did);
let (generics, decl) = clean::enter_impl_trait(cx, || {
((cx.tcx.generics_of(did), &predicates).clean(cx), (did, sig).clean(cx))
Expand All @@ -230,7 +234,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
unsafety: sig.unsafety(),
abi: sig.abi(),
constness,
asyncness: hir::IsAsync::NotAsync,
asyncness,
},
all_types,
ret_types,
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,11 @@ impl Clean<Item> for ty::AssocItem {
} else {
hir::Constness::NotConst
};
let asyncness = if cx.tcx.is_async_fn(self.def_id) {
hir::IsAsync::Async
} else {
hir::IsAsync::NotAsync
};
let defaultness = match self.container {
ty::ImplContainer(_) => Some(self.defaultness),
ty::TraitContainer(_) => None,
Expand All @@ -2414,7 +2419,7 @@ impl Clean<Item> for ty::AssocItem {
unsafety: sig.unsafety(),
abi: sig.abi(),
constness,
asyncness: hir::IsAsync::NotAsync,
asyncness,
},
defaultness,
all_types,
Expand Down

0 comments on commit 9ffb1ce

Please sign in to comment.