Skip to content

Commit 8d1a09c

Browse files
committed
auto merge of #6348 : sstewartgallus/rust/incoming, r=brson
In this commit I added a useful utility type, named Void, that encapsulates the doable but annoying job of creating an uninhabited type. As well, a function on that type, named absurd, was created which is useful for ignoring the result of matching on that type. No unit tests were created because it is not possible to create an instance of this type to test the usage of. This type is useful because it is like NonCopyable in that it can be used to create a type with special characteristics without special bloat. For instance, instead of typing pub struct PhantomType { priv contents : () } for each void type one may want to use one can simply type pub struct PhantomType (Void);. This type make such special cases much easier to write.
2 parents 830b945 + 72c9aab commit 8d1a09c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/libcore/util.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -132,6 +132,20 @@ impl Drop for NonCopyable {
132132

133133
pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }
134134

135+
136+
/// A type with no inhabitants
137+
pub enum Void { }
138+
139+
pub impl Void {
140+
/// A utility function for ignoring this uninhabited type
141+
fn uninhabited(&self) -> ! {
142+
match *self {
143+
// Nothing to match on
144+
}
145+
}
146+
}
147+
148+
135149
/**
136150
A utility function for indicating unreachable code. It will fail if
137151
executed. This is occasionally useful to put after loops that never

0 commit comments

Comments
 (0)