Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed type signature of uninhabited method. #6442

Closed
wants to merge 1 commit into from
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 ()
}
}
}