Skip to content

Instantly share code, notes, and snippets.

@kmcallister
Created February 18, 2014 19:57
Show Gist options
  • Select an option

  • Save kmcallister/9078738 to your computer and use it in GitHub Desktop.

Select an option

Save kmcallister/9078738 to your computer and use it in GitHub Desktop.
Void type in Rust
enum Void {}
impl Void {
fn unreachable(self) -> ! {
match self { }
}
unsafe fn make() -> Void {
std::unstable::intrinsics::uninit()
}
}
fn main() {
let x: Void = unsafe { Void::make() };
x.unreachable();
}
/*
$ rustc void.rs
Found return instr that returns non-void in Function of void return type!
ret %enum.Void undef
voidBroken module found, compilation aborted!
Aborted
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment