-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve display of enum variants #90089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1080,7 +1080,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum | |
cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.as_ref().unwrap())); | ||
write!( | ||
w, | ||
"<div id=\"{id}\" class=\"variant small-section-header\">\ | ||
"<h3 id=\"{id}\" class=\"variant small-section-header\">\ | ||
<a href=\"#{id}\" class=\"anchor field\"></a>\ | ||
<code>{name}", | ||
id = id, | ||
|
@@ -1093,9 +1093,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum | |
} | ||
w.write_str("</code>"); | ||
render_stability_since(w, variant, it, cx.tcx()); | ||
w.write_str("</div>"); | ||
document(w, cx, variant, Some(it), HeadingOffset::H3); | ||
document_non_exhaustive(w, variant); | ||
w.write_str("</h3>"); | ||
|
||
use crate::clean::Variant; | ||
if let Some((extra, fields)) = match *variant.kind { | ||
|
@@ -1109,12 +1107,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum | |
variant.name.as_ref().unwrap() | ||
)); | ||
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id); | ||
write!( | ||
w, | ||
"<h3>{extra}Fields of <b>{name}</b></h3><div>", | ||
extra = extra, | ||
name = variant.name.as_ref().unwrap(), | ||
); | ||
write!(w, "<h4>{extra}Fields</h4>", extra = extra,); | ||
document_non_exhaustive(w, variant); | ||
for field in fields { | ||
match *field.kind { | ||
clean::StrippedItem(box clean::StructFieldItem(_)) => {} | ||
|
@@ -1126,21 +1120,25 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum | |
)); | ||
write!( | ||
w, | ||
"<span id=\"{id}\" class=\"variant small-section-header\">\ | ||
"<div class=\"sub-variant-field\">\ | ||
<span id=\"{id}\" class=\"variant small-section-header\">\ | ||
<a href=\"#{id}\" class=\"anchor field\"></a>\ | ||
<code>{f}: {t}</code>\ | ||
</span>", | ||
id = id, | ||
f = field.name.as_ref().unwrap(), | ||
t = ty.print(cx) | ||
); | ||
document(w, cx, field, Some(variant), HeadingOffset::H4); | ||
document(w, cx, field, Some(variant), HeadingOffset::H5); | ||
write!(w, "</div>"); | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
w.write_str("</div></div>"); | ||
w.write_str("</div>"); | ||
} | ||
|
||
document(w, cx, variant, Some(it), HeadingOffset::H4); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, should this be H3? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think (iirc) that it means the biggest heading will be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I think the heading immediately above (in the HTML, not the Rust source) is h3? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is correct. In the demo: https://rustdoc.crud.net/jsha/enum-headings/foo/enum.Token.html#variant.Declaration "Declaration" is h3, and then "Variant-First" is h4, as it should be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I guess I'm still confused by |
||
} | ||
} | ||
let def_id = it.def_id.expect_def_id(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![crate_name = "foo"] | ||
// @has foo/enum.Token.html | ||
/// A token! | ||
/// # First | ||
/// Some following text... | ||
// @has - '//h2[@id="first"]' "First" | ||
pub enum Token { | ||
/// A declaration! | ||
/// # Variant-First | ||
/// Some following text... | ||
// @has - '//h4[@id="variant-first"]' "Variant-First" | ||
Declaration { | ||
/// A version! | ||
/// # Variant-Field-First | ||
/// Some following text... | ||
// @has - '//h5[@id="variant-field-first"]' "Variant-Field-First" | ||
version: String, | ||
}, | ||
/// A Zoople! | ||
/// # Variant-First | ||
Zoople( | ||
// @has - '//h5[@id="variant-tuple-field-first"]' "Variant-Tuple-Field-First" | ||
/// Zoople's first variant! | ||
/// # Variant-Tuple-Field-First | ||
/// Some following text... | ||
usize, | ||
), | ||
/// Unfinished business! | ||
/// # Non-Exhaustive-First | ||
/// Some following text... | ||
// @has - '//h4[@id="non-exhaustive-first"]' "Non-Exhaustive-First" | ||
#[non_exhaustive] | ||
Unfinished { | ||
/// This is x. | ||
/// # X-First | ||
/// Some following text... | ||
// @has - '//h5[@id="x-first"]' "X-First" | ||
x: usize, | ||
}, | ||
} |
Uh oh!
There was an error while loading. Please reload this page.