Skip to content

Commit

Permalink
Permit uninhabited enums to cast into ints
Browse files Browse the repository at this point in the history
This essentially reverts part of #6204.
  • Loading branch information
Mark-Simulacrum committed Sep 1, 2020
1 parent e88e908 commit e023158
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/uninhabited/uninhabited-enum-cast.rs
Original file line number Diff line number Diff line change
@@ -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() {}
9 changes: 0 additions & 9 deletions src/test/ui/uninhabited/uninhabited-enum-cast.stderr

This file was deleted.

0 comments on commit e023158

Please sign in to comment.