Skip to content

Commit 935a2f1

Browse files
committed
Auto merge of #50735 - eddyb:issue-50731, r=nikomatsakis
rustc: don't trip an assertion for enums with present but uninhabited variants. Fixes #50731. r? @nikomatsakis
2 parents cb1ce7d + 29b4c7b commit 935a2f1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/librustc/ty/layout.rs

+5
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
888888
if x < min { min = x; }
889889
if x > max { max = x; }
890890
}
891+
// We might have no inhabited variants, so pretend there's at least one.
892+
if (min, max) == (i128::max_value(), i128::min_value()) {
893+
min = 0;
894+
max = 0;
895+
}
891896
assert!(min <= max, "discriminant range is {}...{}", min, max);
892897
let (min_ity, signed) = Integer::repr_discr(tcx, ty, &def.repr, min, max);
893898

src/test/run-pass/issue-50731.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Void {}
12+
fn foo(_: Result<(Void, u32), (Void, String)>) {}
13+
fn main() {
14+
let _: fn(_) = foo;
15+
}

0 commit comments

Comments
 (0)