From 9263cbbcc8bb503e6abd93f111401b2f63f6a67d Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 10 Mar 2020 10:10:10 +0100 Subject: [PATCH] VariantSizeDifferences: bail on SizeOverflow --- src/librustc_lint/types.rs | 6 ++---- src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs | 9 +++++++++ .../ui/lint/issue-69485-var-size-diffs-too-large.stderr | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs create mode 100644 src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 86d93612e993b..2896682ea8268 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -998,10 +998,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { let ty = cx.tcx.erase_regions(&t); let layout = match cx.layout_of(ty) { Ok(layout) => layout, - Err(ty::layout::LayoutError::Unknown(_)) => return, - Err(err @ ty::layout::LayoutError::SizeOverflow(_)) => { - bug!("failed to get layout for `{}`: {}", t, err); - } + Err(ty::layout::LayoutError::Unknown(_)) + | Err(ty::layout::LayoutError::SizeOverflow(_)) => return, }; let (variants, tag) = match layout.variants { layout::Variants::Multiple { diff --git a/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs new file mode 100644 index 0000000000000..59032ab9775c8 --- /dev/null +++ b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs @@ -0,0 +1,9 @@ +// build-fail + +fn main() { + Bug::V([0; !0]); //~ ERROR is too big for the current +} + +enum Bug { + V([u8; !0]), +} diff --git a/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr new file mode 100644 index 0000000000000..ce9790fc94681 --- /dev/null +++ b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr @@ -0,0 +1,8 @@ +error: the type `[u8; 18446744073709551615]` is too big for the current architecture + --> $DIR/issue-69485-var-size-diffs-too-large.rs:4:12 + | +LL | Bug::V([0; !0]); + | ^^^^^^^ + +error: aborting due to previous error +