Skip to content

Commit f40b60b

Browse files
committed
librustdoc/html: recognize slices not to nest A tags.
1. A slice of parametrized type, say BorrowedRef { ... Vector(Generic(T)) }, is rendered as "<a href='primitive.slice.html'>&amp;[T]</a>" 2. A slice of other types, say BorrowedRef { ... Vector(int) }, is rendered as "<a href='primitive.slice.html'>&amp;[</a> <a href='primitive.int.html'>int</a> <a href='primitive.slice.html'>]</a>" 3. Other cases, say BorrowedRef { ... int }, are rendered as same as before: "&<a href='primitive.int.html'>int</a>" Relevant W3C specs: - http://www.w3.org/TR/html401/struct/links.html#h-12.2.2 12.2.2 Nested links are illegal - http://www.w3.org/TR/html5/text-level-semantics.html#the-a-element states A tag must not enclose any "interactive contents" which include A tags themselves.
1 parent bc649ba commit f40b60b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/librustdoc/html/format.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,25 @@ impl fmt::Show for clean::Type {
478478
Some(ref l) => format!("{} ", *l),
479479
_ => "".to_string(),
480480
};
481-
write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
481+
let m = MutableSpace(mutability);
482+
match **ty {
483+
clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
484+
match **bt {
485+
clean::Generic(_) =>
486+
primitive_link(f, clean::Slice,
487+
format!("&amp;{}{}[{}]", lt, m, **bt).as_slice()),
488+
_ => {
489+
try!(primitive_link(f, clean::Slice,
490+
format!("&amp;{}{}[", lt, m).as_slice()));
491+
try!(write!(f, "{}", **bt));
492+
primitive_link(f, clean::Slice, "]")
493+
}
494+
}
495+
}
496+
_ => {
497+
write!(f, "&amp;{}{}{}", lt, m, **ty)
498+
}
499+
}
482500
}
483501
clean::Unique(..) => {
484502
fail!("should have been cleaned")

0 commit comments

Comments
 (0)