Skip to content

Commit

Permalink
Fixed type signature of uninhabited method.
Browse files Browse the repository at this point in the history
Added unit test to prevent similar mistakes from happening again. The
previous method was wrong because it dereferenced a pointer to a void type to
match on the result. No self pointer was needed, and the correct method
signature took the self value by value.
  • Loading branch information
Steven Stewart-Gallus committed May 13, 2013
1 parent 1bf2f68 commit 8c5de02
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/libcore/util.rs
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 ()
}
}
}

9 comments on commit 8c5de02

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at mstewartgallus@8c5de02

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging sstewartgallus/rust/incoming = 8c5de02 into auto

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sstewartgallus/rust/incoming = 8c5de02 merged ok, testing candidate = c1bf6a43

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at mstewartgallus@8c5de02

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging sstewartgallus/rust/incoming = 8c5de02 into auto

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sstewartgallus/rust/incoming = 8c5de02 merged ok, testing candidate = 290a2eb

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 8c5de02 May 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 290a2eb

Please sign in to comment.