Skip to content

Commit 589446e

Browse files
Without Boatscramertj
authored andcommitted
Display async fn in rustdoc.
1 parent 18ff7d0 commit 589446e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/librustdoc/html/format.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub struct UnsafetySpace(pub hir::Unsafety);
3939
/// with a space after it.
4040
#[derive(Copy, Clone)]
4141
pub struct ConstnessSpace(pub hir::Constness);
42+
/// Similarly to VisSpace, this structure is used to render a function asyncness
43+
/// with a space after it.
44+
#[derive(Copy, Clone)]
45+
pub struct AsyncSpace(pub hir::IsAsync);
4246
/// Similar to VisSpace, but used for mutability
4347
#[derive(Copy, Clone)]
4448
pub struct MutableSpace(pub clean::Mutability);
@@ -962,6 +966,15 @@ impl fmt::Display for ConstnessSpace {
962966
}
963967
}
964968

969+
impl fmt::Display for AsyncSpace {
970+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
971+
match self.0 {
972+
hir::IsAsync::Async => write!(f, "async "),
973+
hir::IsAsync::NotAsync => Ok(()),
974+
}
975+
}
976+
}
977+
965978
impl fmt::Display for clean::Import {
966979
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
967980
match *self {

src/librustdoc/html/render.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use clean::{self, AttributesExt, GetDefId, SelfTy, Mutability};
6767
use doctree;
6868
use fold::DocFolder;
6969
use html::escape::Escape;
70-
use html::format::{ConstnessSpace};
70+
use html::format::{AsyncSpace, ConstnessSpace};
7171
use html::format::{GenericBounds, WhereClause, href, AbiSpace};
7272
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
7373
use html::format::fmt_impl_for_trait_page;
@@ -2574,19 +2574,21 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
25742574

25752575
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
25762576
f: &clean::Function) -> fmt::Result {
2577-
let name_len = format!("{}{}{}{:#}fn {}{:#}",
2577+
let name_len = format!("{}{}{}{}{:#}fn {}{:#}",
25782578
VisSpace(&it.visibility),
25792579
ConstnessSpace(f.header.constness),
2580+
AsyncSpace(f.header.asyncness),
25802581
UnsafetySpace(f.header.unsafety),
25812582
AbiSpace(f.header.abi),
25822583
it.name.as_ref().unwrap(),
25832584
f.generics).len();
25842585
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)?)?;
25852586
render_attributes(w, it)?;
25862587
write!(w,
2587-
"{vis}{constness}{unsafety}{abi}fn {name}{generics}{decl}{where_clause}</pre>",
2588+
"{vis}{constness}{asyncness}{unsafety}{abi}fn {name}{generics}{decl}{where_clause}</pre>",
25882589
vis = VisSpace(&it.visibility),
25892590
constness = ConstnessSpace(f.header.constness),
2591+
asyncness = AsyncSpace(f.header.asyncness),
25902592
unsafety = UnsafetySpace(f.header.unsafety),
25912593
abi = AbiSpace(f.header.abi),
25922594
name = it.name.as_ref().unwrap(),

0 commit comments

Comments
 (0)