From f40b60b0e46512e204225ce42c702ce23c943232 Mon Sep 17 00:00:00 2001 From: "NODA, Kai" Date: Sun, 28 Sep 2014 00:15:31 +0800 Subject: [PATCH] librustdoc/html: recognize slices not to nest A tags. 1. A slice of parametrized type, say BorrowedRef { ... Vector(Generic(T)) }, is rendered as "&[T]" 2. A slice of other types, say BorrowedRef { ... Vector(int) }, is rendered as "&[ int ]" 3. Other cases, say BorrowedRef { ... int }, are rendered as same as before: "&int" 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. --- src/librustdoc/html/format.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index ebccb1188cc7..02ba4aabc991 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -478,7 +478,25 @@ impl fmt::Show for clean::Type { Some(ref l) => format!("{} ", *l), _ => "".to_string(), }; - write!(f, "&{}{}{}", lt, MutableSpace(mutability), **ty) + let m = MutableSpace(mutability); + match **ty { + clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T] + match **bt { + clean::Generic(_) => + primitive_link(f, clean::Slice, + format!("&{}{}[{}]", lt, m, **bt).as_slice()), + _ => { + try!(primitive_link(f, clean::Slice, + format!("&{}{}[", lt, m).as_slice())); + try!(write!(f, "{}", **bt)); + primitive_link(f, clean::Slice, "]") + } + } + } + _ => { + write!(f, "&{}{}{}", lt, m, **ty) + } + } } clean::Unique(..) => { fail!("should have been cleaned")