Skip to content

jsondocck: Refactor directive handling #141709

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aDotInTheVoid
Copy link
Member

Best reviewed commit by commit.

  1. Moves directive handling into its own file. This makes it easier to link to in the dev-guide (Start documenting tests/rustdoc-json rustc-dev-guide#2422 (comment)), but also makes the code nicer in it's own right
  2. Renames command to directive. This is what compiletest uses, and it's nice to not have 2 words for this.

r? @GuillaumeGomez

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 28, 2025
@aDotInTheVoid aDotInTheVoid added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label May 28, 2025
@GuillaumeGomez GuillaumeGomez changed the title jsondocck: Refractor directive handling jsondocck: Refactor directive handling May 29, 2025
/// `//@ !has <path>`
///
/// Checks the path doesn't exist.
HasNotPath,
Copy link
Member

Choose a reason for hiding this comment

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

It sounds a bit weird to me, needed to read the docs (yeay docs!) to get what it was about. Also, is it really worth it to have two variants for each command and its opposite? Why not having a not: bool argument (or field directly in the enum if you prefer?) instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because that leads to really sucky error messages. The old implementation (before #133478) did this, and it was miserable. We had to special-case looking at not to give a more specific error (5f24798).

_ => panic!("`//@ !has` must have 2 or 3 arguments, but got {args:?}"),
},

(_, false) if KNOWN_DIRECTIVE_NAMES.contains(&directive_name) => {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it fail here saying it doesn't support the not mode for this command?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean? This is for things that arn't negeated (e.g. //@ only-aarch64), which we should silently ignore. For //@ !only-aarch64, then negated will be true, this case won't match, and we'll panic the the wildcard below.

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 C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

4 participants