Rollup merge of #64599 - csmoe:doc_async_reexport, r=nikomatsakis

Rustdoc render async function re-export

Closes #63710
r? @nikomatsakis
This commit is contained in:
Mazdak Farrokhzad 2019-09-25 03:48:27 +02:00 committed by GitHub
commit 34067ee961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 60 additions and 5 deletions

View File

@ -244,6 +244,10 @@ rustc_queries! {
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
}
query asyncness(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

@ -3353,6 +3353,22 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
}
}
/// Check if a function is async.
fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap_or_else(|| {
bug!("asyncness: expected local `DefId`, got `{:?}`", def_id)
});
let node = tcx.hir().get(hir_id);
let fn_like = hir::map::blocks::FnLikeNode::from_node(node).unwrap_or_else(|| {
bug!("asyncness: expected fn-like node but got `{:?}`", def_id);
});
fn_like.asyncness()
}
pub fn provide(providers: &mut ty::query::Providers<'_>) {
context::provide(providers);
erase_regions::provide(providers);
@ -3360,6 +3376,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
util::provide(providers);
constness::provide(providers);
*providers = ty::query::Providers {
asyncness,
associated_item,
associated_item_def_ids,
adt_sized_constraint,

View File

@ -134,6 +134,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) }
asyncness => { cdata.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

@ -1212,6 +1212,15 @@ impl<'a, 'tcx> CrateMetadata {
constness == hir::Constness::Const
}
pub fn asyncness(&self, id: DefIndex) -> hir::IsAsync {
match self.entry(id).kind {
EntryKind::Fn(data) => data.decode(self).asyncness,
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
_ => bug!("asyncness: expect functions entry."),
}
}
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
match self.entry(id).kind {
EntryKind::ForeignImmStatic |

View File

@ -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,6 +885,7 @@ impl EncodeContext<'tcx> {
}
};
FnData {
asyncness: method_sig.header.asyncness,
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)),
@ -1677,6 +1680,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>>,

View File

@ -217,7 +217,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
} else {
hir::Constness::NotConst
};
let asyncness = cx.tcx.asyncness(did);
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 +230,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,

View File

@ -2403,6 +2403,7 @@ impl Clean<Item> for ty::AssocItem {
} else {
hir::Constness::NotConst
};
let asyncness = cx.tcx.asyncness(self.def_id);
let defaultness = match self.container {
ty::ImplContainer(_) => Some(self.defaultness),
ty::TraitContainer(_) => None,
@ -2414,7 +2415,7 @@ impl Clean<Item> for ty::AssocItem {
unsafety: sig.unsafety(),
abi: sig.abi(),
constness,
asyncness: hir::IsAsync::NotAsync,
asyncness,
},
defaultness,
all_types,

View File

@ -1,3 +1,5 @@
// edition:2018
use std::ops::Deref;
pub fn func<'a>(_x: impl Clone + Into<Vec<u8>> + 'a) {}
@ -11,8 +13,16 @@ pub fn func3(_x: impl Iterator<Item = impl Iterator<Item = u8>> + Clone) {}
pub fn func4<T: Iterator<Item = impl Clone>>(_x: T) {}
pub async fn async_fn() {}
pub struct Foo;
impl Foo {
pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a) {}
}
pub struct Bar;
impl Bar {
pub async fn async_foo(&self) {}
}

View File

@ -1,4 +1,5 @@
// aux-build:impl_trait_aux.rs
// edition:2018
extern crate impl_trait_aux;
@ -20,13 +21,20 @@ pub use impl_trait_aux::func2;
// @!has - '//pre[@class="rust fn"]' 'where'
pub use impl_trait_aux::func3;
// @has impl_trait/fn.func4.html
// @has - '//pre[@class="rust fn"]' "func4<T>("
// @has - '//pre[@class="rust fn"]' "T: Iterator<Item = impl Clone>,"
pub use impl_trait_aux::func4;
// @has impl_trait/fn.async_fn.html
// @has - '//pre[@class="rust fn"]' "pub async fn async_fn()"
pub use impl_trait_aux::async_fn;
// @has impl_trait/struct.Foo.html
// @has - '//code[@id="method.v"]' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a)"
// @!has - '//code[@id="method.v"]' 'where'
pub use impl_trait_aux::Foo;
// @has impl_trait/struct.Bar.html
// @has - '//*[@id="method.async_foo"]' "pub async fn async_foo("
pub use impl_trait_aux::Bar;