Skip to content

Commit 20a134f

Browse files
committed
rustdoc: Use discrs Display impl to render the value with the correct signedness
1 parent de13718 commit 20a134f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,11 +1656,9 @@ fn display_c_like_variant(
16561656
} else if should_show_enum_discriminant {
16571657
let adt_def = cx.tcx().adt_def(enum_def_id);
16581658
let discr = adt_def.discriminant_for_variant(cx.tcx(), index);
1659-
if discr.ty.is_signed() {
1660-
write!(w, "{} = {}", name.as_str(), discr.val as i128)?;
1661-
} else {
1662-
write!(w, "{} = {}", name.as_str(), discr.val)?;
1663-
}
1659+
// Use `discr`'s `Display` impl to render the value with the correct
1660+
// signedness, including proper sign-extension for signed types.
1661+
write!(w, "{} = {}", name.as_str(), discr)?;
16641662
} else {
16651663
write!(w, "{name}")?;
16661664
}

0 commit comments

Comments
 (0)