Skip to content

Commit 5636ca6

Browse files
committed
rustdoc: Start rendering variants (redirect to enum)
This allows reasonable behavior when an enum is clicked in an import.
1 parent 5c6f8a9 commit 5636ca6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/librustdoc/html/render.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ impl<'self> fmt::Default for Item<'self> {
589589
clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
590590
clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
591591
clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
592+
clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
592593
_ => {}
593594
}
594595
}
@@ -930,7 +931,8 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
930931
} else {
931932
write!(w, " \\{\n");
932933
for v in e.variants.iter() {
933-
let name = v.name.get_ref().as_slice();
934+
let name = format!("<a name='variant.{0}'>{0}</a>",
935+
v.name.get_ref().as_slice());
934936
match v.inner {
935937
clean::VariantItem(ref var) => {
936938
match var.kind {
@@ -1159,3 +1161,12 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
11591161
}
11601162
return map;
11611163
}
1164+
1165+
fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
1166+
write!(w, "<DOCTYPE html><html><head>\
1167+
<meta http-equiv='refresh' content='0; \
1168+
url=../enum.{}.html\\#variant.{}'>\
1169+
</head><body></body></html>",
1170+
*cx.current.last(),
1171+
it.name.get_ref().as_slice());
1172+
}

0 commit comments

Comments
 (0)