Skip to content

rustdoc: Reify emission types#155679

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
fmease:rustdoc-reify-emission-types
May 10, 2026
Merged

rustdoc: Reify emission types#155679
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
fmease:rustdoc-reify-emission-types

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented Apr 23, 2026

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).

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Apr 23, 2026
Comment thread src/librustdoc/config.rs
dcx.fatal(format!("unrecognized emission type: {typ}"))
};

match typ {
Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

A match (output_format, typ) { … } / match (typ, output_format) { … } looked less legible in my eyes esp. due to rustfmt's decisions.

View changes since the review

Comment thread src/librustdoc/config.rs
// 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() {
Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

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.

View changes since the review

Comment thread src/librustdoc/config.rs
Comment on lines +523 to +525
if let OutputFormat::Doctest = output_format {
dcx.fatal("the `--emit` flag is not supported with `--output-format=doctest`");
}
Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

If you do like this PR I'll of course add a test for this.

View changes since the review

@fmease fmease marked this pull request as ready for review April 23, 2026 09:27
@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 Apr 23, 2026
Comment thread src/librustdoc/config.rs
"the `--emit={emit_flag}` flag is not supported with `--output-format=json`",
));
let mut emit = FxIndexMap::default();
for list in matches.opt_strs("emit") {
Copy link
Copy Markdown
Member Author

@fmease fmease Apr 23, 2026

Choose a reason for hiding this comment

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

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

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. The output format changes the resulting Clean AST, because HTML is inlined and JSON isn't.
  2. Constructing clean::Crate mutates DocContext, so we can't just construct Clean twice.
  3. You'll want to be able to specify a different output location for the JSON than for the HTML.
  4. 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?

Copy link
Copy Markdown
Member Author

@fmease fmease May 7, 2026

Choose a reason for hiding this comment

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

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 :)

@fmease
Copy link
Copy Markdown
Member Author

fmease commented May 7, 2026

What do you think of this PR itself? Irrespective of potential future plans for --emit that is?

@notriddle
Copy link
Copy Markdown
Contributor

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.

@fmease fmease force-pushed the rustdoc-reify-emission-types branch from b5f0ae7 to 4d8ebc9 Compare May 9, 2026 22:44
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 9, 2026

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.

@fmease
Copy link
Copy Markdown
Member Author

fmease commented May 9, 2026

Test added.

@fmease fmease force-pushed the rustdoc-reify-emission-types branch from 4d8ebc9 to ef282ff Compare May 9, 2026 22:54
@notriddle
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 10, 2026

📌 Commit ef282ff 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-review Status: Awaiting review from the assignee but also interested parties. labels May 10, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 10, 2026
…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).
rust-bors Bot pushed a commit that referenced this pull request May 10, 2026
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)
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 10, 2026

⌛ Testing commit ef282ff with merge 9788718...

Workflow: https://github.com/rust-lang/rust/actions/runs/25630769060

rust-bors Bot pushed a commit that referenced this pull request May 10, 2026
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).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 10, 2026
…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).
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors yield
Yielding to enclosing rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 10, 2026

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #156397.

rust-bors Bot pushed a commit that referenced this pull request May 10, 2026
…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)
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 10, 2026

⌛ Testing commit ef282ff with merge 8f1bc40...

Workflow: https://github.com/rust-lang/rust/actions/runs/25632375858

rust-bors Bot pushed a commit that referenced this pull request May 10, 2026
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).
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors yield
Yielding to enclosing rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 10, 2026

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #156397.

rust-bors Bot pushed a commit that referenced this pull request May 10, 2026
…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)
rust-bors Bot pushed a commit that referenced this pull request May 10, 2026
…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)
@rust-bors rust-bors Bot merged commit 63e70d5 into rust-lang:main May 10, 2026
11 of 12 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 10, 2026
@fmease fmease deleted the rustdoc-reify-emission-types branch May 10, 2026 23:14
WhySoBad pushed a commit to WhySoBad/miri that referenced this pull request May 13, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants