Skip to content

Commit 7f2574f

Browse files
committed
Move attribute and keyword docs from std to core
* refactor: move attribute and keywords docs files to core * fix references to `std` * tidy fixes * ignore doc tests w/ explicit_tail_calls * revert `unsafe` example and ignore specifically WASM for `become` doc tests * add explicit note about doube including the docs in `core` and `std` * missed refactoring of doc test ignore * conditionally exclude doc-test containing threading for `wasm-wasip1` * Change exclusion to just `wasi` target_os Co-authored-by: Justin Schilleman <97192655+jschillem@users.noreply.github.com>
1 parent cb41b6d commit 7f2574f

4 files changed

Lines changed: 53 additions & 40 deletions

File tree

Lines changed: 28 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};
1239+
/// fn main() -> Result<(), &'static str> {
1240+
/// let contents = "Hello, world!";
12401241
///
1241-
/// fn main() -> Result<()> {
1242-
/// let mut file = match File::open("foo.txt") {
1243-
/// Ok(f) => f,
1244-
/// Err(e) => return Err(e),
1245-
/// };
1242+
/// if contents.contains("impossible!") {
1243+
/// return Err("oh no!");
1244+
/// }
12461245
///
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-
/// };
1252-
///
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,11 @@ mod return_keyword {}
13061294
/// manner to computed goto).
13071295
///
13081296
/// Example of using `become` to implement functional-style `fold`:
1309-
/// ```
1297+
#[cfg_attr(
1298+
target_family = "wasm",
1299+
doc = "```ignore (tail-call target feature not enabled by default on wasm)"
1300+
)]
1301+
#[cfg_attr(not(target_family = "wasm"), doc = "```")]
13101302
/// #![feature(explicit_tail_calls)]
13111303
/// #![expect(incomplete_features)]
13121304
///
@@ -1360,7 +1352,11 @@ mod return_keyword {}
13601352
/// (unless it's coerced to a function pointer)
13611353
///
13621354
/// It is possible to tail-call a function pointer:
1363-
/// ```
1355+
#[cfg_attr(
1356+
target_family = "wasm",
1357+
doc = "```ignore (tail-call target feature not enabled by default on wasm)"
1358+
)]
1359+
#[cfg_attr(not(target_family = "wasm"), doc = "```")]
13641360
/// #![feature(explicit_tail_calls)]
13651361
/// #![expect(incomplete_features)]
13661362
///
@@ -1631,8 +1627,8 @@ mod self_upper_keyword {}
16311627
/// [`extern`]: keyword.extern.html
16321628
/// [`mut`]: keyword.mut.html
16331629
/// [`unsafe`]: keyword.unsafe.html
1634-
/// [`Mutex`]: sync::Mutex
1635-
/// [`OnceLock`]: sync::OnceLock
1630+
/// [`Mutex`]: ../std/sync/struct.Mutex.html
1631+
/// [`OnceLock`]: ../std/sync/struct.OnceLock.html
16361632
/// [`RefCell`]: cell::RefCell
16371633
/// [atomic]: sync::atomic
16381634
/// [Reference]: ../reference/items/static-items.html
@@ -1959,7 +1955,7 @@ mod trait_keyword {}
19591955

19601956
#[doc(keyword = "true")]
19611957
//
1962-
/// A value of type [`bool`] representing logical **true**.
1958+
/// A value of type [`prim@bool`] representing logical **true**.
19631959
///
19641960
/// Logically `true` is not equal to [`false`].
19651961
///
@@ -2312,6 +2308,7 @@ mod type_keyword {}
23122308
/// [`static`]: keyword.static.html
23132309
/// [`union`]: keyword.union.html
23142310
/// [`impl`]: keyword.impl.html
2311+
/// [`Vec::set_len`]: ../std/vec/struct.Vec.html#method.set_len
23152312
/// [raw pointers]: ../reference/types/pointer.html
23162313
/// [memory safety]: ../book/ch19-01-unsafe-rust.html
23172314
/// [Rustonomicon]: ../nomicon/index.html
@@ -2502,7 +2499,7 @@ mod use_keyword {}
25022499
/// ```
25032500
///
25042501
/// `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
2502+
/// as can be seen with the [`Cow`](../std/borrow/enum.Cow.html) type from the standard
25062503
/// library:
25072504
///
25082505
/// ```rust

library/core/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,17 @@ pub mod simd {
397397
pub use crate::core_simd::simd::*;
398398
}
399399

400+
// Include private modules that exist solely to provide rustdoc
401+
// documentation for built-in attributes. Using `include!` because rustdoc
402+
// only looks for these modules at the crate level.
403+
include!("attribute_docs.rs");
404+
405+
// Include a number of private modules that exist solely to provide
406+
// the rustdoc documentation for the existing keywords. Using `include!`
407+
// because rustdoc only looks for these modules at the crate level.
408+
include!("keyword_docs.rs");
409+
410+
// Include a number of private modules that exist solely to provide
411+
// the rustdoc documentation for primitive types. Using `include!`
412+
// because rustdoc only looks for these modules at the crate level.
400413
include!("primitive_docs.rs");

library/std/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,20 +778,23 @@ pub mod from {
778778
pub use core::from::From;
779779
}
780780

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

786789
// Include a number of private modules that exist solely to provide
787790
// the rustdoc documentation for the existing keywords. Using `include!`
788791
// because rustdoc only looks for these modules at the crate level.
789-
include!("keyword_docs.rs");
792+
include!("../../core/src/keyword_docs.rs");
790793

791-
// Include private modules that exist solely to provide rustdoc
792-
// documentation for built-in attributes. Using `include!` because rustdoc
793-
// only looks for these modules at the crate level.
794-
include!("attribute_docs.rs");
794+
// Include a number of private modules that exist solely to provide
795+
// the rustdoc documentation for primitive types. Using `include!`
796+
// because rustdoc only looks for these modules at the crate level.
797+
include!("../../core/src/primitive_docs.rs");
795798

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

0 commit comments

Comments
 (0)