diff options
| author | csmoe <csmoe@msn.com> | 2019-09-19 03:21:11 +0000 |
|---|---|---|
| committer | csmoe <csmoe@msn.com> | 2019-09-19 18:38:55 +0000 |
| commit | 9ffb1ce28cb1656d6142f1f9f6f882eb187fac25 (patch) | |
| tree | 97885edde0513823f34baa1c20f9555db31c0431 | |
| parent | 2fd4c27c329d85a69a6b585d217e48b4d500477e (diff) | |
append asyncness info to functions
| -rw-r--r-- | src/librustc/query/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 15 | ||||
| -rw-r--r-- | src/librustc_metadata/cstore_impl.rs | 2 | ||||
| -rw-r--r-- | src/librustc_metadata/encoder.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 7 |
6 files changed, 31 insertions, 7 deletions
diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index c4f62df12b7..5e1db92b555 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -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) } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 5ca819e12f2..97981f47820 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -3349,6 +3349,20 @@ 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); @@ -3356,6 +3370,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { util::provide(providers); constness::provide(providers); *providers = ty::query::Providers { + is_async_fn, associated_item, associated_item_def_ids, adt_sized_constraint, diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 6db3bfd8880..c46e2a901f8 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -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) } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 439763810ec..1e7c0829a26 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -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) @@ -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)), diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index cb42ff1c805..0752934c8c1 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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)) @@ -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, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ae70fdc530b..7bd54c64cf6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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, @@ -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, |
