Skip to content

Commit e023158

Browse files
Permit uninhabited enums to cast into ints
This essentially reverts part of #6204.
1 parent e88e908 commit e023158

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2481,8 +2481,10 @@ impl<'tcx> AdtDef {
24812481
self.variants.iter().flat_map(|v| v.fields.iter())
24822482
}
24832483

2484+
/// Whether the ADT lacks fields. Note that this includes uninhabited enums,
2485+
/// e.g., `enum Void {}` is considered payload free as well.
24842486
pub fn is_payloadfree(&self) -> bool {
2485-
!self.variants.is_empty() && self.variants.iter().all(|v| v.fields.is_empty())
2487+
self.variants.iter().all(|v| v.fields.is_empty())
24862488
}
24872489

24882490
/// Return a `VariantDef` given a variant id.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// check-pass
2+
13
enum E {}
24

35
fn f(e: E) {
4-
println!("{}", (e as isize).to_string()); //~ ERROR non-primitive cast
6+
println!("{}", (e as isize).to_string());
57
}
68

79
fn main() {}

src/test/ui/uninhabited/uninhabited-enum-cast.stderr

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)