Skip to content

Commit 3c1446d

Browse files
committed
describe_enum_variant: Reduce code duplication
1 parent 428943c commit 3c1446d

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,14 @@ fn describe_enum_variant(
15351535
unique_type_id,
15361536
Some(containing_scope));
15371537

1538+
let arg_name = |i: usize| {
1539+
if variant.ctor_kind == CtorKind::Fn {
1540+
format!("__{}", i)
1541+
} else {
1542+
variant.fields[i].ident.to_string()
1543+
}
1544+
};
1545+
15381546
// Build an array of (field name, field type) pairs to be captured in the factory closure.
15391547
let (offsets, args) = if use_enum_fallback(cx) {
15401548
// If this is not a univariant enum, there is also the discriminant field.
@@ -1552,12 +1560,7 @@ fn describe_enum_variant(
15521560
layout.fields.offset(i)
15531561
})).collect(),
15541562
discr_arg.into_iter().chain((0..layout.fields.count()).map(|i| {
1555-
let name = if variant.ctor_kind == CtorKind::Fn {
1556-
format!("__{}", i)
1557-
} else {
1558-
variant.fields[i].ident.to_string()
1559-
};
1560-
(name, layout.field(cx, i).ty)
1563+
(arg_name(i), layout.field(cx, i).ty)
15611564
})).collect()
15621565
)
15631566
} else {
@@ -1566,12 +1569,7 @@ fn describe_enum_variant(
15661569
layout.fields.offset(i)
15671570
}).collect(),
15681571
(0..layout.fields.count()).map(|i| {
1569-
let name = if variant.ctor_kind == CtorKind::Fn {
1570-
format!("__{}", i)
1571-
} else {
1572-
variant.fields[i].ident.to_string()
1573-
};
1574-
(name, layout.field(cx, i).ty)
1572+
(arg_name(i), layout.field(cx, i).ty)
15751573
}).collect()
15761574
)
15771575
};

0 commit comments

Comments
 (0)