Skip to content

Commit f8d6261

Browse files
committed
Add docs for crate keyword
I think it might be used in some other things, but I'm not fluent enough at sifting through the rust compiler's source code to find every use of a specific keyword. This leaves the question of how to document the `extern` keyword, what with how much overlap it has with `crate`, but that's used with ABI stuff so that should be fine.
1 parent 6cbcfa2 commit f8d6261

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/libstd/keyword_docs.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,40 @@ mod as_keyword { }
9090
/// [Reference]: https://doc.rust-lang.org/reference/items/constant-items.html
9191
mod const_keyword { }
9292

93+
#[doc(keyword = "crate")]
94+
//
95+
/// The `crate` keyword.
96+
///
97+
/// The primary use of the `crate` keyword is as a part of `extern crate` declarations, which are
98+
/// used to specify a dependency on a crate external to the one it's declared in. Crates are the
99+
/// fundamental compilation unit of Rust code, and can be seen as libraries or projects. More can
100+
/// be read about crates in the [Reference].
101+
///
102+
/// ```rust ignore
103+
/// extern crate rand;
104+
/// extern crate my_crate as thing;
105+
/// extern crate std; // implicitly added to the root of every Rust project
106+
/// ```
107+
///
108+
/// The `as` keyword can be used to change what the crate is referred to as in your project. If a
109+
/// crate name includes a dash, it is implicitly imported with the dashes replaced by underscores.
110+
///
111+
/// `crate` is also used as in conjunction with [`pub`] to signify that the item it's attached to
112+
/// is public only to other members of the same crate it's in.
113+
///
114+
/// ```rust
115+
/// # #[allow(unused_imports)]
116+
/// pub(crate) use std::io::Error as IoError;
117+
/// pub(crate) enum CoolMarkerType { }
118+
/// pub struct PublicThing {
119+
/// pub(crate) semi_secret_thing: bool,
120+
/// }
121+
/// ```
122+
///
123+
/// [Reference]: https://doc.rust-lang.org/reference/items/extern-crates.html
124+
/// [`pub`]: keyword.pub.html
125+
mod crate_keyword { }
126+
93127
#[doc(keyword = "fn")]
94128
//
95129
/// The `fn` keyword.

0 commit comments

Comments
 (0)