Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/libcore/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ pub enum Void { }

pub impl Void {
/// A utility function for ignoring this uninhabited type
fn uninhabited(&self) -> ! {
match *self {
fn uninhabited(self) -> ! {
match self {
// Nothing to match on
}
}
Expand Down Expand Up @@ -177,7 +177,8 @@ pub fn unreachable() -> ! {
#[cfg(test)]
mod tests {
use option::{None, Some};
use util::{NonCopyable, id, replace, swap};
use util::{Void, NonCopyable, id, replace, swap};
use either::{Either, Left, Right};

#[test]
pub fn identity_crisis() {
Expand All @@ -202,4 +203,12 @@ mod tests {
assert!(x.is_none());
assert!(y.is_some());
}
#[test]
pub fn test_uninhabited() {
let could_only_be_coin : Either <Void, ()> = Right (());
match could_only_be_coin {
Right (coin) => coin,
Left (is_void) => is_void.uninhabited ()
}
}
}