@@ -1261,6 +1261,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
1261
1261
variants_count,
1262
1262
has_stripped_entries,
1263
1263
* is_non_exhaustive,
1264
+ it. def_id ( ) . unwrap ( ) ,
1264
1265
)
1265
1266
} ) ;
1266
1267
item_variants ( w, cx, it, & variants) ;
@@ -1425,6 +1426,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
1425
1426
count_variants,
1426
1427
e. has_stripped_entries ( ) ,
1427
1428
it. is_non_exhaustive ( ) ,
1429
+ it. def_id ( ) . unwrap ( ) ,
1428
1430
) ;
1429
1431
} ) ;
1430
1432
@@ -1438,21 +1440,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
1438
1440
write ! ( w, "{}" , document_type_layout( cx, def_id) ) ;
1439
1441
}
1440
1442
1441
- fn get_parent_enum_def_id (
1442
- cx : & mut Context < ' _ > ,
1443
- variant_def_id : rustc_hir:: def_id:: LocalDefId ,
1444
- ) -> DefId {
1445
- use rustc_hir:: { ItemKind , Node } ;
1446
- let variant_hir_id = cx. tcx ( ) . hir ( ) . local_def_id_to_hir_id ( variant_def_id) ;
1447
-
1448
- for ( _, node) in cx. tcx ( ) . hir ( ) . parent_iter ( variant_hir_id) {
1449
- if let Node :: Item ( item) = node && matches ! ( item. kind, ItemKind :: Enum ( ..) ) {
1450
- return item. owner_id . to_def_id ( ) ;
1451
- }
1452
- }
1453
- panic ! ( "No parent enum found for variant {variant_def_id:?}" ) ;
1454
- }
1455
-
1456
1443
/// It'll return true if all variants are C-like variants and if at least one of them has a value
1457
1444
/// set.
1458
1445
fn should_show_c_like_variants_value (
@@ -1478,15 +1465,12 @@ fn display_c_like_variant(
1478
1465
variant : & clean:: Variant ,
1479
1466
index : rustc_target:: abi:: VariantIdx ,
1480
1467
should_show_c_like_variants_value : bool ,
1468
+ enum_def_id : DefId ,
1481
1469
) {
1482
1470
let name = item. name . unwrap ( ) ;
1483
1471
if let Some ( ref value) = variant. discriminant {
1484
1472
write ! ( w, "{} = {}" , name. as_str( ) , value. value( cx. tcx( ) , true ) ) ;
1485
- } else if should_show_c_like_variants_value &&
1486
- let Some ( variant_def_id) = item. item_id . as_def_id ( ) &&
1487
- let Some ( variant_def_id) = variant_def_id. as_local ( )
1488
- {
1489
- let enum_def_id = get_parent_enum_def_id ( cx, variant_def_id) ;
1473
+ } else if should_show_c_like_variants_value {
1490
1474
let adt_def = cx. tcx ( ) . adt_def ( enum_def_id) ;
1491
1475
let discr = adt_def. discriminant_for_variant ( cx. tcx ( ) , index) ;
1492
1476
if discr. ty . is_signed ( ) {
@@ -1507,6 +1491,7 @@ fn render_enum_fields(
1507
1491
count_variants : usize ,
1508
1492
has_stripped_entries : bool ,
1509
1493
is_non_exhaustive : bool ,
1494
+ enum_def_id : DefId ,
1510
1495
) {
1511
1496
let should_show_c_like_variants_value = should_show_c_like_variants_value ( variants) ;
1512
1497
if !g. is_some_and ( |g| print_where_clause_and_check ( w, g, cx) ) {
@@ -1538,6 +1523,7 @@ fn render_enum_fields(
1538
1523
var,
1539
1524
index,
1540
1525
should_show_c_like_variants_value,
1526
+ enum_def_id,
1541
1527
) ,
1542
1528
clean:: VariantKind :: Tuple ( ref s) => {
1543
1529
write ! ( w, "{}({})" , v. name. unwrap( ) , print_tuple_struct_fields( cx, s) ) ;
@@ -1608,6 +1594,7 @@ fn item_variants(
1608
1594
var,
1609
1595
index,
1610
1596
should_show_c_like_variants_value,
1597
+ it. def_id ( ) . unwrap ( ) ,
1611
1598
) ;
1612
1599
} else {
1613
1600
w. write_str ( variant. name . unwrap ( ) . as_str ( ) ) ;
0 commit comments