Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add primitive doc for () #15321

Merged
merged 2 commits into from
Jul 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tuple.rs → src/libcore/tuple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

#![doc(primitive = "tuple")]

pub use unit;

use clone::Clone;
use cmp::*;
use default::Default;
Expand Down
44 changes: 44 additions & 0 deletions src/libcore/tuple/unit.rs
Original file line number Diff line number Diff line change
@@ -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() {}
//! ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention ; too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a paragraph below; what do you think?

//!
//! 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using For example: rather than For example,, I wonder which is better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, don't know.

(It's mainly just a habit I have from mathematics, where even an "broken out" equation is normally written to be a natural part of the sentence it's in

Hence, we've proven that

a + 2 = 3

where a = 1.

This may not be the style we want for Rust's docs.)

//!
//! ```rust
//! fn returns_i64() -> i64 {
//! 1i64
//! }
//! fn returns_unit() {
//! 1i64;
//! }
//!
//! let is_i64 = {
//! returns_i64()
//! };
//! let is_unit = {
//! returns_i64();
//! };
//! ```
12 changes: 6 additions & 6 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ pub enum Primitive {
F32, F64,
Char,
Bool,
Nil,
Unit,
Str,
Slice,
PrimitiveTuple,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1159,15 +1159,15 @@ impl Primitive {
Str => "str",
Bool => "bool",
Char => "char",
Nil => "()",
Unit => "()",
Slice => "slice",
PrimitiveTuple => "tuple",
}
}

pub fn to_url_str(&self) -> &'static str {
match *self {
Nil => "nil",
Unit => "unit",
other => other.to_str(),
}
}
Expand All @@ -1184,7 +1184,7 @@ impl Clean<Type> 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(),
Expand Down Expand Up @@ -1214,7 +1214,7 @@ impl Clean<Type> 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),
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(" -&gt; {}", decl.decl.output),
},
bounds = {
Expand Down Expand Up @@ -411,7 +411,7 @@ impl fmt::Show for clean::Type {
m.collect::<Vec<String>>().connect(" + "))
},
arrow = match decl.decl.output {
clean::Primitive(clean::Nil) => "".to_string(),
clean::Primitive(clean::Unit) => "".to_string(),
_ => format!(" -&gt; {}", decl.decl.output)
})
}
Expand Down Expand Up @@ -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!(" -&gt; {}", self.output),
})
}
Expand Down Expand Up @@ -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!(" -&gt; {}", d.output),
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down