about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-06-27 18:33:15 +0200
committerAlexis Bourget <alexis.bourget@gmail.com>2020-06-27 18:34:34 +0200
commit3fc5593ea80819f940f6edef3108d15ef2ad7956 (patch)
tree7cdbc94752f71a665d9e5503064c36798980c642 /src/libstd
parent394e1b40d264aa6928811919c1124fa248e7d802 (diff)
downloadrust-3fc5593ea80819f940f6edef3108d15ef2ad7956.tar.gz
rust-3fc5593ea80819f940f6edef3108d15ef2ad7956.zip
Document the type keyword
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/keyword_docs.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs
index d972cf6db18..3b493c4244d 100644
--- a/src/libstd/keyword_docs.rs
+++ b/src/libstd/keyword_docs.rs
@@ -1463,9 +1463,33 @@ mod true_keyword {}
 //
 /// Define an alias for an existing type.
 ///
-/// The documentation for this keyword is [not yet complete]. Pull requests welcome!
+/// The syntax is `type Name = ExistingType;`.
 ///
-/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
+/// # Examples
+///
+/// `type` does **not** create a new type:
+///
+/// ```rust
+/// type Meters = u32;
+/// type Kilograms = u32;
+///
+/// let m: Meters = 3;
+/// let k: Kilograms = 3;
+///
+/// assert_eq!(m, k);
+/// ```
+///
+/// In traits, using `type` allows the usage of an associated type without
+/// knowing about it when declaring the [`trait`]:
+///
+/// ```rust
+/// trait Iterator {
+///     type Item;
+///     fn next(&mut self) -> Option<Self::Item>;
+/// }
+/// ```
+///
+/// [`trait`]: keyword.trait.html
 mod type_keyword {}
 
 #[doc(keyword = "unsafe")]