Skip to content

[rustdoc] Update doc_cfg hide/show syntax#157871

Merged
rust-bors[bot] merged 8 commits into
rust-lang:mainfrom
GuillaumeGomez:doc_cfg-syntax
Jun 27, 2026
Merged

[rustdoc] Update doc_cfg hide/show syntax#157871
rust-bors[bot] merged 8 commits into
rust-lang:mainfrom
GuillaumeGomez:doc_cfg-syntax

Conversation

@GuillaumeGomez

@GuillaumeGomez GuillaumeGomez commented Jun 13, 2026

Copy link
Copy Markdown
Member

View all comments

Part of #43781.

As discussed at the all-hands with the rustdoc team, we decided to follow the check-cfg syntax. So this PR implements it.

Considering @Urgau made the check-cfg implementation, I'll set them as reviewer here.

r? @Urgau

@rustbot

rustbot commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend 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. T-libs Relevant to the library 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 13, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Fixed CI. :)

@Urgau Urgau left a comment

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.

Looks pretty good. Some changes around none() and we should be in a good place.

View changes since this review

Comment thread compiler/rustc_attr_parsing/src/attributes/doc.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/attributes/doc.rs Outdated
Comment on lines 502 to 515
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute, PartialEq)]
pub enum DocCfgHideShowValue {
Any(Span),
List(ThinVec<(Symbol, Span)>),
}

#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
pub struct CfgInfo {
pub name: Symbol,
pub name_span: Span,
pub value: Option<(Symbol, Span)>,
pub struct DocCfgHideShow {
/// If `Some`, then `cfg` without values (like `cfg(windows)`) will be shown/hidden.
/// The `Span` comes from where this value was set.
pub only_key: Option<Span>,
/// The values of this `cfg` to shown/hidden.
pub values: DocCfgHideShowValue,
}

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.

This representation of the values of #[cfg] diverges from the compiler ExpectedValues for the none value (ie #[cfg(foo)]).

Normally we represent it with an Option<Symbol> where None is the absence of value, but this representation states that a value is only a Symbol and that it cannot be mixed with an "only key", but this ignores that mixed cases like #[cfg(foo)], #[cfg(foo = "12")], #[cfg(foo = "16")], ...

Suggested change
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute, PartialEq)]
pub enum DocCfgHideShowValue {
Any(Span),
List(ThinVec<(Symbol, Span)>),
}
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
pub struct CfgInfo {
pub name: Symbol,
pub name_span: Span,
pub value: Option<(Symbol, Span)>,
pub struct DocCfgHideShow {
/// If `Some`, then `cfg` without values (like `cfg(windows)`) will be shown/hidden.
/// The `Span` comes from where this value was set.
pub only_key: Option<Span>,
/// The values of this `cfg` to shown/hidden.
pub values: DocCfgHideShowValue,
}
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute, PartialEq)]
pub enum DocCfgHideShowValue {
Any(Span),
List(ThinVec<(Option<Symbol>, Span)>),
}
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
pub struct DocCfgHideShow {
/// The values of this `cfg` to shown/hidden.
pub values: DocCfgHideShowValue,
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But with this approach, you need to have two DocCfgHideShow: one to represent cfg(foo) and another to represent cfg(foo = "bla"). Or did I misunderstand your point?

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.

No, you still only need one DocCfgHideShow and one DocCfgHideShowValue.

The way cfg(foo) would be represented is by having a (None, none_span) inside DocCfgHideShowValue::List.

All the other values, like cfg(foo = "bla") would be (Some("bla"), bla_span)) inside DocCfgHideShowValue::List.

So at the end if you had hide(foo, values(none(), "bla")) it would be represented as:

// imaging this is dbg!()
DocCfgHideShow {
    values: DocCfgHideShowValue::List(vec![
        (None, none_span),
        (Some("bla"), bla_span)),
    ])
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But you cannot have an any() and a none() in the same struct then.

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.

any() already implies none(), there is no need for both of them to be specified at the same time.

Also for --check-cfg specifying both is rejected.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So you cannot say "all values but only if there is a value"?

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.

So you cannot say "all values but only if there is a value"?

No, not currently. The same is also not possible with a literal like "bar". There hasn't been a desire to introduce a "all values expect ...".


For the record, we talked about this extensively in DM and ended-up with two possible way forward:

  1. allow conflicting hide(...) and show(...) on the same level: auto_cfg(hide(windows, values(any())), show(windows))
  2. change the effect of show(...) to not take into account hide(...), but instead show everything inside (...) and hide everything else
    • instead of only effecting what was hidden by a previous hide(...)

Both solution would I think work, and I don't have a preference, so feel free to do either of them.

The end goal is to be consistent with --check-cfg: any() implies none().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll go with 1. as I find it more elegant and coherent with how cfg works.

Comment thread compiler/rustc_attr_parsing/src/diagnostics.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/diagnostics.rs Outdated
Comment thread tests/rustdoc-html/doc-cfg/hide-inheritance.rs
Comment thread src/librustdoc/json/conversions.rs
@Urgau Urgau added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 16, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

These commits modify tests/rustdoc-json.
rustdoc-json is a public (but unstable) interface.

Please ensure that if you've changed the output:

  • It's intentional.
  • The FORMAT_VERSION in src/librustdoc-json-types is bumped if necessary.

cc @aDotInTheVoid, @obi1kenobi

@rustbot

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Correctly handled values(), added test for values("a", none()), add a rustdoc-json test and updated the book.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Well, fmt makes me sad on this one but it's fine. :')

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Implemented the correct handling of values(any()) and remove the show/hide conflict, allowing cases that were not possible otherwise.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

And because I had to forget something, I updated the docs too. :)

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

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.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Fixed merge conflict.

@Urgau Urgau left a comment

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.

Thanks for working on it. LGTM

View changes since this review

@Urgau

Urgau commented Jun 27, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 702445c has been approved by Urgau

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1. This pull request will be tested once the tree is reopened.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 27, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #157871 ([rustdoc] Update `doc_cfg` hide/show syntax)
 - #158234 (Cross-referencing tuple_trait tracking issue, source and the Unstable Book)
 - #158480 (add smoketest for std::net::hostname)
 - #157625 (Use infer tys for synthetic params when lowering const paths point to fns)
 - #158290 (add crashtests [1/N])
 - #158306 (tests: modify s390x vector test to be robust to instruction scheduling)
 - #158313 (Move `check_target_feature` into the attribute parser)
 - #158431 (More lint cleanups)
 - #158452 (Add missing links in integer docs)
 - #158467 (Add proc macro for unused assignments and corresponding test)
 - #158472 (Add regression test for unexpected pointer dereference issue)
 - #158475 (Fix doc comment on get_debug_as_hex.)
 - #158476 (Fix doc comment on FormattingOptions::new().)
rust-bors Bot pushed a commit that referenced this pull request Jun 27, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #157871 ([rustdoc] Update `doc_cfg` hide/show syntax)
 - #158234 (Cross-referencing tuple_trait tracking issue, source and the Unstable Book)
 - #158480 (add smoketest for std::net::hostname)
 - #157625 (Use infer tys for synthetic params when lowering const paths point to fns)
 - #158290 (add crashtests [1/N])
 - #158306 (tests: modify s390x vector test to be robust to instruction scheduling)
 - #158313 (Move `check_target_feature` into the attribute parser)
 - #158431 (More lint cleanups)
 - #158452 (Add missing links in integer docs)
 - #158467 (Add proc macro for unused assignments and corresponding test)
 - #158472 (Add regression test for unexpected pointer dereference issue)
 - #158475 (Fix doc comment on get_debug_as_hex.)
 - #158476 (Fix doc comment on FormattingOptions::new().)
rust-bors Bot pushed a commit that referenced this pull request Jun 27, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #157871 ([rustdoc] Update `doc_cfg` hide/show syntax)
 - #158234 (Cross-referencing tuple_trait tracking issue, source and the Unstable Book)
 - #158480 (add smoketest for std::net::hostname)
 - #157625 (Use infer tys for synthetic params when lowering const paths point to fns)
 - #158290 (add crashtests [1/N])
 - #158306 (tests: modify s390x vector test to be robust to instruction scheduling)
 - #158313 (Move `check_target_feature` into the attribute parser)
 - #158431 (More lint cleanups)
 - #158452 (Add missing links in integer docs)
 - #158467 (Add proc macro for unused assignments and corresponding test)
 - #158472 (Add regression test for unexpected pointer dereference issue)
 - #158475 (Fix doc comment on get_debug_as_hex.)
 - #158476 (Fix doc comment on FormattingOptions::new().)
rust-bors Bot pushed a commit that referenced this pull request Jun 27, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #157871 ([rustdoc] Update `doc_cfg` hide/show syntax)
 - #158234 (Cross-referencing tuple_trait tracking issue, source and the Unstable Book)
 - #158480 (add smoketest for std::net::hostname)
 - #157625 (Use infer tys for synthetic params when lowering const paths point to fns)
 - #158290 (add crashtests [1/N])
 - #158306 (tests: modify s390x vector test to be robust to instruction scheduling)
 - #158313 (Move `check_target_feature` into the attribute parser)
 - #158431 (More lint cleanups)
 - #158452 (Add missing links in integer docs)
 - #158467 (Add proc macro for unused assignments and corresponding test)
 - #158472 (Add regression test for unexpected pointer dereference issue)
 - #158475 (Fix doc comment on get_debug_as_hex.)
 - #158476 (Fix doc comment on FormattingOptions::new().)
@rust-bors rust-bors Bot merged commit eb804b3 into rust-lang:main Jun 27, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 27, 2026
@JonathanBrouwer

JonathanBrouwer commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

@rust-timer build 0a46792
Perf run for #158487

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0a46792): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.5%] 7
Regressions ❌
(secondary)
0.4% [0.2%, 0.6%] 18
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.5%] 7

Max RSS (memory usage)

Results (primary 5.7%, secondary 2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
5.7% [5.6%, 5.8%] 2
Regressions ❌
(secondary)
5.3% [1.0%, 9.5%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-5.2%, -1.8%] 2
All ❌✅ (primary) 5.7% [5.6%, 5.8%] 2

Cycles

Results (primary 2.9%, secondary 1.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
4.4% [3.1%, 5.2%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-3.4%, -2.1%] 4
All ❌✅ (primary) 2.9% [2.9%, 2.9%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 485.171s -> 485.604s (0.09%)
Artifact size: 393.14 MiB -> 393.21 MiB (0.02%)

@rustbot rustbot added the perf-regression Performance regression. label Jun 27, 2026
@GuillaumeGomez GuillaumeGomez deleted the doc_cfg-syntax branch June 27, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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. 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.

6 participants