Skip to content

Move attribute and keyword docs from std to core#158327

Open
jschillem wants to merge 4 commits into
rust-lang:mainfrom
jschillem:docs-move-attributes-and-keywords-to-core
Open

Move attribute and keyword docs from std to core#158327
jschillem wants to merge 4 commits into
rust-lang:mainfrom
jschillem:docs-move-attributes-and-keywords-to-core

Conversation

@jschillem

@jschillem jschillem commented Jun 23, 2026

Copy link
Copy Markdown

View all comments

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.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 23, 2026
@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @GuillaumeGomez (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@GuillaumeGomez

Copy link
Copy Markdown
Member

Thanks!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e5d79ed has been approved by GuillaumeGomez

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…-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 rust-lang#157604.

r? @GuillaumeGomez

Verified documentation using:
`./x doc library/core` and `./x doc library/std`, as well as running doc-tests for both crates.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…-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 rust-lang#157604.

r? @GuillaumeGomez

Verified documentation using:
`./x doc library/core` and `./x doc library/std`, as well as running doc-tests for both crates.
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #158389 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 25, 2026
@rust-bors

rust-bors Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#158389), which was unapproved.

View changes since this unapproval

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jun 25, 2026
@jschillem jschillem force-pushed the docs-move-attributes-and-keywords-to-core branch from 2ce02ed to 8230837 Compare June 25, 2026 13:16
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Jun 25, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

@bors try job=test-various

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 25, 2026
…o-core, r=<try>

Move attribute and keyword docs from `std` to `core`


try-job: test-various
@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 25, 2026
@rust-bors

rust-bors Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 6850d53 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@jschillem: 🔑 Insufficient privileges: not in try users

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc PG-exploit-mitigations Project group: Exploit mitigations T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jun 26, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@jschillem jschillem force-pushed the docs-move-attributes-and-keywords-to-core branch from 059494a to 5ebd7f2 Compare June 26, 2026 03:32
@jschillem jschillem force-pushed the docs-move-attributes-and-keywords-to-core branch from 5ebd7f2 to 471fbdf Compare June 26, 2026 03:35
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Error: Label Ameta can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@jschillem

Copy link
Copy Markdown
Author

Sorry about all the extra labels being added and comments! Borked a rebase 😅

@jieyouxu jieyouxu removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. A-meta Area: Issues & PRs about the rust-lang/rust repository itself PG-exploit-mitigations Project group: Exploit mitigations WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) A-CI Area: Our Github Actions CI T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-clippy Relevant to the Clippy team. labels Jun 26, 2026
///
/// Example of using `become` to implement functional-style `fold`:
/// ```
/// ```ignore (explicit_tail_calls not supported on wasm targets)

@RalfJung RalfJung Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a test coverage regression, since it will be ignored on all targets now

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is there a way to ignore a doc test for a specific target?

When these docs were in std, the test did not run for the wasm32-wasip1 target in CI. However in core it does. The log of the failed try run earlier indicated that the explicit_tail_calls feature is not supported for this target.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes:

#[cfg_attr(target_os = "linux", doc = "```")]
#[cfg_attr(not(target_os = "linux"), doc = "```ignore (not supporting  on this target)")]

/// contract that the compiler cannot enforce, documenting it is important. The
/// standard library has many examples of this, like the following which is an
/// extract from [`Vec::set_len`]. The `# Safety` section explains the contract
/// extract from [`ptr::replace`]. The `# Safety` section explains the contract

@RalfJung RalfJung Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer to stick to the original example here -- ptr::replace is a raw pointer method which "feels" quite different from an unsafe method on a typically "safe" type. Also ptr::replace's condition is harder to understand.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree and the goal with changing it was to make the example reference an unsafe method in core instead of std.

I spoke with @GuillaumeGomez about this AlPR. With the move to core, ideally the examples should minimize links to std.

I'll try and find a simpler method in core, and revert if I can't find one.

@RalfJung RalfJung Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we should artificially limit our discussion of things like the unsafe keyword to examples that can be found in core. Instead, we should write the best docs we can write, using examples from any part of the standard library. unsafe is a language keyword, it's not part of any library, it's placement in core vs std is entirely incidental.

Arguably these docs really should be in the Reference, and then obviously they could use examples from std.

Comment thread library/std/src/lib.rs
// Include private modules that exist solely to provide rustdoc
// documentation for built-in attributes. Using `include!` because rustdoc
// only looks for these modules at the crate level.
include!("../../core/src/attribute_docs.rs");

@RalfJung RalfJung Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are these files included both in libcore and libstd? I guess this is to keep existing links like https://doc.rust-lang.org/nightly/std/keyword.unsafe.html working?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This pattern was in place for the primitives docs already.

I spoke with some folks during the lang-docs office hour and the assumption is for visibility. Most people will be looking in the std documentation, however it should likely be in both. Additionally yes to avoid breaking existing links.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When you are in the std docs, you have access to core in any case, so no need to make them appear in both core and std.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This pattern was in place for the primitives docs already.

Yeah I saw that.

Still, would be good to add a brief comment explaining it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Including in both was already set for primitive_docs.rs. I'm assuming this was added for just visibility reasons. But removing attributes and keywords from also being included in std, should I leave primitive_docs.rs included?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That will mean that looking for fn or any other items will show two items in the search results. Not great.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thinking out loud, infra team can likely add redirections for these items.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That will mean that looking for fn or any other items will show two items in the search results. Not great.

Would it? We don't get duplicates for e.g. bool currently.

@jschillem jschillem Jun 26, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I believe it's only searching in the crate you're in currently. So if if the includes are removed from std, these docs will not be searchable. The user would have to explicitly go to core to find them.

So I don't believe it's show up twice. If anything removing from std would reduce overall visibility as most people are already searching within std.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it? We don't get duplicates for e.g. bool currently.

Ah indeed. That is... surprising. Oh well, if it works let's use it then. =D

@rust-bors

rust-bors Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #158455) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants