Skip to content

Commit da5e5e2

Browse files
committed
auto merge of #13464 : alexcrichton/rust/fix-rustdoc-rendering, r=brson
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
2 parents 296e60b + 44e34c2 commit da5e5e2

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

src/librustdoc/html/format.rs

+53-21
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,17 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
279279
}
280280

281281
/// Helper to render type parameters
282-
fn typarams(w: &mut io::Writer,
282+
fn tybounds(w: &mut io::Writer,
283283
typarams: &Option<Vec<clean::TyParamBound> >) -> fmt::Result {
284284
match *typarams {
285285
Some(ref params) => {
286-
try!(write!(w, "&lt;"));
286+
try!(write!(w, ":"));
287287
for (i, param) in params.iter().enumerate() {
288288
if i > 0 {
289-
try!(write!(w, ", "));
289+
try!(write!(w, " + "));
290290
}
291291
try!(write!(w, "{}", *param));
292292
}
293-
try!(write!(w, "&gt;"));
294293
Ok(())
295294
}
296295
None => Ok(())
@@ -308,13 +307,13 @@ impl fmt::Show for clean::Type {
308307
}
309308
clean::ResolvedPath{id, typarams: ref tp, path: ref path} => {
310309
try!(resolved_path(f.buf, id, path, false));
311-
typarams(f.buf, tp)
310+
tybounds(f.buf, tp)
312311
}
313312
clean::ExternalPath{path: ref path, typarams: ref tp,
314313
fqn: ref fqn, kind, krate} => {
315314
try!(external_path(f.buf, path, false, fqn.as_slice(), kind,
316315
krate))
317-
typarams(f.buf, tp)
316+
tybounds(f.buf, tp)
318317
}
319318
clean::Self(..) => f.buf.write("Self".as_bytes()),
320319
clean::Primitive(prim) => {
@@ -338,26 +337,59 @@ impl fmt::Show for clean::Type {
338337
f.buf.write(s.as_bytes())
339338
}
340339
clean::Closure(ref decl, ref region) => {
341-
let region = match *region {
342-
Some(ref region) => format!("{} ", *region),
343-
None => ~"",
344-
};
345-
346-
write!(f.buf, "{}{}|{}|{arrow, select, yes{ -&gt; {ret}} other{}}",
347-
FnStyleSpace(decl.fn_style),
348-
region,
349-
decl.decl.inputs,
340+
write!(f.buf, "{style}{lifetimes}|{args}|{bounds}\
341+
{arrow, select, yes{ -&gt; {ret}} other{}}",
342+
style = FnStyleSpace(decl.fn_style),
343+
lifetimes = if decl.lifetimes.len() == 0 {
344+
~""
345+
} else {
346+
format!("&lt;{:#}&gt;", decl.lifetimes)
347+
},
348+
args = decl.decl.inputs,
350349
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
351-
ret = decl.decl.output)
352-
// FIXME: where are bounds and lifetimes printed?!
350+
ret = decl.decl.output,
351+
bounds = {
352+
let mut ret = StrBuf::new();
353+
match *region {
354+
Some(ref lt) => {
355+
ret.push_str(format!(": {}", *lt));
356+
}
357+
None => {}
358+
}
359+
for bound in decl.bounds.iter() {
360+
match *bound {
361+
clean::RegionBound => {}
362+
clean::TraitBound(ref t) => {
363+
if ret.len() == 0 {
364+
ret.push_str(": ");
365+
} else {
366+
ret.push_str(" + ");
367+
}
368+
ret.push_str(format!("{}", *t));
369+
}
370+
}
371+
}
372+
ret.into_owned()
373+
})
353374
}
354375
clean::Proc(ref decl) => {
355-
write!(f.buf, "{}proc({}){arrow, select, yes{ -&gt; {ret}} other{}}",
356-
FnStyleSpace(decl.fn_style),
357-
decl.decl.inputs,
376+
write!(f.buf, "{style}{lifetimes}proc({args}){bounds}\
377+
{arrow, select, yes{ -&gt; {ret}} other{}}",
378+
style = FnStyleSpace(decl.fn_style),
379+
lifetimes = if decl.lifetimes.len() == 0 {
380+
~""
381+
} else {
382+
format!("&lt;{:#}&gt;", decl.lifetimes)
383+
},
384+
args = decl.decl.inputs,
385+
bounds = if decl.bounds.len() == 0 {
386+
~""
387+
} else {
388+
let mut m = decl.bounds.iter().map(|s| s.to_str());
389+
": " + m.collect::<~[~str]>().connect(" + ")
390+
},
358391
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
359392
ret = decl.decl.output)
360-
// FIXME: where are bounds and lifetimes printed?!
361393
}
362394
clean::BareFunction(ref decl) => {
363395
write!(f.buf, "{}{}fn{}{}",

src/libstd/slice.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,9 @@ impl<A: Clone> Clone for ~[A] {
26012601

26022602
impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
26032603
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2604-
try!(write!(f.buf, "["));
2604+
if f.flags & (1 << (fmt::parse::FlagAlternate as uint)) == 0 {
2605+
try!(write!(f.buf, "["));
2606+
}
26052607
let mut is_first = true;
26062608
for x in self.iter() {
26072609
if is_first {
@@ -2611,7 +2613,10 @@ impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
26112613
}
26122614
try!(write!(f.buf, "{}", *x))
26132615
}
2614-
write!(f.buf, "]")
2616+
if f.flags & (1 << (fmt::parse::FlagAlternate as uint)) == 0 {
2617+
try!(write!(f.buf, "]"));
2618+
}
2619+
Ok(())
26152620
}
26162621
}
26172622

0 commit comments

Comments
 (0)