Skip to content

Commit

Permalink
Rollup merge of rust-lang#118974 - workingjubilee:why-worry-about-enu…
Browse files Browse the repository at this point in the history
…m-abi, r=davidtwco

Annotate panic! reasons during enum layout

Add some reasons to the panics, and use more exhaustive matches.

Also see: rust-lang#118955
  • Loading branch information
matthiaskrgr committed Dec 15, 2023
2 parents b9a6f19 + 0e9d400 commit 88a9619
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub trait LayoutCalculator {
*offset += this_offset;
}
}
_ => {
FieldsShape::Primitive | FieldsShape::Array { .. } | FieldsShape::Union(..) => {
panic!("Layout of fields should be Arbitrary for variants")
}
}
Expand Down Expand Up @@ -600,7 +600,9 @@ pub trait LayoutCalculator {
variant.size = new_ity_size;
}
}
_ => panic!(),
FieldsShape::Primitive | FieldsShape::Array { .. } | FieldsShape::Union(..) => {
panic!("encountered a non-arbitrary layout during enum layout")
}
}
}
}
Expand Down Expand Up @@ -628,7 +630,7 @@ pub trait LayoutCalculator {
let mut common_prim_initialized_in_all_variants = true;
for (field_layouts, layout_variant) in iter::zip(variants, &layout_variants) {
let FieldsShape::Arbitrary { ref offsets, .. } = layout_variant.fields else {
panic!();
panic!("encountered a non-arbitrary layout during enum layout");
};
// We skip *all* ZST here and later check if we are good in terms of alignment.
// This lets us handle some cases involving aligned ZST.
Expand Down Expand Up @@ -681,7 +683,7 @@ pub trait LayoutCalculator {
assert_eq!(memory_index.raw, [0, 1]);
offsets
}
_ => panic!(),
_ => panic!("encountered a non-arbitrary layout during enum layout"),
};
if pair_offsets[FieldIdx::new(0)] == Size::ZERO
&& pair_offsets[FieldIdx::new(1)] == *offset
Expand Down Expand Up @@ -758,7 +760,9 @@ pub trait LayoutCalculator {
Variants::Multiple { tag, tag_encoding, tag_field, .. } => {
Variants::Multiple { tag, tag_encoding, tag_field, variants: best_layout.variants }
}
_ => panic!(),
Variants::Single { .. } => {
panic!("encountered a single-variant enum during multi-variant layout")
}
};
Some(best_layout.layout)
}
Expand Down Expand Up @@ -1154,7 +1158,11 @@ fn univariant<
assert_eq!(memory_index.raw, [0, 1]);
offsets
}
_ => panic!(),
FieldsShape::Primitive
| FieldsShape::Array { .. }
| FieldsShape::Union(..) => {
panic!("encountered a non-arbitrary layout during enum layout")
}
};
if offsets[i] == pair_offsets[FieldIdx::new(0)]
&& offsets[j] == pair_offsets[FieldIdx::new(1)]
Expand Down

0 comments on commit 88a9619

Please sign in to comment.