rustdoc: Reify emission types#155679
Conversation
| dcx.fatal(format!("unrecognized emission type: {typ}")) | ||
| }; | ||
|
|
||
| match typ { |
There was a problem hiding this comment.
A match (output_format, typ) { … } / match (typ, output_format) { … } looked less legible in my eyes esp. due to rustfmt's decisions.
| // If `--emit` is absent we'll register default emission types depending on the requested | ||
| // output format. We can safely use `is_empty` for this since `--emit=` ("truly empty") | ||
| // will have already been rejected above. | ||
| if emit.is_empty() { |
There was a problem hiding this comment.
Alternatively, I could change the earlier emit from FxIndexMap to Option<FxIndexMap> to avoid conflating Some([]) with None which would be more robust and future-proof but slightly more annoying to construct.
| if let OutputFormat::Doctest = output_format { | ||
| dcx.fatal("the `--emit` flag is not supported with `--output-format=doctest`"); | ||
| } |
There was a problem hiding this comment.
If you do like this PR I'll of course add a test for this.
| "the `--emit={emit_flag}` flag is not supported with `--output-format=json`", | ||
| )); | ||
| let mut emit = FxIndexMap::default(); | ||
| for list in matches.opt_strs("emit") { |
There was a problem hiding this comment.
Unrelated and already brought up in the stabilization PR, I'm more and more leaning towards fully ditching -w, --output-format in favor of --emit because the current setup makes my head spin (the loose proposal to repurpose--output and the one to add --print doesn't help ^^).
--emit=json-files and --emit=doctests could be wonderful. Of course, we probably want to make some emission types mutually exclusive then … which might not be in line with its "spirit" but oh well
There was a problem hiding this comment.
Of course, we probably want to make some emission types mutually exclusive then
This doesn't seem obvious to me. I know there are several barriers that prevent rustdoc from emitting json and html at the same time:
- The output format changes the resulting Clean AST, because HTML is inlined and JSON isn't.
- Constructing
clean::CratemutatesDocContext, so we can't just construct Clean twice. - You'll want to be able to specify a different output location for the JSON than for the HTML.
- Some cleaning-related processes produce warnings, and we don't want duplicates.
If either of those first two barriers were fixed, wouldn't --emit=html-static-files,html-non-static-files,json-file=./target/doc-json/CRATENAME.json make sense?
There was a problem hiding this comment.
I guess it would indeed make sense if it's feasible to fix these issues 👍.
Let me change my statement to the following then: "If we were to introduce --emit=json-files and ditch -wjson, we would want to make the html-* emission types incompatible with json-files for the time being until we have figured out how to make them compatible implementation-wise".
In any case, this topic isn't strictly related to this PR which is a mere internal refactoring plus a fix for an unstable feature (-wdoctest) and shouldn't block it in the slightest :)
|
What do you think of this PR itself? Irrespective of potential future plans for |
|
Other than the lack of tests, this seems okay. If nobody else has a problem, and if tests are added, I’d be happy to merge this. |
b5f0ae7 to
4d8ebc9
Compare
|
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. |
|
Test added. |
4d8ebc9 to
ef282ff
Compare
|
@bors r+ |
…s, r=notriddle rustdoc: Reify emission types Implements rust-lang#155374 (comment): Instead of maintaining the hidden assumption or invariant that `opts.emit.is_empty()` actually means "emit default artifacts" (i.e., `[HtmlStaticFiles, HtmlNonStaticFiles]` under output format `html`; "`[???]`" under output format `json`), actually *reify* the list of emission types so the rest of the code doesn't need to keep this in mind. I'm not sure if you like this. It's a tinge overengineered, maybe, but it's more robust I claim. This PR also rejects `--emit` when `--output-format doctest -Zunstable-options` is passed since the latter doesn't honor emission types at all (yet).
Rollup of 6 pull requests Successful merges: - #153975 (remove forever-deprecated and hidden `f64` methods) - #155679 (rustdoc: Reify emission types) - #155982 (Fix closure HIR span context mismatch) - #156323 (Handle --print=backend-has-mnemonic in cg_clif) - #156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`) - #156365 (stream_send_recv_stress tests: wait for threads to finish)
|
⌛ Testing commit ef282ff with merge 9788718... Workflow: https://github.com/rust-lang/rust/actions/runs/25630769060 |
rustdoc: Reify emission types Implements #155374 (comment): Instead of maintaining the hidden assumption or invariant that `opts.emit.is_empty()` actually means "emit default artifacts" (i.e., `[HtmlStaticFiles, HtmlNonStaticFiles]` under output format `html`; "`[???]`" under output format `json`), actually *reify* the list of emission types so the rest of the code doesn't need to keep this in mind. I'm not sure if you like this. It's a tinge overengineered, maybe, but it's more robust I claim. This PR also rejects `--emit` when `--output-format doctest -Zunstable-options` is passed since the latter doesn't honor emission types at all (yet).
…s, r=notriddle rustdoc: Reify emission types Implements rust-lang#155374 (comment): Instead of maintaining the hidden assumption or invariant that `opts.emit.is_empty()` actually means "emit default artifacts" (i.e., `[HtmlStaticFiles, HtmlNonStaticFiles]` under output format `html`; "`[???]`" under output format `json`), actually *reify* the list of emission types so the rest of the code doesn't need to keep this in mind. I'm not sure if you like this. It's a tinge overengineered, maybe, but it's more robust I claim. This PR also rejects `--emit` when `--output-format doctest -Zunstable-options` is passed since the latter doesn't honor emission types at all (yet).
|
@bors yield |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #156397. |
…uwer Rollup of 6 pull requests Successful merges: - #155679 (rustdoc: Reify emission types) - #155982 (Fix closure HIR span context mismatch) - #156323 (Handle --print=backend-has-mnemonic in cg_clif) - #156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`) - #156365 (stream_send_recv_stress tests: wait for threads to finish) - #156368 (Fix invalid unreachable in is_known_valid_scrutinee for Reborrow)
|
⌛ Testing commit ef282ff with merge 8f1bc40... Workflow: https://github.com/rust-lang/rust/actions/runs/25632375858 |
rustdoc: Reify emission types Implements #155374 (comment): Instead of maintaining the hidden assumption or invariant that `opts.emit.is_empty()` actually means "emit default artifacts" (i.e., `[HtmlStaticFiles, HtmlNonStaticFiles]` under output format `html`; "`[???]`" under output format `json`), actually *reify* the list of emission types so the rest of the code doesn't need to keep this in mind. I'm not sure if you like this. It's a tinge overengineered, maybe, but it's more robust I claim. This PR also rejects `--emit` when `--output-format doctest -Zunstable-options` is passed since the latter doesn't honor emission types at all (yet).
|
@bors yield |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #156397. |
…uwer Rollup of 6 pull requests Successful merges: - #155679 (rustdoc: Reify emission types) - #155982 (Fix closure HIR span context mismatch) - #156323 (Handle --print=backend-has-mnemonic in cg_clif) - #156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`) - #156365 (stream_send_recv_stress tests: wait for threads to finish) - #156368 (Fix invalid unreachable in is_known_valid_scrutinee for Reborrow)
…uwer Rollup of 10 pull requests Successful merges: - #156394 (miri subtree update) - #154972 (Implement `core::arch::return_address` and tests) - #155679 (rustdoc: Reify emission types) - #155982 (Fix closure HIR span context mismatch) - #156323 (Handle --print=backend-has-mnemonic in cg_clif) - #156387 (std fs tests: avoid matching on OS-provided error string) - #156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`) - #156192 (core: Replace `ptr::slice_from_raw_parts` with `slice::from_raw_parts`) - #156365 (stream_send_recv_stress tests: wait for threads to finish) - #156368 (Fix invalid unreachable in is_known_valid_scrutinee for Reborrow)
…uwer Rollup of 10 pull requests Successful merges: - rust-lang/rust#156394 (miri subtree update) - rust-lang/rust#154972 (Implement `core::arch::return_address` and tests) - rust-lang/rust#155679 (rustdoc: Reify emission types) - rust-lang/rust#155982 (Fix closure HIR span context mismatch) - rust-lang/rust#156323 (Handle --print=backend-has-mnemonic in cg_clif) - rust-lang/rust#156387 (std fs tests: avoid matching on OS-provided error string) - rust-lang/rust#156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`) - rust-lang/rust#156192 (core: Replace `ptr::slice_from_raw_parts` with `slice::from_raw_parts`) - rust-lang/rust#156365 (stream_send_recv_stress tests: wait for threads to finish) - rust-lang/rust#156368 (Fix invalid unreachable in is_known_valid_scrutinee for Reborrow)
Implements #155374 (comment):
Instead of maintaining the hidden assumption or invariant that
opts.emit.is_empty()actually means "emit default artifacts" (i.e.,[HtmlStaticFiles, HtmlNonStaticFiles]under output formathtml; "[???]" under output formatjson), actually reify the list of emission types so the rest of the code doesn't need to keep this in mind.I'm not sure if you like this. It's a tinge overengineered, maybe, but it's more robust I claim.
This PR also rejects
--emitwhen--output-format doctest -Zunstable-optionsis passed since the latter doesn't honor emission types at all (yet).