Skip to content

Commit 6c9d795

Browse files
committed
rustdoc: correctly render ret ty of cross-crate async fns
1 parent e4a361a commit 6c9d795

File tree

6 files changed

+44
-15
lines changed

6 files changed

+44
-15
lines changed

src/librustdoc/clean/inline.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> Box<c
253253
let mut generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
254254
// FIXME: This does not place parameters in source order (late-bound ones come last)
255255
generics.params.extend(late_bound_regions);
256-
let decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig);
256+
let mut decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig);
257+
if cx.tcx.asyncness(did).is_async() {
258+
decl.output = decl.sugared_async_return_type();
259+
}
257260
(generics, decl)
258261
});
259262
Box::new(clean::Function { decl, generics })

src/librustdoc/clean/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,9 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13701370
generics.params.extend(late_bound_regions);
13711371

13721372
let mut decl = clean_fn_decl_from_did_and_sig(cx, Some(assoc_item.def_id), sig);
1373+
if tcx.asyncness(assoc_item.def_id).is_async() {
1374+
decl.output = decl.sugared_async_return_type();
1375+
}
13731376

13741377
if assoc_item.fn_has_self_parameter {
13751378
let self_ty = match assoc_item.container {
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for issue #115760.
2+
// Check that we render the correct return type of free and
3+
// associated async functions reexported from external crates.
4+
5+
// aux-crate:async_fn=async-fn.rs
6+
// edition: 2021
7+
#![crate_name = "user"]
8+
9+
// @has user/fn.load.html
10+
// @has - '//pre[@class="rust item-decl"]' "pub async fn load() -> i32"
11+
pub use async_fn::load;
12+
13+
// @has user/trait.Load.html
14+
// @has - '//*[@id="tymethod.run"]' 'async fn run(&self) -> i32'
15+
pub use async_fn::Load;
16+
17+
// @has user/struct.Loader.html
18+
// @has - '//*[@id="method.run"]' 'async fn run(&self) -> i32'
19+
pub use async_fn::Loader;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(async_fn_in_trait)]
2+
// edition: 2021
3+
4+
pub async fn load() -> i32 {
5+
0
6+
}
7+
8+
pub trait Load {
9+
async fn run(&self) -> i32;
10+
}
11+
12+
pub struct Loader;
13+
14+
impl Load for Loader {
15+
async fn run(&self) -> i32 {
16+
1
17+
}
18+
}

tests/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs

-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,3 @@ pub struct Foo;
3333
impl Foo {
3434
pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a) {}
3535
}
36-
37-
pub struct Bar;
38-
39-
impl Bar {
40-
pub async fn async_foo(&self) {}
41-
}

tests/rustdoc/inline_cross/impl_trait.rs

-8
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,7 @@ pub use impl_trait_aux::func4;
3333
// @!has - '//pre[@class="rust item-decl"]' 'where'
3434
pub use impl_trait_aux::func5;
3535

36-
// @has impl_trait/fn.async_fn.html
37-
// @has - '//pre[@class="rust item-decl"]' "pub async fn async_fn()"
38-
pub use impl_trait_aux::async_fn;
39-
4036
// @has impl_trait/struct.Foo.html
4137
// @has - '//*[@id="method.method"]//h4[@class="code-header"]' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8, Global>> + 'a)"
4238
// @!has - '//*[@id="method.method"]//h4[@class="code-header"]' 'where'
4339
pub use impl_trait_aux::Foo;
44-
45-
// @has impl_trait/struct.Bar.html
46-
// @has - '//*[@id="method.async_foo"]' "pub async fn async_foo("
47-
pub use impl_trait_aux::Bar;

0 commit comments

Comments
 (0)