rustdoc: Generate valid code for struct-variants

Closes #9587
This commit is contained in:
Alex Crichton 2013-09-30 11:44:25 -07:00
parent 8174618a05
commit a3ccbdc904

View File

@ -1050,7 +1050,7 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
write!(w, "<pre class='struct'>");
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields, "");
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields, "", true);
write!(w, "</pre>");
document(w, it);
@ -1082,8 +1082,10 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
write!(w, "),\n");
}
clean::StructVariant(ref s) => {
write!(w, " ");
render_struct(w, v, None, s.struct_type, s.fields,
" ");
" ", false);
write!(w, ",\n");
}
}
}
@ -1102,9 +1104,11 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
g: Option<&clean::Generics>,
ty: doctree::StructType,
fields: &[clean::Item],
tab: &str) {
write!(w, "{}struct {}",
tab: &str,
structhead: bool) {
write!(w, "{}{}{}",
VisSpace(it.visibility),
if structhead {"struct "} else {""},
it.name.get_ref().as_slice());
match g {
Some(g) => write!(w, "{}", *g),
@ -1112,7 +1116,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
}
match ty {
doctree::Plain => {
write!(w, " \\{\n");
write!(w, " \\{\n{}", tab);
for field in fields.iter() {
match field.inner {
clean::StructFieldItem(ref ty) => {