Skip to content

Commit 8319f3d

Browse files
author
Without Boats
committed
Display async fn in rustdoc.
1 parent 6c73b95 commit 8319f3d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/librustdoc/html/format.rs

+13
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

+5-3
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::{TyParamBounds, WhereClause, href, AbiSpace};
7272
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
7373
use html::format::fmt_impl_for_trait_page;
@@ -2592,19 +2592,21 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
25922592

25932593
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
25942594
f: &clean::Function) -> fmt::Result {
2595-
let name_len = format!("{}{}{}{:#}fn {}{:#}",
2595+
let name_len = format!("{}{}{}{}{:#}fn {}{:#}",
25962596
VisSpace(&it.visibility),
25972597
ConstnessSpace(f.header.constness),
2598+
AsyncSpace(f.header.asyncness),
25982599
UnsafetySpace(f.header.unsafety),
25992600
AbiSpace(f.header.abi),
26002601
it.name.as_ref().unwrap(),
26012602
f.generics).len();
26022603
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)?)?;
26032604
render_attributes(w, it)?;
26042605
write!(w,
2605-
"{vis}{constness}{unsafety}{abi}fn {name}{generics}{decl}{where_clause}</pre>",
2606+
"{vis}{constness}{asyncness}{unsafety}{abi}fn {name}{generics}{decl}{where_clause}</pre>",
26062607
vis = VisSpace(&it.visibility),
26072608
constness = ConstnessSpace(f.header.constness),
2609+
asyncness = AsyncSpace(f.header.asyncness),
26082610
unsafety = UnsafetySpace(f.header.unsafety),
26092611
abi = AbiSpace(f.header.abi),
26102612
name = it.name.as_ref().unwrap(),

0 commit comments

Comments
 (0)