Skip to content

Commit dab9ecf

Browse files
Rollup merge of #158327 - jschillem:docs-move-attributes-and-keywords-to-core, r=GuillaumeGomez
Move attribute and keyword docs from `std` to `core` Move the documentation for attributes and keywords into the `core` crate. Apart from strictly moving the module, I had to make a few small changes to certain docs to avoid using `std` types when possible, as well as fixing a few suggestions related to linking to primitives. Pre-requisite for work on #157604. r? @GuillaumeGomez Verified documentation using: `./x doc library/core` and `./x doc library/std`, as well as running doc-tests for both crates.
2 parents 86eb76f + cca8cd1 commit dab9ecf

4 files changed

Lines changed: 47 additions & 40 deletions

File tree

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ mod break_keyword {}
195195
/// to be most things that would be reasonable to have in a constant (barring `const fn`s). For
196196
/// example, you can't have a [`File`] as a `const`.
197197
///
198-
/// [`File`]: crate::fs::File
198+
/// [`File`]: ../std/fs/struct.File.html
199199
///
200200
/// The only lifetime allowed in a constant is `'static`, which is the lifetime that encompasses
201201
/// all others in a Rust program. For example, if you wanted to define a constant string, it would
@@ -484,7 +484,7 @@ mod extern_keyword {}
484484

485485
#[doc(keyword = "false")]
486486
//
487-
/// A value of type [`bool`] representing logical **false**.
487+
/// A value of type [`prim@bool`] representing logical **false**.
488488
///
489489
/// `false` is the logical opposite of [`true`].
490490
///
@@ -1060,7 +1060,8 @@ mod mod_keyword {}
10601060
///
10611061
/// `move` is often used when [threads] are involved.
10621062
///
1063-
/// ```rust
1063+
#[cfg_attr(target_os = "wasi", doc = "```rust,ignore (thread::spawn not supported)")]
1064+
#[cfg_attr(not(target_os = "wasi"), doc = "```rust")]
10641065
/// let data = vec![1, 2, 3];
10651066
///
10661067
/// std::thread::spawn(move || {
@@ -1235,31 +1236,18 @@ mod ref_keyword {}
12351236
/// `return` returns from the function immediately (an "early return"):
12361237
///
12371238
/// ```no_run
1238-
/// use std::fs::File;
1239-
/// use std::io::{Error, ErrorKind, Read, Result};
1240-
///
1241-
/// fn main() -> Result<()> {
1242-
/// let mut file = match File::open("foo.txt") {
1243-
/// Ok(f) => f,
1244-
/// Err(e) => return Err(e),
1245-
/// };
1239+
/// fn main() -> Result<(), &'static str> {
1240+
/// let contents = "Hello, world!";
12461241
///
1247-
/// let mut contents = String::new();
1248-
/// let size = match file.read_to_string(&mut contents) {
1249-
/// Ok(s) => s,
1250-
/// Err(e) => return Err(e),
1251-
/// };
1242+
/// if contents.contains("impossible!") {
1243+
/// return Err("oh no!");
1244+
/// }
12521245
///
1253-
/// if contents.contains("impossible!") {
1254-
/// return Err(Error::new(ErrorKind::Other, "oh no!"));
1255-
/// }
1246+
/// if contents.len() > 9000 {
1247+
/// return Err("over 9000!");
1248+
/// }
12561249
///
1257-
/// if size > 9000 {
1258-
/// return Err(Error::new(ErrorKind::Other, "over 9000!"));
1259-
/// }
1260-
///
1261-
/// assert_eq!(contents, "Hello, world!");
1262-
/// Ok(())
1250+
/// Ok(())
12631251
/// }
12641252
/// ```
12651253
///
@@ -1306,7 +1294,8 @@ mod return_keyword {}
13061294
/// manner to computed goto).
13071295
///
13081296
/// Example of using `become` to implement functional-style `fold`:
1309-
/// ```
1297+
///
1298+
/// ```ignore-wasm (tail-call target feature not enabled by default on wasm)
13101299
/// #![feature(explicit_tail_calls)]
13111300
/// #![expect(incomplete_features)]
13121301
///
@@ -1360,7 +1349,8 @@ mod return_keyword {}
13601349
/// (unless it's coerced to a function pointer)
13611350
///
13621351
/// It is possible to tail-call a function pointer:
1363-
/// ```
1352+
///
1353+
/// ```ignore-wasm (tail-call target feature not enabled by default on wasm)
13641354
/// #![feature(explicit_tail_calls)]
13651355
/// #![expect(incomplete_features)]
13661356
///
@@ -1631,8 +1621,8 @@ mod self_upper_keyword {}
16311621
/// [`extern`]: keyword.extern.html
16321622
/// [`mut`]: keyword.mut.html
16331623
/// [`unsafe`]: keyword.unsafe.html
1634-
/// [`Mutex`]: sync::Mutex
1635-
/// [`OnceLock`]: sync::OnceLock
1624+
/// [`Mutex`]: ../std/sync/struct.Mutex.html
1625+
/// [`OnceLock`]: ../std/sync/struct.OnceLock.html
16361626
/// [`RefCell`]: cell::RefCell
16371627
/// [atomic]: sync::atomic
16381628
/// [Reference]: ../reference/items/static-items.html
@@ -1959,7 +1949,7 @@ mod trait_keyword {}
19591949

19601950
#[doc(keyword = "true")]
19611951
//
1962-
/// A value of type [`bool`] representing logical **true**.
1952+
/// A value of type [`prim@bool`] representing logical **true**.
19631953
///
19641954
/// Logically `true` is not equal to [`false`].
19651955
///
@@ -2312,6 +2302,7 @@ mod type_keyword {}
23122302
/// [`static`]: keyword.static.html
23132303
/// [`union`]: keyword.union.html
23142304
/// [`impl`]: keyword.impl.html
2305+
/// [`Vec::set_len`]: ../std/vec/struct.Vec.html#method.set_len
23152306
/// [raw pointers]: ../reference/types/pointer.html
23162307
/// [memory safety]: ../book/ch19-01-unsafe-rust.html
23172308
/// [Rustonomicon]: ../nomicon/index.html
@@ -2502,7 +2493,7 @@ mod use_keyword {}
25022493
/// ```
25032494
///
25042495
/// `where` is available anywhere generic and lifetime parameters are available,
2505-
/// as can be seen with the [`Cow`](crate::borrow::Cow) type from the standard
2496+
/// as can be seen with the [`Cow`](../std/borrow/enum.Cow.html) type from the standard
25062497
/// library:
25072498
///
25082499
/// ```rust

library/core/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,17 @@ pub mod simd {
386386
pub use crate::core_simd::simd::*;
387387
}
388388

389+
// Include private modules that exist solely to provide rustdoc
390+
// documentation for built-in attributes. Using `include!` because rustdoc
391+
// only looks for these modules at the crate level.
392+
include!("attribute_docs.rs");
393+
394+
// Include a number of private modules that exist solely to provide
395+
// the rustdoc documentation for the existing keywords. Using `include!`
396+
// because rustdoc only looks for these modules at the crate level.
397+
include!("keyword_docs.rs");
398+
399+
// Include a number of private modules that exist solely to provide
400+
// the rustdoc documentation for primitive types. Using `include!`
401+
// because rustdoc only looks for these modules at the crate level.
389402
include!("primitive_docs.rs");

library/std/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -772,20 +772,23 @@ pub mod from {
772772
pub use core::from::From;
773773
}
774774

775-
// Include a number of private modules that exist solely to provide
776-
// the rustdoc documentation for primitive types. Using `include!`
777-
// because rustdoc only looks for these modules at the crate level.
778-
include!("../../core/src/primitive_docs.rs");
775+
// We include the following files here *again* (they are already included in libcore)
776+
// so that they show up in search results for the std crate, and to avoid breaking
777+
// existing links:
778+
779+
// documentation for built-in attributes. Using `include!` because rustdoc
780+
// only looks for these modules at the crate level.
781+
include!("../../core/src/attribute_docs.rs");
779782

780783
// Include a number of private modules that exist solely to provide
781784
// the rustdoc documentation for the existing keywords. Using `include!`
782785
// because rustdoc only looks for these modules at the crate level.
783-
include!("keyword_docs.rs");
786+
include!("../../core/src/keyword_docs.rs");
784787

785-
// Include private modules that exist solely to provide rustdoc
786-
// documentation for built-in attributes. Using `include!` because rustdoc
787-
// only looks for these modules at the crate level.
788-
include!("attribute_docs.rs");
788+
// Include a number of private modules that exist solely to provide
789+
// the rustdoc documentation for primitive types. Using `include!`
790+
// because rustdoc only looks for these modules at the crate level.
791+
include!("../../core/src/primitive_docs.rs");
789792

790793
// This is required to avoid an unstable error when `restricted-std` is not
791794
// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std

0 commit comments

Comments
 (0)