Skip to content

Commit c429c7c

Browse files
committed
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
1 parent 6f991a2 commit c429c7c

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/librustdoc/html/render.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,14 @@ impl Context {
521521
}
522522
}
523523
}
524+
clean::StructItem(s) => {
525+
let mut it = s.fields.move_iter();
526+
do self.recurse(name) |this| {
527+
for item in it {
528+
f(this, item);
529+
}
530+
}
531+
}
524532
_ => {}
525533
}
526534
}
@@ -590,6 +598,8 @@ impl<'self> fmt::Default for Item<'self> {
590598
clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
591599
clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
592600
clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
601+
clean::StructFieldItem(*) => item_struct_field(fmt.buf, it.cx,
602+
it.item),
593603
_ => {}
594604
}
595605
}
@@ -980,11 +990,12 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
980990
for field in fields.iter() {
981991
match field.inner {
982992
clean::StructFieldItem(ref ty) => {
983-
write!(w, " {}{}: {},\n{}",
993+
write!(w, " {}<a name='field.{name}'>{name}</a>: \
994+
{},\n{}",
984995
VisSpace(field.visibility),
985-
field.name.get_ref().as_slice(),
986996
ty.type_,
987-
tab);
997+
tab,
998+
name = field.name.get_ref().as_slice());
988999
}
9891000
_ => unreachable!()
9901001
}
@@ -1170,3 +1181,12 @@ fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
11701181
*cx.current.last(),
11711182
it.name.get_ref().as_slice());
11721183
}
1184+
1185+
fn item_struct_field(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
1186+
write!(w, "<DOCTYPE html><html><head>\
1187+
<meta http-equiv='refresh' content='0; \
1188+
url=../struct.{}.html\\#field.{}'>\
1189+
</head><body></body></html>",
1190+
*cx.current.last(),
1191+
it.name.get_ref().as_slice());
1192+
}

0 commit comments

Comments
 (0)