From f89cc11827a36e6d1eb4e22322a51eb9b1153450 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 2 Jul 2014 10:20:39 +1000 Subject: [PATCH 1/2] rustdoc: s/nil/unit/ internally. Quick poll on IRC suggested that unit was the preferred name for (). --- src/librustdoc/clean/mod.rs | 12 ++++++------ src/librustdoc/html/format.rs | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 87151708812e5..be761341f1bf4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1079,7 +1079,7 @@ pub enum Primitive { F32, F64, Char, Bool, - Nil, + Unit, Str, Slice, PrimitiveTuple, @@ -1110,7 +1110,7 @@ impl Primitive { "u32" => Some(U32), "u64" => Some(U64), "bool" => Some(Bool), - "nil" => Some(Nil), + "unit" => Some(Unit), "char" => Some(Char), "str" => Some(Str), "f32" => Some(F32), @@ -1159,7 +1159,7 @@ impl Primitive { Str => "str", Bool => "bool", Char => "char", - Nil => "()", + Unit => "()", Slice => "slice", PrimitiveTuple => "tuple", } @@ -1167,7 +1167,7 @@ impl Primitive { pub fn to_url_str(&self) -> &'static str { match *self { - Nil => "nil", + Unit => "unit", other => other.to_str(), } } @@ -1184,7 +1184,7 @@ impl Clean for ast::Ty { fn clean(&self) -> Type { use syntax::ast::*; match self.node { - TyNil => Primitive(Nil), + TyNil => Primitive(Unit), TyPtr(ref m) => RawPointer(m.mutbl.clean(), box m.ty.clean()), TyRptr(ref l, ref m) => BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(), @@ -1214,7 +1214,7 @@ impl Clean for ty::t { fn clean(&self) -> Type { match ty::get(*self).sty { ty::ty_bot => Bottom, - ty::ty_nil => Primitive(Nil), + ty::ty_nil => Primitive(Unit), ty::ty_bool => Primitive(Bool), ty::ty_char => Primitive(Char), ty::ty_int(ast::TyI) => Primitive(Int), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 9677b9004cdf1..cec665768d1ee 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -362,7 +362,7 @@ impl fmt::Show for clean::Type { }, args = decl.decl.inputs, arrow = match decl.decl.output { - clean::Primitive(clean::Nil) => "".to_string(), + clean::Primitive(clean::Unit) => "".to_string(), _ => format!(" -> {}", decl.decl.output), }, bounds = { @@ -411,7 +411,7 @@ impl fmt::Show for clean::Type { m.collect::>().connect(" + ")) }, arrow = match decl.decl.output { - clean::Primitive(clean::Nil) => "".to_string(), + clean::Primitive(clean::Unit) => "".to_string(), _ => format!(" -> {}", decl.decl.output) }) } @@ -472,7 +472,7 @@ impl fmt::Show for clean::FnDecl { write!(f, "({args}){arrow}", args = self.inputs, arrow = match self.output { - clean::Primitive(clean::Nil) => "".to_string(), + clean::Primitive(clean::Unit) => "".to_string(), _ => format!(" -> {}", self.output), }) } @@ -505,7 +505,7 @@ impl<'a> fmt::Show for Method<'a> { write!(f, "({args}){arrow}", args = args, arrow = match d.output { - clean::Primitive(clean::Nil) => "".to_string(), + clean::Primitive(clean::Unit) => "".to_string(), _ => format!(" -> {}", d.output), }) } From 7c92735f08711cf15dd2dbdbd6119d49ae765807 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 2 Jul 2014 10:21:15 +1000 Subject: [PATCH 2/2] 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 385a33fb92a4c..4f85ae22e5bfc 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 0e3722894bc46..4f34c64de1ba5 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 0000000000000..a60b3d098d361 --- /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 48ccd1aa22ce3..39da8afd03e55 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;