about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcore/lib.rs4
-rw-r--r--src/libcore/tuple/mod.rs (renamed from src/libcore/tuple.rs)2
-rw-r--r--src/libcore/tuple/unit.rs44
-rw-r--r--src/libstd/lib.rs3
4 files changed, 53 insertions, 0 deletions
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 385a33fb92a..4f85ae22e5b 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -122,6 +122,10 @@ pub mod simd;
 pub mod slice;
 pub mod str;
 pub mod tuple;
+// FIXME #15320: primitive documentation needs top-level modules, this
+// should be `core::tuple::unit`.
+#[path = "tuple/unit.rs"]
+pub mod unit;
 pub mod fmt;
 
 #[doc(hidden)]
diff --git a/src/libcore/tuple.rs b/src/libcore/tuple/mod.rs
index 0e3722894bc..4f34c64de1b 100644
--- a/src/libcore/tuple.rs
+++ b/src/libcore/tuple/mod.rs
@@ -61,6 +61,8 @@
 
 #![doc(primitive = "tuple")]
 
+pub use unit;
+
 use clone::Clone;
 use cmp::*;
 use default::Default;
diff --git a/src/libcore/tuple/unit.rs b/src/libcore/tuple/unit.rs
new file mode 100644
index 00000000000..a60b3d098d3
--- /dev/null
+++ b/src/libcore/tuple/unit.rs
@@ -0,0 +1,44 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![doc(primitive = "unit")]
+
+//! The `()` type, sometimes called "unit" or "nil".
+//!
+//! The `()` type has exactly one value `()`, and is used when there
+//! is no other meaningful value that could be returned. `()` is most
+//! commonly seen implicitly: functions without a `-> ...` implicitly
+//! have return type `()`, that is, these are equivalent:
+//!
+//! ```rust
+//! fn long() -> () {}
+//!
+//! fn short() {}
+//! ```
+//!
+//! The semicolon `;` can be used to discard the result of an
+//! expression at the end of a block, making the expression (and thus
+//! the block) evaluate to `()`. For example,
+//!
+//! ```rust
+//! fn returns_i64() -> i64 {
+//!     1i64
+//! }
+//! fn returns_unit() {
+//!     1i64;
+//! }
+//!
+//! let is_i64 = {
+//!     returns_i64()
+//! };
+//! let is_unit = {
+//!     returns_i64();
+//! };
+//! ```
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 48ccd1aa22c..39da8afd03e 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -160,6 +160,9 @@ pub use core::ptr;
 pub use core::raw;
 pub use core::simd;
 pub use core::tuple;
+// FIXME #15320: primitive documentation needs top-level modules, this
+// should be `std::tuple::unit`.
+pub use core::unit;
 #[cfg(not(test))] pub use core::ty;
 pub use core::result;
 pub use core::option;