mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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 https://github.com/mozilla/rust/pull/6348
This commit is contained in:
commit
290a2ebab6
@ -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 ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user