[rustdoc] Update doc_cfg hide/show syntax#157871
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
This comment has been minimized.
This comment has been minimized.
0406a13 to
2c62c7f
Compare
This comment has been minimized.
This comment has been minimized.
2c62c7f to
7eaade0
Compare
|
Fixed CI. :) |
| #[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, | ||
| } |
There was a problem hiding this comment.
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")], ...
| #[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, | |
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)),
])
}There was a problem hiding this comment.
But you cannot have an any() and a none() in the same struct then.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
So you cannot say "all values but only if there is a value"?
There was a problem hiding this comment.
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:
- allow conflicting
hide(...)andshow(...)on the same level:auto_cfg(hide(windows, values(any())), show(windows)) - change the effect of
show(...)to not take into accounthide(...), but instead show everything inside(...)and hide everything else- instead of only effecting what was hidden by a previous
hide(...)
- instead of only effecting what was hidden by a previous
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().
There was a problem hiding this comment.
I'll go with 1. as I find it more elegant and coherent with how cfg works.
7eaade0 to
fba8015
Compare
|
These commits modify Please ensure that if you've changed the output:
|
This comment has been minimized.
This comment has been minimized.
|
Correctly handled |
This comment has been minimized.
This comment has been minimized.
fba8015 to
d38a2c9
Compare
|
Well, |
|
Implemented the correct handling of |
230486d to
7a047c7
Compare
|
And because I had to forget something, I updated the docs too. :) |
This comment has been minimized.
This comment has been minimized.
7a047c7 to
771318c
Compare
This comment has been minimized.
This comment has been minimized.
771318c to
702445c
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. |
|
Fixed merge conflict. |
|
@bors r+ |
…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().)
…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().)
…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().)
…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-timer build 0a46792 |
This comment has been minimized.
This comment has been minimized.
|
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 @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
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.
CyclesResults (primary 2.9%, secondary 1.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 485.171s -> 485.604s (0.09%) |
View all comments
Part of #43781.
As discussed at the all-hands with the rustdoc team, we decided to follow the
check-cfgsyntax. So this PR implements it.Considering @Urgau made the
check-cfgimplementation, I'll set them as reviewer here.r? @Urgau