Skip to content

Commit

Permalink
rustdoc: Fix rendering closures and trait bounds
Browse files Browse the repository at this point in the history
Closures did not have their bounds printed at all, nor their lifetimes. Trait
bounds were also printed in angle brackets rather than after a colon with a '+'
inbetween them.

Note that on the current task::spawn [1] documentation page, there is no mention
of a `Send` bound even though it is crucially important!

[1] - http://static.rust-lang.org/doc/master/std/task/fn.task.html
  • Loading branch information
alexcrichton committed Apr 13, 2014
1 parent 4c62ab1 commit 44e34c2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 23 deletions.
74 changes: 53 additions & 21 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,17 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
}

/// Helper to render type parameters
fn typarams(w: &mut io::Writer,
fn tybounds(w: &mut io::Writer,
typarams: &Option<Vec<clean::TyParamBound> >) -> fmt::Result {
match *typarams {
Some(ref params) => {
try!(write!(w, "&lt;"));
try!(write!(w, ":"));
for (i, param) in params.iter().enumerate() {
if i > 0 {
try!(write!(w, ", "));
try!(write!(w, " + "));
}
try!(write!(w, "{}", *param));
}
try!(write!(w, "&gt;"));
Ok(())
}
None => Ok(())
Expand All @@ -308,13 +307,13 @@ impl fmt::Show for clean::Type {
}
clean::ResolvedPath{id, typarams: ref tp, path: ref path} => {
try!(resolved_path(f.buf, id, path, false));
typarams(f.buf, tp)
tybounds(f.buf, tp)
}
clean::ExternalPath{path: ref path, typarams: ref tp,
fqn: ref fqn, kind, krate} => {
try!(external_path(f.buf, path, false, fqn.as_slice(), kind,
krate))
typarams(f.buf, tp)
tybounds(f.buf, tp)
}
clean::Self(..) => f.buf.write("Self".as_bytes()),
clean::Primitive(prim) => {
Expand All @@ -338,26 +337,59 @@ impl fmt::Show for clean::Type {
f.buf.write(s.as_bytes())
}
clean::Closure(ref decl, ref region) => {
let region = match *region {
Some(ref region) => format!("{} ", *region),
None => ~"",
};

write!(f.buf, "{}{}|{}|{arrow, select, yes{ -&gt; {ret}} other{}}",
FnStyleSpace(decl.fn_style),
region,
decl.decl.inputs,
write!(f.buf, "{style}{lifetimes}|{args}|{bounds}\
{arrow, select, yes{ -&gt; {ret}} other{}}",
style = FnStyleSpace(decl.fn_style),
lifetimes = if decl.lifetimes.len() == 0 {
~""
} else {
format!("&lt;{:#}&gt;", decl.lifetimes)
},
args = decl.decl.inputs,
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
ret = decl.decl.output)
// FIXME: where are bounds and lifetimes printed?!
ret = decl.decl.output,
bounds = {
let mut ret = StrBuf::new();
match *region {
Some(ref lt) => {
ret.push_str(format!(": {}", *lt));
}
None => {}
}
for bound in decl.bounds.iter() {
match *bound {
clean::RegionBound => {}
clean::TraitBound(ref t) => {
if ret.len() == 0 {
ret.push_str(": ");
} else {
ret.push_str(" + ");
}
ret.push_str(format!("{}", *t));
}
}
}
ret.into_owned()
})
}
clean::Proc(ref decl) => {
write!(f.buf, "{}proc({}){arrow, select, yes{ -&gt; {ret}} other{}}",
FnStyleSpace(decl.fn_style),
decl.decl.inputs,
write!(f.buf, "{style}{lifetimes}proc({args}){bounds}\
{arrow, select, yes{ -&gt; {ret}} other{}}",
style = FnStyleSpace(decl.fn_style),
lifetimes = if decl.lifetimes.len() == 0 {
~""
} else {
format!("&lt;{:#}&gt;", decl.lifetimes)
},
args = decl.decl.inputs,
bounds = if decl.bounds.len() == 0 {
~""
} else {
let mut m = decl.bounds.iter().map(|s| s.to_str());
": " + m.collect::<~[~str]>().connect(" + ")
},
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
ret = decl.decl.output)
// FIXME: where are bounds and lifetimes printed?!
}
clean::BareFunction(ref decl) => {
write!(f.buf, "{}{}fn{}{}",
Expand Down
9 changes: 7 additions & 2 deletions src/libstd/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,9 @@ impl<A: Clone> Clone for ~[A] {

impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f.buf, "["));
if f.flags & (1 << (fmt::parse::FlagAlternate as uint)) == 0 {
try!(write!(f.buf, "["));
}
let mut is_first = true;
for x in self.iter() {
if is_first {
Expand All @@ -2611,7 +2613,10 @@ impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
}
try!(write!(f.buf, "{}", *x))
}
write!(f.buf, "]")
if f.flags & (1 << (fmt::parse::FlagAlternate as uint)) == 0 {
try!(write!(f.buf, "]"));
}
Ok(())
}
}

Expand Down

13 comments on commit 44e34c2

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@44e34c2

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/fix-rustdoc-rendering = 44e34c2 into auto

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/fix-rustdoc-rendering = 44e34c2 merged ok, testing candidate = df331241

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@44e34c2

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/fix-rustdoc-rendering = 44e34c2 into auto

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/fix-rustdoc-rendering = 44e34c2 merged ok, testing candidate = da5e5e2

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@44e34c2

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/fix-rustdoc-rendering = 44e34c2 into auto

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/fix-rustdoc-rendering = 44e34c2 merged ok, testing candidate = 5d284a0

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 14, 2014

@bors
Copy link
Contributor

@bors bors commented on 44e34c2 Apr 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 5d284a0

Please sign in to comment.