From 29b4c7b9e0a5e32127c42f5aab9baefadc38033c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 14 May 2018 12:23:12 +0300 Subject: [PATCH] rustc: don't trip an assertion for enums with present but uninhabited variants. --- src/librustc/ty/layout.rs | 5 +++++ src/test/run-pass/issue-50731.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/run-pass/issue-50731.rs diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index b22c025e86c0b..bbfc6d883e9ae 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -888,6 +888,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { if x < min { min = x; } if x > max { max = x; } } + // We might have no inhabited variants, so pretend there's at least one. + if (min, max) == (i128::max_value(), i128::min_value()) { + min = 0; + max = 0; + } assert!(min <= max, "discriminant range is {}...{}", min, max); let (min_ity, signed) = Integer::repr_discr(tcx, ty, &def.repr, min, max); diff --git a/src/test/run-pass/issue-50731.rs b/src/test/run-pass/issue-50731.rs new file mode 100644 index 0000000000000..06df2b989af28 --- /dev/null +++ b/src/test/run-pass/issue-50731.rs @@ -0,0 +1,15 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Void {} +fn foo(_: Result<(Void, u32), (Void, String)>) {} +fn main() { + let _: fn(_) = foo; +}