Permit uninhabited enums to cast into ints

This essentially reverts part of #6204.
This commit is contained in:
Mark Rousskov 2020-09-01 09:49:40 -04:00
parent e88e908e66
commit e023158145
3 changed files with 6 additions and 11 deletions

View file

@ -2481,8 +2481,10 @@ impl<'tcx> AdtDef {
self.variants.iter().flat_map(|v| v.fields.iter())
}
/// Whether the ADT lacks fields. Note that this includes uninhabited enums,
/// e.g., `enum Void {}` is considered payload free as well.
pub fn is_payloadfree(&self) -> bool {
!self.variants.is_empty() && self.variants.iter().all(|v| v.fields.is_empty())
self.variants.iter().all(|v| v.fields.is_empty())
}
/// Return a `VariantDef` given a variant id.

View file

@ -1,7 +1,9 @@
// check-pass
enum E {}
fn f(e: E) {
println!("{}", (e as isize).to_string()); //~ ERROR non-primitive cast
println!("{}", (e as isize).to_string());
}
fn main() {}

View file

@ -1,9 +0,0 @@
error[E0605]: non-primitive cast: `E` as `isize`
--> $DIR/uninhabited-enum-cast.rs:4:20
|
LL | println!("{}", (e as isize).to_string());
| ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
error: aborting due to previous error
For more information about this error, try `rustc --explain E0605`.