From 0eacf2cb240606343284a2d38b0f54b6028b134d Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 21 Dec 2018 15:08:33 +0100 Subject: [PATCH] Sidestep ICE in `FieldPlacement::count` by not calling it when count will not fit in host's usize. --- src/librustc/ty/layout.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index f4506c8e819..2bc352d1d99 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1852,7 +1852,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { return Ok(None); } } - if let FieldPlacement::Array { .. } = layout.fields { + if let FieldPlacement::Array { count: original_64_bit_count, .. } = layout.fields { + // rust-lang/rust#57038: avoid ICE within FieldPlacement::count when count too big + if original_64_bit_count > usize::max_value() as u64 { + return Err(LayoutError::SizeOverflow(layout.ty)); + } if layout.fields.count() > 0 { return self.find_niche(layout.field(self, 0)?); } else {