Skip to content

rustdoc: add --print option - #151618

Merged
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
ShE3py:rustdoc-print
Sep 1, 2026
Merged

rustdoc: add --print option#151618
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
ShE3py:rustdoc-print

Conversation

@ShE3py

@ShE3py ShE3py commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

View all comments

Context: --print crate-root-lint-levels (#139180) is only available for rustc and clippy-driver, while it would make sense for it to also be available for rustdoc (à la #83895.)

Not too sure about the stability of rustdoc --print=any or if this needs a MCP; strictly speaking, only rustdoc +nightly -Z unstable-options --print=crate-root-lint-levels would be required (and the rustdoc --print would be stabilized together with crate-root-lint-levels), but I guess that makes sense to have all the --prints for consistency.

For regression tests, not sure if ui or run-make is preferable, as run-make would need some sort of trait to avoid duplicating code between rustc() and rustdoc() (or just test rustdoc as it delegates to rustc):

fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) {
let output = rustc()
.input("lib.rs")
.arg("-Zunstable-options")
.print("crate-root-lint-levels")
.args(args)
.run();

@rustbot label +A-CLI +A-print-requests

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

rustbot commented Jan 24, 2026

Copy link
Copy Markdown
Collaborator

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-CLI Area: Command-line interface (CLI) to the compiler A-print-requests Area: print requests (`--print=...`) labels Jan 24, 2026
@rust-log-analyzer

This comment has been minimized.

@Urgau

Urgau commented Jan 24, 2026

Copy link
Copy Markdown
Member

I could indeed see the --print being useful in rustdoc, but I'm still a bit curious what your use-case.
Would you be able describe it?

Comment thread src/librustdoc/lib.rs Outdated
Comment thread src/librustdoc/lib.rs
Comment thread src/librustdoc/config.rs Outdated
@ShE3py

ShE3py commented Jan 25, 2026

Copy link
Copy Markdown
Contributor Author

I could indeed see the --print being useful in rustdoc, but I'm still a bit curious what your use-case. Would you be able describe it?

I'd like to diff the default lint-levels of two Rust versions in order to simplify updating the lints when I come back after a while (e.g. remove -W foo if foo was promoted to warn-by-default).

@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 25, 2026
@rustbot

rustbot commented Jan 25, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jan 28, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_session/src/config.rs Outdated
Comment on lines +1376 to +1375
(option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE")
env!("CFG_COMPILER_HOST_TRIPLE")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was changed from env! to option_env! in the first commit of #13724, but not sure why this change was made or if it's still relevant as CI is green.

(Was looking looking for a #[expect] reason as removing the extra parentheses triggers deny-by-default clippy::option_env_unwrap)

@rust-bors

This comment has been minimized.

@Urgau

Urgau commented Jul 25, 2026

Copy link
Copy Markdown
Member

@ShE3py still interested in driving this PR forward?

@ShE3py

ShE3py commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Yup, prolly next month when I have time.

@rustbot

rustbot commented Aug 30, 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.

Comment thread src/librustdoc/doctest.rs
Comment on lines +223 to +227
// -W help
if sess.opts.describe_lints {
rustc_driver::describe_lints(sess, registered_lints);
return Ok(None);
}

@ShE3py ShE3py Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixes -W help when running doctests:

$ rustdoc +nightly -Whelp --test /dev/null 
error: couldn't find file ``

View changes since the review

@ShE3py ShE3py Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copied from tests/run-make/print-crate-root-lint-levels/, replaced unexpected_cfgs with rustdoc::private_doc_tests.

View changes since the review

@ShE3py

ShE3py commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

I have grouped the --print=options into four groups: crate, target, codegen and linker. Only the first two groups makes sense for Rustdoc imo.

I can somewhat far-fetch someone using rustdoc --print=host-tuple, but it might be better to initially restricts the print set to actual use cases, and then add more as people request them, e.g. not trying to make it as big as possible right from the start?

For Markdown files and doctests, --print would probably mean having one entry per ```code block```, at least for the crate group. Could be made in a follow-up PR, for now I flat out error.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 30, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
rustdoc: add `--print` option


try-job: test-various
try-job: x86_64-msvc-*
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 8facfe3 failed: CI. Failed job:

@ShE3py

ShE3py commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

AUX is a reserved name in MS-DOS ;)

Added ignore directives based on another doctest test:

// Some targets (for example wasm) cannot execute doctests directly even with a runner,
// so only exercise the success path when the target can run on the host.
if target().contains("wasm")
|| target().contains("sgx")
|| target().contains("pauthtest")
|| std::env::var_os("REMOTE_TEST_CLIENT").is_some()
{
return;
}

@bors try jobs=test-various,armhf-gnu

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 1, 2026
rustdoc: add `--print` option


try-job: test-various
try-job: armhf-gnu
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 6508b6f failed: CI. Failed job:

@ShE3py

This comment was marked as outdated.

@rust-bors

rust-bors Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Unknown argument "armhf-gnu". Did you mean to use @bors jobs=<jobs>|parent=<parent>? Run @bors help or go to https://bors.rust-lang.org/help to see available commands.

@ShE3py

ShE3py commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@bors try jobs=armhf-gnu

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 1, 2026
rustdoc: add `--print` option


try-job: armhf-gnu
@rust-bors

rust-bors Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 82dc2e7 (82dc2e751b36ffa49fa36ba039a665ee362563b7)
Base parent: 7022271 (70222712809cd5cc1718ed8995914a1cbacb6b92)

@ShE3py

ShE3py commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@bors r=notriddle

@rust-bors

rust-bors Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bf27a5a has been approved by notriddle

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
rustdoc: add `--print` option

Context: `--print crate-root-lint-levels` (rust-lang#139180) is only available for `rustc` and `clippy-driver`, while it would make sense for it to also be available for `rustdoc` (à la rust-lang#83895.)

Not too sure about the stability of `rustdoc --print=any` or if this needs a MCP; strictly speaking, only `rustdoc +nightly -Z unstable-options --print=crate-root-lint-levels` would be required (and the `rustdoc --print` would be stabilized together with `crate-root-lint-levels`), but I guess that makes sense to have all the `--print`s for consistency.

For regression tests, not sure if ui or run-make is preferable, as run-make would need some sort of trait to avoid duplicating code between `rustc()` and `rustdoc()` (or just test `rustdoc` as it delegates to `rustc`):
https://github.com/rust-lang/rust/blob/021fc25b7a48f6051bee1e1f06c7a277e4de1cc9/tests/run-make/print-crate-root-lint-levels/rmake.rs#L82-L88

@rustbot label +A-CLI +A-print-requests
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 1, 2026
rustdoc: add `--print` option

Context: `--print crate-root-lint-levels` (rust-lang#139180) is only available for `rustc` and `clippy-driver`, while it would make sense for it to also be available for `rustdoc` (à la rust-lang#83895.)

Not too sure about the stability of `rustdoc --print=any` or if this needs a MCP; strictly speaking, only `rustdoc +nightly -Z unstable-options --print=crate-root-lint-levels` would be required (and the `rustdoc --print` would be stabilized together with `crate-root-lint-levels`), but I guess that makes sense to have all the `--print`s for consistency.

For regression tests, not sure if ui or run-make is preferable, as run-make would need some sort of trait to avoid duplicating code between `rustc()` and `rustdoc()` (or just test `rustdoc` as it delegates to `rustc`):
https://github.com/rust-lang/rust/blob/021fc25b7a48f6051bee1e1f06c7a277e4de1cc9/tests/run-make/print-crate-root-lint-levels/rmake.rs#L82-L88

@rustbot label +A-CLI +A-print-requests
rust-bors Bot pushed a commit that referenced this pull request Sep 1, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #151618 (rustdoc: add `--print` option)
 - #161287 (Update `icu_list` dependency to 2.3)
 - #161767 (change DEFAULT_STACK_SIZE to be 32MB on s390x)
 - #161968 (Diverse offload fixes)
 - #161971 (Remove -Zsaturating-float-casts flag)
 - #162071 (Fix ICE of getting item name from RPITIT)
 - #161209 (Rework `next_power_of_two` to always be `1 << …`)
 - #162073 (Change some `Infallible` to `!` in std)
 - #162086 (Remove `gate_check` from `AttributeStability::Unstable`)
 - #162102 (`alloc` crate: shrink undocumented `unsafe` blocks)
 - #162110 (make it clear that Range cannot represent arbitrary ranges)
@rust-bors
rust-bors Bot merged commit 549f475 into rust-lang:main Sep 1, 2026
14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 1, 2026
Rollup merge of #151618 - ShE3py:rustdoc-print, r=notriddle

rustdoc: add `--print` option

Context: `--print crate-root-lint-levels` (#139180) is only available for `rustc` and `clippy-driver`, while it would make sense for it to also be available for `rustdoc` (à la #83895.)

Not too sure about the stability of `rustdoc --print=any` or if this needs a MCP; strictly speaking, only `rustdoc +nightly -Z unstable-options --print=crate-root-lint-levels` would be required (and the `rustdoc --print` would be stabilized together with `crate-root-lint-levels`), but I guess that makes sense to have all the `--print`s for consistency.

For regression tests, not sure if ui or run-make is preferable, as run-make would need some sort of trait to avoid duplicating code between `rustc()` and `rustdoc()` (or just test `rustdoc` as it delegates to `rustc`):
https://github.com/rust-lang/rust/blob/021fc25b7a48f6051bee1e1f06c7a277e4de1cc9/tests/run-make/print-crate-root-lint-levels/rmake.rs#L82-L88

@rustbot label +A-CLI +A-print-requests
@rustbot rustbot added this to the 1.100.0 milestone Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: Command-line interface (CLI) to the compiler A-print-requests Area: print requests (`--print=...`) A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc 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