Skip to content

Commit 9f7141a

Browse files
Rollup merge of rust-lang#142987 - lolbinarycat:rustdoc-non_exhaustive-enum-v-142599, r=GuillaumeGomez
rustdoc: show attributes on enum variants mostly for #[non_exhaustive] unsure if there's any attributes we should take care to *not* include, it could use `render_code_attribute` and `is_non_exhaustive` instead, if that is a concern. fixes rust-lang#142599
2 parents 8d1e320 + b2be01c commit 9f7141a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,7 @@ fn render_enum_fields(
17031703
if v.is_stripped() {
17041704
continue;
17051705
}
1706+
write!(w, "{}", render_attributes_in_pre(v, TAB, cx))?;
17061707
w.write_str(TAB)?;
17071708
match v.kind {
17081709
clean::VariantItem(ref var) => match var.kind {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// regression test for https://github.com/rust-lang/rust/issues/142599
2+
3+
#![crate_name = "foo"]
4+
5+
//@ snapshot type-code 'foo/enum.Type.html' '//pre[@class="rust item-decl"]/code'
6+
pub enum Type {
7+
#[non_exhaustive]
8+
// attribute that should not be shown
9+
#[warn(unsafe_code)]
10+
Variant,
11+
}
12+
13+
// we would love to use the `following-sibling::` axis
14+
// (along with an `h2[@id="aliased-type"]` query),
15+
// but unfortunately python doesn't implement that.
16+
//@ snapshot type-alias-code 'foo/type.TypeAlias.html' '//pre[@class="rust item-decl"][2]/code'
17+
pub type TypeAlias = Type;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<code>pub enum TypeAlias {
2+
#[non_exhaustive]
3+
Variant,
4+
}</code>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<code>pub enum Type {
2+
#[non_exhaustive]
3+
Variant,
4+
}</code>

0 commit comments

Comments
 (0)