Skip to content

Commit d623a8b

Browse files
committed
auto merge of #15321 : huonw/rust/nil-prim, r=alexcrichton
This adds a primitive page for () like http://doc.rust-lang.org/master/std/uint/primitive.uint.html . I would prefer the modules to be `std::tuple::unit`, but rustdoc only searches at the top level (filed as #15320).
2 parents 5b11610 + 7c92735 commit d623a8b

File tree

6 files changed

+63
-10
lines changed

6 files changed

+63
-10
lines changed

src/libcore/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ pub mod simd;
122122
pub mod slice;
123123
pub mod str;
124124
pub mod tuple;
125+
// FIXME #15320: primitive documentation needs top-level modules, this
126+
// should be `core::tuple::unit`.
127+
#[path = "tuple/unit.rs"]
128+
pub mod unit;
125129
pub mod fmt;
126130

127131
#[doc(hidden)]

src/libcore/tuple.rs renamed to src/libcore/tuple/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
6262
#![doc(primitive = "tuple")]
6363

64+
pub use unit;
65+
6466
use clone::Clone;
6567
use cmp::*;
6668
use default::Default;

src/libcore/tuple/unit.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![doc(primitive = "unit")]
12+
13+
//! The `()` type, sometimes called "unit" or "nil".
14+
//!
15+
//! The `()` type has exactly one value `()`, and is used when there
16+
//! is no other meaningful value that could be returned. `()` is most
17+
//! commonly seen implicitly: functions without a `-> ...` implicitly
18+
//! have return type `()`, that is, these are equivalent:
19+
//!
20+
//! ```rust
21+
//! fn long() -> () {}
22+
//!
23+
//! fn short() {}
24+
//! ```
25+
//!
26+
//! The semicolon `;` can be used to discard the result of an
27+
//! expression at the end of a block, making the expression (and thus
28+
//! the block) evaluate to `()`. For example,
29+
//!
30+
//! ```rust
31+
//! fn returns_i64() -> i64 {
32+
//! 1i64
33+
//! }
34+
//! fn returns_unit() {
35+
//! 1i64;
36+
//! }
37+
//!
38+
//! let is_i64 = {
39+
//! returns_i64()
40+
//! };
41+
//! let is_unit = {
42+
//! returns_i64();
43+
//! };
44+
//! ```

src/librustdoc/clean/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ pub enum Primitive {
10791079
F32, F64,
10801080
Char,
10811081
Bool,
1082-
Nil,
1082+
Unit,
10831083
Str,
10841084
Slice,
10851085
PrimitiveTuple,
@@ -1110,7 +1110,7 @@ impl Primitive {
11101110
"u32" => Some(U32),
11111111
"u64" => Some(U64),
11121112
"bool" => Some(Bool),
1113-
"nil" => Some(Nil),
1113+
"unit" => Some(Unit),
11141114
"char" => Some(Char),
11151115
"str" => Some(Str),
11161116
"f32" => Some(F32),
@@ -1159,15 +1159,15 @@ impl Primitive {
11591159
Str => "str",
11601160
Bool => "bool",
11611161
Char => "char",
1162-
Nil => "()",
1162+
Unit => "()",
11631163
Slice => "slice",
11641164
PrimitiveTuple => "tuple",
11651165
}
11661166
}
11671167

11681168
pub fn to_url_str(&self) -> &'static str {
11691169
match *self {
1170-
Nil => "nil",
1170+
Unit => "unit",
11711171
other => other.to_str(),
11721172
}
11731173
}
@@ -1184,7 +1184,7 @@ impl Clean<Type> for ast::Ty {
11841184
fn clean(&self) -> Type {
11851185
use syntax::ast::*;
11861186
match self.node {
1187-
TyNil => Primitive(Nil),
1187+
TyNil => Primitive(Unit),
11881188
TyPtr(ref m) => RawPointer(m.mutbl.clean(), box m.ty.clean()),
11891189
TyRptr(ref l, ref m) =>
11901190
BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
@@ -1214,7 +1214,7 @@ impl Clean<Type> for ty::t {
12141214
fn clean(&self) -> Type {
12151215
match ty::get(*self).sty {
12161216
ty::ty_bot => Bottom,
1217-
ty::ty_nil => Primitive(Nil),
1217+
ty::ty_nil => Primitive(Unit),
12181218
ty::ty_bool => Primitive(Bool),
12191219
ty::ty_char => Primitive(Char),
12201220
ty::ty_int(ast::TyI) => Primitive(Int),

src/librustdoc/html/format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl fmt::Show for clean::Type {
362362
},
363363
args = decl.decl.inputs,
364364
arrow = match decl.decl.output {
365-
clean::Primitive(clean::Nil) => "".to_string(),
365+
clean::Primitive(clean::Unit) => "".to_string(),
366366
_ => format!(" -&gt; {}", decl.decl.output),
367367
},
368368
bounds = {
@@ -411,7 +411,7 @@ impl fmt::Show for clean::Type {
411411
m.collect::<Vec<String>>().connect(" + "))
412412
},
413413
arrow = match decl.decl.output {
414-
clean::Primitive(clean::Nil) => "".to_string(),
414+
clean::Primitive(clean::Unit) => "".to_string(),
415415
_ => format!(" -&gt; {}", decl.decl.output)
416416
})
417417
}
@@ -472,7 +472,7 @@ impl fmt::Show for clean::FnDecl {
472472
write!(f, "({args}){arrow}",
473473
args = self.inputs,
474474
arrow = match self.output {
475-
clean::Primitive(clean::Nil) => "".to_string(),
475+
clean::Primitive(clean::Unit) => "".to_string(),
476476
_ => format!(" -&gt; {}", self.output),
477477
})
478478
}
@@ -505,7 +505,7 @@ impl<'a> fmt::Show for Method<'a> {
505505
write!(f, "({args}){arrow}",
506506
args = args,
507507
arrow = match d.output {
508-
clean::Primitive(clean::Nil) => "".to_string(),
508+
clean::Primitive(clean::Unit) => "".to_string(),
509509
_ => format!(" -&gt; {}", d.output),
510510
})
511511
}

src/libstd/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ pub use core::ptr;
160160
pub use core::raw;
161161
pub use core::simd;
162162
pub use core::tuple;
163+
// FIXME #15320: primitive documentation needs top-level modules, this
164+
// should be `std::tuple::unit`.
165+
pub use core::unit;
163166
#[cfg(not(test))] pub use core::ty;
164167
pub use core::result;
165168
pub use core::option;

0 commit comments

Comments
 (0)