Skip to content

Unstable book options parser#154070

Merged
rust-bors[bot] merged 5 commits intorust-lang:mainfrom
mehdiakiki:unstable-book-options-parser
Mar 28, 2026
Merged

Unstable book options parser#154070
rust-bors[bot] merged 5 commits intorust-lang:mainfrom
mehdiakiki:unstable-book-options-parser

Conversation

@mehdiakiki
Copy link
Copy Markdown
Contributor

@mehdiakiki mehdiakiki commented Mar 19, 2026

Parses the options! macro in compiler/rustc_session/src/options.rs directly to extract the unstable (-Z) compiler flag names and descriptions to generate documentation for the unstable book.

I took notice from the previous attempt which ran rustc -Zhelp and parsed the output and used this approach that reads the source directly.

Used claude for the tedious char by char parsing parts but verified the code, I hope that's ok!

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 19, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Mar 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 19, 2026

r? @petrochenkov

rustbot has assigned @petrochenkov.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

@rustbot

This comment has been minimized.

@mehdiakiki mehdiakiki force-pushed the unstable-book-options-parser branch from 6d964c6 to 96b9265 Compare March 19, 2026 02:11
@rustbot

This comment has been minimized.

@mehdiakiki mehdiakiki force-pushed the unstable-book-options-parser branch from 96b9265 to d5f2c91 Compare March 19, 2026 02:19
next_idx: usize,
}

fn parse_compiler_flags(options_rs: &str, options_path: &Path) -> Features {
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.

is there any way you can use syn here instead of open-coding it?

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.

alternatively, maybe we could move to the options to a separate file, use include! in the existing rust file, and then require them to be in a simpler format that's easier for syn to parse?

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.

Hi @jyn514 ! Currently I am parsing the whole file as a string, I will have a look at syn and report back!

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.

Parsing is much more straightforward with syn. Here’s my first attempt and I’d appreciate any feedback.

@petrochenkov
Copy link
Copy Markdown
Contributor

r? rustdoc I guess

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Mar 19, 2026
@rustbot rustbot assigned notriddle and unassigned petrochenkov Mar 19, 2026
@jyn514
Copy link
Copy Markdown
Member

jyn514 commented Mar 19, 2026

r? bootstrap

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Mar 19, 2026
@rustbot rustbot assigned clubby789 and unassigned notriddle Mar 19, 2026
@mehdiakiki mehdiakiki force-pushed the unstable-book-options-parser branch from b1a4466 to deeb45a Compare March 21, 2026 16:07
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 21, 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.

@clubby789
Copy link
Copy Markdown
Contributor

It seems a bit unfortunate that we're essentially implementing this macro twice (once as a decl macro, once as a Syn parser) but it's probably worth the benefit. Can we update the options! macro definition to mention that this parser needs to be kept up to date?

return Err(syn::Error::new(
name.span(),
format!(
"unexpected field count for option `{name}`: expected 4 or 5, found {}",
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.

Suggested change
"unexpected field count for option `{name}`: expected 4 or 5, found {}",
"unexpected field count for option `{name}`: expected {REQUIRED_FIELDS} or {OPTIONAL_FIELDS}, found {}",

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.

@clubby789 sure, will do by tomorrow!

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 25, 2026

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@mehdiakiki
Copy link
Copy Markdown
Contributor Author

It seems a bit unfortunate that we're essentially implementing this macro twice (once as a decl macro, once as a Syn parser) but it's probably worth the benefit. Can we update the options! macro definition to mention that this parser needs to be kept up to date?

That's right. That's a concern to keep in mind. Should we consider adding a test that parses options! in order to catch potential changes to the macro?

@clubby789
Copy link
Copy Markdown
Contributor

I believe parses_real_unstable_options_file should catch that, this comment is just to hopefully catch issues before waiting for CI to run.
LGTM now, thanks
@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 27, 2026

📌 Commit 75bd926 has been approved by clubby789

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 Mar 27, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 27, 2026
Rollup of 10 pull requests

Successful merges:

 - #154070 (Unstable book options parser)
 - #154371 (Use LocalDefId for more tcx method calls)
 - #154405 (Improve doc comment unicode guidance)
 - #154431 (Avoid ICE in explicit reference cast suggestion for unrelated leaf pr…)
 - #153528 (Fix LegacyKeyValueFormat report from docker build: mips)
 - #154246 (Add test for issue #101532: dead code warnings in const _)
 - #154421 (Rustdoc rejects html emits with json output)
 - #154428 (bootstrap: `-Zjson-target-spec` for synthetic targets)
 - #154437 (bootstrap.example.toml: Hint how to allow `build.warnings`)
 - #154454 (fix: [rustfmt] prevent panic when rewritng associated item delegations)

Failed merges:

 - #154450 (Use the normal arg-parsing machinery for `-Zassert-incr-state`)
rust-bors bot pushed a commit that referenced this pull request Mar 27, 2026
Rollup of 10 pull requests

Successful merges:

 - #154070 (Unstable book options parser)
 - #154371 (Use LocalDefId for more tcx method calls)
 - #154405 (Improve doc comment unicode guidance)
 - #154431 (Avoid ICE in explicit reference cast suggestion for unrelated leaf pr…)
 - #153528 (Fix LegacyKeyValueFormat report from docker build: mips)
 - #154246 (Add test for issue #101532: dead code warnings in const _)
 - #154421 (Rustdoc rejects html emits with json output)
 - #154428 (bootstrap: `-Zjson-target-spec` for synthetic targets)
 - #154437 (bootstrap.example.toml: Hint how to allow `build.warnings`)
 - #154454 (fix: [rustfmt] prevent panic when rewritng associated item delegations)

Failed merges:

 - #154450 (Use the normal arg-parsing machinery for `-Zassert-incr-state`)
@rust-bors rust-bors bot merged commit 6fd8466 into rust-lang:main Mar 28, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 28, 2026
rust-timer added a commit that referenced this pull request Mar 28, 2026
Rollup merge of #154070 - mehdiakiki:unstable-book-options-parser, r=clubby789

Unstable book options parser

Parses the `options!` macro in `compiler/rustc_session/src/options.rs` directly to extract the unstable (-Z) compiler flag names and descriptions to generate documentation for the unstable book.

I took notice from the previous attempt which ran `rustc -Zhelp` and parsed the output and used this approach that reads the source directly.

Used claude for the tedious char by char parsing parts but verified the code, I hope that's ok!
@Zalathar
Copy link
Copy Markdown
Member

I'm unhappy to see that this was merged, as it seems unreasonably burdensome to maintenance of unstable options.

Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 28, 2026
Revert "Unstable book options parser"

- Reverts rust-lang#154070

This reverts commit 6fd8466, reversing changes made to fda6d37.

---

The changes in rust-lang#154070 are well-intentioned, but in their current form they place an unreasonable maintenance burden on the affected part of the compiler, out of proportion to the benefit gained.

- Moving the unstable options to a separate `include!` file is marginally more convenient for the unstable-book-gen tool, but a big hassle for compiler contributors looking to read or modify the list of unstable options. It breaks normal file layout conventions, interferes with navigation, and interferes with IDE features, all without ever being truly necessary.

- The extra `syn`-based parser in unstable-book-gen is quite complicated, almost entirely undocumented, and seemingly buggy. That makes it extremely difficult to understand or modify, which in turn makes it effectively impossible to ever change the `options!` macro on the compiler side.

- The new tests in unstable-book-gen don't appear to be hooked up to run in CI.

- The compiler changes don't appear to have been approved by a T-compiler reviewer.

Before contemplating a revert, I tried to put together a fix-forward to resolve or mitigate some of these issues. But unstable-book-gen in its current state makes that impractical, so unfortunately I believe that the only way forward is to revert the original changes.

---

I do think the reverted functionality is potentially useful, and I'm not fundamentally opposed to a revised version of it landing in the future, if the relevant concerns are addressed.

But I feel strongly that the current version does not justify the real and troublesome maintenance burden that it imposes on compiler contributors.
@Noratrieb
Copy link
Copy Markdown
Member

Wouldn't a much easier alternative be to just add a new perma-unstable --print flag that dumps machine readable information about the flags (like JSON)?

@jyn514
Copy link
Copy Markdown
Member

jyn514 commented Mar 28, 2026

Then we have to build the compiler before building the unstable book. I guess that’s not the end of the world.

rust-timer added a commit that referenced this pull request Mar 28, 2026
Rollup merge of #154488 - Zalathar:unstable, r=jieyouxu

Revert "Unstable book options parser"

- Reverts #154070

This reverts commit 6fd8466, reversing changes made to fda6d37.

---

The changes in #154070 are well-intentioned, but in their current form they place an unreasonable maintenance burden on the affected part of the compiler, out of proportion to the benefit gained.

- Moving the unstable options to a separate `include!` file is marginally more convenient for the unstable-book-gen tool, but a big hassle for compiler contributors looking to read or modify the list of unstable options. It breaks normal file layout conventions, interferes with navigation, and interferes with IDE features, all without ever being truly necessary.

- The extra `syn`-based parser in unstable-book-gen is quite complicated, almost entirely undocumented, and seemingly buggy. That makes it extremely difficult to understand or modify, which in turn makes it effectively impossible to ever change the `options!` macro on the compiler side.

- The new tests in unstable-book-gen don't appear to be hooked up to run in CI.

- The compiler changes don't appear to have been approved by a T-compiler reviewer.

Before contemplating a revert, I tried to put together a fix-forward to resolve or mitigate some of these issues. But unstable-book-gen in its current state makes that impractical, so unfortunately I believe that the only way forward is to revert the original changes.

---

I do think the reverted functionality is potentially useful, and I'm not fundamentally opposed to a revised version of it landing in the future, if the relevant concerns are addressed.

But I feel strongly that the current version does not justify the real and troublesome maintenance burden that it imposes on compiler contributors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

8 participants