Skip to content
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

rustdoc: prefer showing enum variants as written #131975

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,8 @@ fn display_c_like_variant(
) {
let name = item.name.unwrap();
if let Some(ref value) = variant.discriminant {
write!(w, "{} = {}", name.as_str(), value.value(cx.tcx(), true));
let v = value.expr(cx.tcx()).unwrap_or(value.value(cx.tcx(), true));
write!(w, "{} = {}", name.as_str(), v);
} else if should_show_enum_discriminant {
let adt_def = cx.tcx().adt_def(enum_def_id);
let discr = adt_def.discriminant_for_variant(cx.tcx(), index);
Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc/src-discrim.perms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<code><div class="code-attribute">#[repr(u8)]</div>pub enum Permissions {
Guest = b'%',
User = b'$',
System = b'@',
Absolute = b'#',
}</code>
12 changes: 12 additions & 0 deletions tests/rustdoc/src-discrim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! regression test for #128347
#![crate_name = "foo"]

//@ snapshot perms foo/enum.Permissions.html '//pre/code'

#[repr(u8)]
pub enum Permissions {
Guest = b'%',
User = b'$',
System = b'@',
Absolute = b'#',
}
Loading