Skip to content

Commit 76fe6a4

Browse files
committed
Refactor a nested if to a match
1 parent 76a7667 commit 76fe6a4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/librustc/ty/layout.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -825,17 +825,13 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
825825
});
826826
(present_variants.next(), present_variants.next())
827827
};
828-
let present_first = if present_first.is_none() {
829-
if def.is_enum() {
830-
// Uninhabited because it has no variants, or only absent ones.
831-
return tcx.layout_raw(param_env.and(tcx.types.never));
832-
} else {
833-
// if it's a struct, still compute a layout so that we can still compute the
834-
// field offsets
835-
Some(VariantIdx::new(0))
836-
}
837-
} else {
838-
present_first
828+
let present_first = match present_first {
829+
present_first @ Some(_) => present_first,
830+
// Uninhabited because it has no variants, or only absent ones.
831+
None if def.is_enum() => return tcx.layout_raw(param_env.and(tcx.types.never)),
832+
// if it's a struct, still compute a layout so that we can still compute the
833+
// field offsets
834+
None => Some(VariantIdx::new(0)),
839835
};
840836

841837
let is_struct = !def.is_enum() ||

0 commit comments

Comments
 (0)