about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-09-26 11:09:47 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-09-26 11:31:40 -0700
commitc429c7c04b9c19c2ca5992b5f4e094e83832dcb8 (patch)
treed42856c49dafa3c5f60d4f4a8e3f7eafa13bf50c /src
parent6f991a24419b4d1f2c4a9d764e07777b6fb317f7 (diff)
downloadrust-c429c7c04b9c19c2ca5992b5f4e094e83832dcb8.tar.gz
rust-c429c7c04b9c19c2ca5992b5f4e094e83832dcb8.zip
rustdoc: Fix broken struct field search links
Takes the same approach as variants, writes a redirect index page back to the
struct with an anchor to the field in question.

Closes #9524
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/render.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 4f8c11d8285..e019599835c 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -521,6 +521,14 @@ impl Context {
                             }
                         }
                     }
+                    clean::StructItem(s) => {
+                        let mut it = s.fields.move_iter();
+                        do self.recurse(name) |this| {
+                            for item in it {
+                                f(this, item);
+                            }
+                        }
+                    }
                     _ => {}
                 }
             }
@@ -590,6 +598,8 @@ impl<'self> fmt::Default for Item<'self> {
             clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
             clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
             clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
+            clean::StructFieldItem(*) => item_struct_field(fmt.buf, it.cx,
+                                                           it.item),
             _ => {}
         }
     }
@@ -980,11 +990,12 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
             for field in fields.iter() {
                 match field.inner {
                     clean::StructFieldItem(ref ty) => {
-                        write!(w, "    {}{}: {},\n{}",
+                        write!(w, "    {}<a name='field.{name}'>{name}</a>: \
+                                   {},\n{}",
                                VisSpace(field.visibility),
-                               field.name.get_ref().as_slice(),
                                ty.type_,
-                               tab);
+                               tab,
+                               name = field.name.get_ref().as_slice());
                     }
                     _ => unreachable!()
                 }
@@ -1170,3 +1181,12 @@ fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
            *cx.current.last(),
            it.name.get_ref().as_slice());
 }
+
+fn item_struct_field(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
+    write!(w, "<DOCTYPE html><html><head>\
+                <meta http-equiv='refresh' content='0; \
+                      url=../struct.{}.html\\#field.{}'>\
+               </head><body></body></html>",
+           *cx.current.last(),
+           it.name.get_ref().as_slice());
+}