about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSteven Stewart-Gallus <sstewartgallus00@langara.bc.ca>2013-05-12 19:43:44 -0700
committerSteven Stewart-Gallus <sstewartgallus00@langara.bc.ca>2013-05-13 10:51:14 -0700
commit8c5de02289d515a367746d062b81e4d473e558ee (patch)
tree1613804ec2359910fe54cbd35bc0ac27fa7a1c82 /src
parent1bf2f68bb255cc6833d4253c4f6d071af9e05648 (diff)
Fixed type signature of uninhabited method.
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.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/util.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libcore/util.rs b/src/libcore/util.rs
index ba176872b9a..c6add76f944 100644
--- a/src/libcore/util.rs
+++ b/src/libcore/util.rs
@@ -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
         }
     }
@@ -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() {
@@ -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 ()
+        }
+    }
 }