From 7c92735f08711cf15dd2dbdbd6119d49ae765807 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 2 Jul 2014 10:21:15 +1000 Subject: [PATCH] core: add a primitive page for `()`. --- src/libcore/lib.rs | 4 +++ src/libcore/{tuple.rs => tuple/mod.rs} | 2 ++ src/libcore/tuple/unit.rs | 44 ++++++++++++++++++++++++++ src/libstd/lib.rs | 3 ++ 4 files changed, 53 insertions(+) rename src/libcore/{tuple.rs => tuple/mod.rs} (99%) create mode 100644 src/libcore/tuple/unit.rs 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 similarity index 99% rename from src/libcore/tuple.rs rename to 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 or the MIT license +// , 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;