Skip to content

Commit 2ff6c65

Browse files
csmoeMark-Simulacrum
authored andcommitted
Backport rust-lang#64599 to beta: rustdoc render async function re-export
1 parent 1a5c963 commit 2ff6c65

File tree

10 files changed

+60
-5
lines changed

10 files changed

+60
-5
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 asyncness(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/ty/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -3353,13 +3353,30 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
33533353
}
33543354
}
33553355

3356+
/// Check if a function is async.
3357+
fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
3358+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap_or_else(|| {
3359+
bug!("asyncness: expected local `DefId`, got `{:?}`", def_id)
3360+
});
3361+
3362+
let node = tcx.hir().get(hir_id);
3363+
3364+
let fn_like = hir::map::blocks::FnLikeNode::from_node(node).unwrap_or_else(|| {
3365+
bug!("asyncness: expected fn-like node but got `{:?}`", def_id);
3366+
});
3367+
3368+
fn_like.asyncness()
3369+
}
3370+
3371+
33563372
pub fn provide(providers: &mut ty::query::Providers<'_>) {
33573373
context::provide(providers);
33583374
erase_regions::provide(providers);
33593375
layout::provide(providers);
33603376
util::provide(providers);
33613377
constness::provide(providers);
33623378
*providers = ty::query::Providers {
3379+
asyncness,
33633380
associated_item,
33643381
associated_item_def_ids,
33653382
adt_sized_constraint,

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+
asyncness => { cdata.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
@@ -1212,6 +1212,15 @@ impl<'a, 'tcx> CrateMetadata {
12121212
constness == hir::Constness::Const
12131213
}
12141214

1215+
pub fn asyncness(&self, id: DefIndex) -> hir::IsAsync {
1216+
match self.entry(id).kind {
1217+
EntryKind::Fn(data) => data.decode(self).asyncness,
1218+
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
1219+
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
1220+
_ => bug!("asyncness: expect functions entry."),
1221+
}
1222+
}
1223+
12151224
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
12161225
match self.entry(id).kind {
12171226
EntryKind::ForeignImmStatic |

src/librustc_metadata/encoder.rs

+5-1
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,6 +885,7 @@ impl EncodeContext<'tcx> {
885885
}
886886
};
887887
FnData {
888+
asyncness: method_sig.header.asyncness,
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>>,

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
217217
} else {
218218
hir::Constness::NotConst
219219
};
220-
220+
let asyncness = cx.tcx.asyncness(did);
221221
let predicates = cx.tcx.predicates_of(did);
222222
let (generics, decl) = clean::enter_impl_trait(cx, || {
223223
((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 {
230230
unsafety: sig.unsafety(),
231231
abi: sig.abi(),
232232
constness,
233-
asyncness: hir::IsAsync::NotAsync,
233+
asyncness,
234234
},
235235
all_types,
236236
ret_types,

src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,7 @@ impl Clean<Item> for ty::AssocItem {
24032403
} else {
24042404
hir::Constness::NotConst
24052405
};
2406+
let asyncness = cx.tcx.asyncness(self.def_id);
24062407
let defaultness = match self.container {
24072408
ty::ImplContainer(_) => Some(self.defaultness),
24082409
ty::TraitContainer(_) => None,
@@ -2414,7 +2415,7 @@ impl Clean<Item> for ty::AssocItem {
24142415
unsafety: sig.unsafety(),
24152416
abi: sig.abi(),
24162417
constness,
2417-
asyncness: hir::IsAsync::NotAsync,
2418+
asyncness,
24182419
},
24192420
defaultness,
24202421
all_types,

src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// edition:2018
2+
13
use std::ops::Deref;
24

35
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) {}
1113

1214
pub fn func4<T: Iterator<Item = impl Clone>>(_x: T) {}
1315

16+
pub async fn async_fn() {}
17+
1418
pub struct Foo;
1519

1620
impl Foo {
1721
pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a) {}
1822
}
23+
24+
pub struct Bar;
25+
26+
impl Bar {
27+
pub async fn async_foo(&self) {}
28+
}

src/test/rustdoc/inline_cross/impl_trait.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// aux-build:impl_trait_aux.rs
2+
// edition:2018
23

34
extern crate impl_trait_aux;
45

@@ -20,13 +21,20 @@ pub use impl_trait_aux::func2;
2021
// @!has - '//pre[@class="rust fn"]' 'where'
2122
pub use impl_trait_aux::func3;
2223

23-
2424
// @has impl_trait/fn.func4.html
2525
// @has - '//pre[@class="rust fn"]' "func4<T>("
2626
// @has - '//pre[@class="rust fn"]' "T: Iterator<Item = impl Clone>,"
2727
pub use impl_trait_aux::func4;
2828

29+
// @has impl_trait/fn.async_fn.html
30+
// @has - '//pre[@class="rust fn"]' "pub async fn async_fn()"
31+
pub use impl_trait_aux::async_fn;
32+
2933
// @has impl_trait/struct.Foo.html
3034
// @has - '//code[@id="method.v"]' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a)"
3135
// @!has - '//code[@id="method.v"]' 'where'
3236
pub use impl_trait_aux::Foo;
37+
38+
// @has impl_trait/struct.Bar.html
39+
// @has - '//*[@id="method.async_foo"]' "pub async fn async_foo("
40+
pub use impl_trait_aux::Bar;

0 commit comments

Comments
 (0)