Skip to content

Commit 017f046

Browse files
authored
Rollup merge of rust-lang#57042 - pnkfelix:issue-57038-sidestep-ice-in-fieldplacement-count, r=michaelwoerister
Don't call `FieldPlacement::count` when count is too large Sidestep ICE in `FieldPlacement::count` by not calling it when count will not fit in host's usize. (I briefly played with trying to fix this by changing `FieldPlacement::count` to return a `u64`. However, based on how `FieldPlacement` is used, it seems like this would be a largely pointless pursuit... I'm open to counter-arguments, however.) Fix rust-lang#57038
2 parents 53aa8a1 + 0eacf2c commit 017f046

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/librustc/ty/layout.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
18421842
return Ok(None);
18431843
}
18441844
}
1845-
if let FieldPlacement::Array { .. } = layout.fields {
1845+
if let FieldPlacement::Array { count: original_64_bit_count, .. } = layout.fields {
1846+
// rust-lang/rust#57038: avoid ICE within FieldPlacement::count when count too big
1847+
if original_64_bit_count > usize::max_value() as u64 {
1848+
return Err(LayoutError::SizeOverflow(layout.ty));
1849+
}
18461850
if layout.fields.count() > 0 {
18471851
return self.find_niche(layout.field(self, 0)?);
18481852
} else {

0 commit comments

Comments
 (0)