From c429c7c04b9c19c2ca5992b5f4e094e83832dcb8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 26 Sep 2013 11:09:47 -0700 Subject: 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 --- src/librustdoc/html/render.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') 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, " {}{name}: \ + {},\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, "\ + \ + ", + *cx.current.last(), + it.name.get_ref().as_slice()); +} -- cgit 1.4.1-3-g733a5