]> git.lizzy.rs Git - rust.git/commitdiff
librustdoc/html: recognize slices not to nest A tags.
authorNODA, Kai <nodakai@gmail.com>
Sat, 27 Sep 2014 16:15:31 +0000 (00:15 +0800)
committerNODA, Kai <nodakai@gmail.com>
Wed, 8 Oct 2014 12:36:30 +0000 (20:36 +0800)
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.

src/librustdoc/html/format.rs

index ebccb1188cc7554a6ddde0f03f8a4b0963f0c182..02ba4aabc9919f79d60415bbdf60524c464e1ec4 100644 (file)
@@ -478,7 +478,25 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                     Some(ref l) => format!("{} ", *l),
                     _ => "".to_string(),
                 };
-                write!(f, "&amp;{}{}{}", 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!("&amp;{}{}[{}]", lt, m, **bt).as_slice()),
+                            _ => {
+                                try!(primitive_link(f, clean::Slice,
+                                    format!("&amp;{}{}[", lt, m).as_slice()));
+                                try!(write!(f, "{}", **bt));
+                                primitive_link(f, clean::Slice, "]")
+                            }
+                        }
+                    }
+                    _ => {
+                        write!(f, "&amp;{}{}{}", lt, m, **ty)
+                    }
+                }
             }
             clean::Unique(..) => {
                 fail!("should have been cleaned")