rustdoc: Resugar async fn return type in clean
, not html
This way it also happens for json output. Fixes #101199
This commit is contained in:
parent
0631ea5d73
commit
6099d17afe
@ -886,7 +886,10 @@ fn clean_function<'tcx>(
|
||||
// NOTE: generics must be cleaned before args
|
||||
let generics = clean_generics(generics, cx);
|
||||
let args = clean_args_from_types_and_body_id(cx, sig.decl.inputs, body_id);
|
||||
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
|
||||
let mut decl = clean_fn_decl_with_args(cx, sig.decl, args);
|
||||
if sig.header.is_async() {
|
||||
decl.output = decl.sugared_async_return_type();
|
||||
}
|
||||
(generics, decl)
|
||||
});
|
||||
Box::new(Function { decl, generics })
|
||||
|
@ -1310,22 +1310,19 @@ impl clean::FnDecl {
|
||||
/// <br>Used to determine line-wrapping.
|
||||
/// * `indent`: The number of spaces to indent each successive line with, if line-wrapping is
|
||||
/// necessary.
|
||||
/// * `asyncness`: Whether the function is async or not.
|
||||
pub(crate) fn full_print<'a, 'tcx: 'a>(
|
||||
&'a self,
|
||||
header_len: usize,
|
||||
indent: usize,
|
||||
asyncness: hir::IsAsync,
|
||||
cx: &'a Context<'tcx>,
|
||||
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
||||
display_fn(move |f| self.inner_full_print(header_len, indent, asyncness, f, cx))
|
||||
display_fn(move |f| self.inner_full_print(header_len, indent, f, cx))
|
||||
}
|
||||
|
||||
fn inner_full_print(
|
||||
&self,
|
||||
header_len: usize,
|
||||
indent: usize,
|
||||
asyncness: hir::IsAsync,
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
cx: &Context<'_>,
|
||||
) -> fmt::Result {
|
||||
@ -1390,15 +1387,9 @@ impl clean::FnDecl {
|
||||
args_plain.push_str(", ...");
|
||||
}
|
||||
|
||||
let arrow_plain;
|
||||
let arrow = if let hir::IsAsync::Async = asyncness {
|
||||
let output = self.sugared_async_return_type();
|
||||
arrow_plain = format!("{:#}", output.print(cx));
|
||||
if f.alternate() { arrow_plain.clone() } else { format!("{}", output.print(cx)) }
|
||||
} else {
|
||||
arrow_plain = format!("{:#}", self.output.print(cx));
|
||||
if f.alternate() { arrow_plain.clone() } else { format!("{}", self.output.print(cx)) }
|
||||
};
|
||||
let arrow_plain = format!("{:#}", self.output.print(cx));
|
||||
let arrow =
|
||||
if f.alternate() { arrow_plain.clone() } else { format!("{}", self.output.print(cx)) };
|
||||
|
||||
let declaration_len = header_len + args_plain.len() + arrow_plain.len();
|
||||
let output = if declaration_len > 80 {
|
||||
|
@ -821,7 +821,7 @@ fn assoc_method(
|
||||
href = href,
|
||||
name = name,
|
||||
generics = g.print(cx),
|
||||
decl = d.full_print(header_len, indent, header.asyncness, cx),
|
||||
decl = d.full_print(header_len, indent, cx),
|
||||
notable_traits = notable_traits_decl(d, cx),
|
||||
where_clause = print_where_clause(g, cx, indent, end_newline),
|
||||
)
|
||||
|
@ -530,7 +530,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
|
||||
name = name,
|
||||
generics = f.generics.print(cx),
|
||||
where_clause = print_where_clause(&f.generics, cx, 0, Ending::Newline),
|
||||
decl = f.decl.full_print(header_len, 0, header.asyncness, cx),
|
||||
decl = f.decl.full_print(header_len, 0, cx),
|
||||
notable_traits = notable_traits_decl(&f.decl, cx),
|
||||
);
|
||||
});
|
||||
|
36
src/test/rustdoc-json/fns/async_return.rs
Normal file
36
src/test/rustdoc-json/fns/async_return.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// edition:2021
|
||||
// ignore-tidy-linelength
|
||||
|
||||
// Regression test for <https://github.com/rust-lang/rust/issues/101199>
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
// @is "$.index[*][?(@.name=='get_int')].inner.decl.output" '{"inner": "i32", "kind": "primitive"}'
|
||||
// @is "$.index[*][?(@.name=='get_int')].inner.header.async" false
|
||||
pub fn get_int() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
// @is "$.index[*][?(@.name=='get_int_async')].inner.decl.output" '{"inner": "i32", "kind": "primitive"}'
|
||||
// @is "$.index[*][?(@.name=='get_int_async')].inner.header.async" true
|
||||
pub async fn get_int_async() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
// @is "$.index[*][?(@.name=='get_int_future')].inner.decl.output.kind" '"impl_trait"'
|
||||
// @is "$.index[*][?(@.name=='get_int_future')].inner.decl.output.inner[0].trait_bound.trait.name" '"Future"'
|
||||
// @is "$.index[*][?(@.name=='get_int_future')].inner.decl.output.inner[0].trait_bound.trait.args.angle_bracketed.bindings[0].name" '"Output"'
|
||||
// @is "$.index[*][?(@.name=='get_int_future')].inner.decl.output.inner[0].trait_bound.trait.args.angle_bracketed.bindings[0].binding.equality.type" '{"inner": "i32", "kind": "primitive"}'
|
||||
// @is "$.index[*][?(@.name=='get_int_future')].inner.header.async" false
|
||||
pub fn get_int_future() -> impl Future<Output = i32> {
|
||||
async { 42 }
|
||||
}
|
||||
|
||||
// @is "$.index[*][?(@.name=='get_int_future_async')].inner.decl.output.kind" '"impl_trait"'
|
||||
// @is "$.index[*][?(@.name=='get_int_future_async')].inner.decl.output.inner[0].trait_bound.trait.name" '"Future"'
|
||||
// @is "$.index[*][?(@.name=='get_int_future_async')].inner.decl.output.inner[0].trait_bound.trait.args.angle_bracketed.bindings[0].name" '"Output"'
|
||||
// @is "$.index[*][?(@.name=='get_int_future_async')].inner.decl.output.inner[0].trait_bound.trait.args.angle_bracketed.bindings[0].binding.equality.type" '{"inner": "i32", "kind": "primitive"}'
|
||||
// @is "$.index[*][?(@.name=='get_int_future_async')].inner.header.async" true
|
||||
pub async fn get_int_future_async() -> impl Future<Output = i32> {
|
||||
async { 42 }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user