From fd7c08447e80169ad1e10a0745cae907b40aadc4 Mon Sep 17 00:00:00 2001 From: RDambrosio016 Date: Wed, 5 Aug 2020 01:34:25 -0400 Subject: [PATCH 1/3] Feat: enum variants with links --- src/librustdoc/html/render/mod.rs | 27 ++++++++++++--------- src/librustdoc/html/static/themes/ayu.css | 3 +++ src/librustdoc/html/static/themes/dark.css | 1 + src/librustdoc/html/static/themes/light.css | 1 + 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 5fb2d9f6f917c..cda3299c9f6fd 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2857,7 +2857,7 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct wrap_into_docblock(w, |w| { write!(w, "
");
         render_attributes(w, it, true);
-        render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true);
+        render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", false);
         write!(w, "
") }); @@ -2970,9 +2970,11 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum, ca let name = v.name.as_ref().unwrap(); match v.inner { clean::VariantItem(ref var) => match var.kind { - clean::VariantKind::CLike => write!(w, "{}", name), + clean::VariantKind::CLike => { + write!(w, "{}", name, name); + } clean::VariantKind::Tuple(ref tys) => { - write!(w, "{}(", name); + write!(w, "{}(", name, name); for (i, ty) in tys.iter().enumerate() { if i > 0 { write!(w, ", ") @@ -2982,7 +2984,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum, ca write!(w, ")"); } clean::VariantKind::Struct(ref s) => { - render_struct(w, v, None, s.struct_type, &s.fields, " ", false); + render_struct(w, v, None, s.struct_type, &s.fields, " ", true); } }, _ => unreachable!(), @@ -3126,15 +3128,16 @@ fn render_struct( ty: doctree::StructType, fields: &[clean::Item], tab: &str, - structhead: bool, + enum_variant: bool, ) { - write!( - w, - "{}{}{}", - it.visibility.print_with_space(), - if structhead { "struct " } else { "" }, - it.name.as_ref().unwrap() - ); + write!(w, "{}", it.visibility.print_with_space()); + // If this is an enum variant we should not write `struct` and the + // name should be a link to the description of the variant. + if enum_variant { + write!(w, "{}", it.name.as_ref().unwrap(), it.name.as_ref().unwrap()); + } else { + write!(w, "struct {} ", it.name.as_ref().unwrap()); + } if let Some(g) = g { write!(w, "{}", g.print()) } diff --git a/src/librustdoc/html/static/themes/ayu.css b/src/librustdoc/html/static/themes/ayu.css index f4710f6ae873a..39551d9445b9c 100644 --- a/src/librustdoc/html/static/themes/ayu.css +++ b/src/librustdoc/html/static/themes/ayu.css @@ -181,6 +181,9 @@ pre { .content span.enum, .content a.enum { color: #99e0c9; } +.content span.variant, .content a.variant { + color: #6380a0; +} .content span.trait, .content a.trait { color: #39AFD7; } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index b3b586ba362fa..b4fae46501e50 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -136,6 +136,7 @@ pre { .content .stability::before { color: #ccc; } .content span.enum, .content a.enum, .block a.current.enum { color: #82b089; } +.content span.variant, .content a.variant, .block a.current.variant { color: #82a5c9; } .content span.struct, .content a.struct, .block a.current.struct { color: #2dbfb8; } .content span.type, .content a.type, .block a.current.type { color: #ff7f00; } .content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #dd7de8; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index b0c5715604baa..1b69775b60c0d 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -137,6 +137,7 @@ pre { .content .stability::before { color: #ccc; } .content span.enum, .content a.enum, .block a.current.enum { color: #508157; } +.content span.variant, .content a.variant, .block a.current.variant { color: #546e8a; } .content span.struct, .content a.struct, .block a.current.struct { color: #ad448e; } .content span.type, .content a.type, .block a.current.type { color: #ba5d00; } .content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #cd00e2; } From 08c1810fed981d16c6ea6df1ea6c2e30e30a0b3b Mon Sep 17 00:00:00 2001 From: RDambrosio016 Date: Wed, 5 Aug 2020 02:03:40 -0400 Subject: [PATCH 2/3] Fix: run proper formatting --- src/librustdoc/html/render/mod.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index cda3299c9f6fd..00579360710d5 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2971,10 +2971,18 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum, ca match v.inner { clean::VariantItem(ref var) => match var.kind { clean::VariantKind::CLike => { - write!(w, "{}", name, name); + write!( + w, + "{}", + name, name + ); } clean::VariantKind::Tuple(ref tys) => { - write!(w, "{}(", name, name); + write!( + w, + "{}(", + name, name + ); for (i, ty) in tys.iter().enumerate() { if i > 0 { write!(w, ", ") @@ -3134,7 +3142,12 @@ fn render_struct( // If this is an enum variant we should not write `struct` and the // name should be a link to the description of the variant. if enum_variant { - write!(w, "{}", it.name.as_ref().unwrap(), it.name.as_ref().unwrap()); + write!( + w, + "{}", + it.name.as_ref().unwrap(), + it.name.as_ref().unwrap() + ); } else { write!(w, "struct {} ", it.name.as_ref().unwrap()); } From cedd951ac369210e4996bab566a863af1a333999 Mon Sep 17 00:00:00 2001 From: RDambrosio016 Date: Sat, 8 Aug 2020 15:02:21 -0400 Subject: [PATCH 3/3] Fix: remove extra space in struct rendering --- src/librustdoc/html/render/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 00579360710d5..494dccdb7e575 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -3149,7 +3149,7 @@ fn render_struct( it.name.as_ref().unwrap() ); } else { - write!(w, "struct {} ", it.name.as_ref().unwrap()); + write!(w, "struct {}", it.name.as_ref().unwrap()); } if let Some(g) = g { write!(w, "{}", g.print())