-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
rustdoc: add --print option
#151618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
rustdoc: add --print option
#151618
Conversation
|
r? @notriddle rustbot has assigned @notriddle. Use |
This comment has been minimized.
This comment has been minimized.
|
I could indeed see the |
| return; | ||
| } | ||
|
|
||
| if rustc_driver::print_crate_info(&*compiler.codegen_backend, sess, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: IINM, this won't be run if the input file is *.md or if --test is passed. Not sure what the consequences of that are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, --print=crate-name doesn't really make sense for *.md inputs I feel like?
src/librustdoc/config.rs
Outdated
| } | ||
| }; | ||
|
|
||
| let prints = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sense that there are certain rustc print requests which I don't think rustdoc can support.
E.g., I'm curious what will happen if you pass --print=link-args to rustdoc under your PR. Contrary to most other rustc print request that make rustc stop compilation early, link-args actually requires full analysis+codegen IINM … which rustdoc obv doesn't do. I guess it just doesn't print anything?
If so, that would be an example of a rustc print request that shouldn't be a legal rustdoc one.
There's also --print=native-static-libs that seems to require sth. similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g., I'm curious what will happen if you pass --print=link-args to rustdoc under your PR. Contrary to most other rustc print request that make rustc stop compilation early, link-args actually requires full analysis+codegen IINM … which rustdoc obv doesn't do. I guess it just doesn't print anything?
Yup, print_crate_info is a no-op for them as it's codegen_ssa that print them, and since the codegen isn't called, they don't print anything.
I'll filter the prints depending on if they make sense depending on the file type (.rs / .md / both) and action (doc / doctest / any).
I'd like to @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
| (option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE") | ||
| env!("CFG_COMPILER_HOST_TRIPLE") |
There was a problem hiding this comment.
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)
Context:
--print crate-root-lint-levels(#139180) is only available forrustcandclippy-driver, while it would make sense for it to also be available forrustdoc(à la #83895.)Not too sure about the stability of
rustdoc --print=anyor if this needs a MCP; strictly speaking, onlyrustdoc +nightly -Z unstable-options --print=crate-root-lint-levelswould be required (and therustdoc --printwould be stabilized together withcrate-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()andrustdoc()(or just testrustdocas it delegates torustc):rust/tests/run-make/print-crate-root-lint-levels/rmake.rs
Lines 82 to 88 in 021fc25
@rustbot label +A-CLI +A-print-requests