Skip to content

Commit 0eacf2c

Browse files
committed
Sidestep ICE in FieldPlacement::count by not calling it when count will not fit in host's usize.
1 parent 6d34ec1 commit 0eacf2c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/librustc/ty/layout.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
18521852
return Ok(None);
18531853
}
18541854
}
1855-
if let FieldPlacement::Array { .. } = layout.fields {
1855+
if let FieldPlacement::Array { count: original_64_bit_count, .. } = layout.fields {
1856+
// rust-lang/rust#57038: avoid ICE within FieldPlacement::count when count too big
1857+
if original_64_bit_count > usize::max_value() as u64 {
1858+
return Err(LayoutError::SizeOverflow(layout.ty));
1859+
}
18561860
if layout.fields.count() > 0 {
18571861
return self.find_niche(layout.field(self, 0)?);
18581862
} else {

0 commit comments

Comments
 (0)