1
Fork 0

rustc: don't trip an assertion for enums with present but uninhabited variants.

This commit is contained in:
Eduard-Mihai Burtescu 2018-05-14 12:23:12 +03:00
parent 76027ed2ad
commit 29b4c7b9e0
2 changed files with 20 additions and 0 deletions

View file

@ -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);

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
}