Skip to content

Commit 290a2eb

Browse files
committed
auto merge of #6442 : sstewartgallus/rust/incoming, r=pcwalton
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. I feel silly that I made this mistake in #6348
2 parents dbbc244 + 8c5de02 commit 290a2eb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/libcore/util.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ pub enum Void { }
138138

139139
pub impl Void {
140140
/// A utility function for ignoring this uninhabited type
141-
fn uninhabited(&self) -> ! {
142-
match *self {
141+
fn uninhabited(self) -> ! {
142+
match self {
143143
// Nothing to match on
144144
}
145145
}
@@ -177,7 +177,8 @@ pub fn unreachable() -> ! {
177177
#[cfg(test)]
178178
mod tests {
179179
use option::{None, Some};
180-
use util::{NonCopyable, id, replace, swap};
180+
use util::{Void, NonCopyable, id, replace, swap};
181+
use either::{Either, Left, Right};
181182

182183
#[test]
183184
pub fn identity_crisis() {
@@ -202,4 +203,12 @@ mod tests {
202203
assert!(x.is_none());
203204
assert!(y.is_some());
204205
}
206+
#[test]
207+
pub fn test_uninhabited() {
208+
let could_only_be_coin : Either <Void, ()> = Right (());
209+
match could_only_be_coin {
210+
Right (coin) => coin,
211+
Left (is_void) => is_void.uninhabited ()
212+
}
213+
}
205214
}

0 commit comments

Comments
 (0)