-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustdoc-json: Include GenericParamDefKind::Type::synthetic in JSON #94150
rustdoc-json: Include GenericParamDefKind::Type::synthetic in JSON #94150
Conversation
rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing |
r? @CraftSpider (rust-highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good change, and might help with #93803
src/rustdoc-json-types/lib.rs
Outdated
@@ -329,7 +329,7 @@ pub struct GenericParamDef { | |||
#[serde(rename_all = "snake_case")] | |||
pub enum GenericParamDefKind { | |||
Lifetime { outlives: Vec<String> }, | |||
Type { bounds: Vec<GenericBound>, default: Option<Type> }, | |||
Type { bounds: Vec<GenericBound>, default: Option<Type>, synthetic: bool }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be documented for what it means, because I can't find any reference to synthetic generic params outside the compiller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I added docs now. I considered documenting other fields, but I think the structure and naming is pretty clear by themselves to someone that is familiar with the Rust type system. The diff is a bit big due to rustfmt though.
Also, big thanks for making the test much more robust.
It is also worth thinking about if we instead of adding synthetic
should simply omit synthetic params from JSON. But, I suspect that if we go that route, that will cascade into current or future problems, such as the need to special case other code that relies on synthetic generic args being available.
Analogous to how it appears to be the case that omitting some private modules was a mistake (see #93518)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also worth thinking about if we instead of adding synthetic should simply omit synthetic params from JSON.
Yeah, the long term plan is to make params only be the names, and put all constraints in the where_predicates
(#93803). But thats a larger change and we can land this now, to also improve the shape of the tests for when it lands
955bab5
to
1d4b30a
Compare
This comment has been minimized.
This comment has been minimized.
9446484
to
9c43789
Compare
Looks good, thank you for the PR. |
📌 Commit 9c43789 has been approved by |
…s-in-json, r=CraftSpider rustdoc-json: Include GenericParamDefKind::Type::synthetic in JSON The rustdoc JSON for ``` pub fn f(_: impl Clone) {} ``` will effectively be ``` pub fn f<impl Clone: Clone>(_: impl Clone) {} ``` where a synthetic generic parameter called `impl Clone` with generic trait bound `Clone` is added to the function declaration. The generated HTML filters out these generic parameters by doing `self.params.iter().filter(|p| !p.is_synthetic_type_param())`, because the synthetic generic paramter is not of interest to regular users. For the same reason, we should expose whether or not a generic parameter is synthetic or not also in the rustdoc JSON, so that rustdoc JSON clients can also have the option to hide syntehtic generic parameters. ````@rustbot```` modify labels: +A-rustdoc-json
#94009 (being merged now) has become version 12, this will need to be version 13 |
@bors r- |
The rustdoc JSON for ``` pub fn f(_: impl Clone) {} ``` will effectively be ``` pub fn f<impl Clone: Clone>(_: impl Clone) ``` where a synthetic generic parameter called `impl Clone` with generic trait bound `Clone` is added to the function declaration. The generated HTML filters out these generic parameters by doing `self.params.iter().filter(|p| !p.is_synthetic_type_param())`, because the synthetic generic parameter is not of interest to regular users. For the same reason, we should expose whether or not a generic parameter is synthetic or not also in the rustdoc JSON, so that rustdoc JSON clients can also have the option to hide synthetic generic parameters.
9c43789
to
a424f42
Compare
I have now rebased and bumped You (and me) can confirm that
and I didn't do anything for #94591 yet since it not clear what the consensus is on how to solve it, but I am fully on board with the need for some kind of solution eventually. |
@rustbot label -S-waiting-on-author +S-waiting-on-review |
@bors r+ |
📌 Commit a424f42 has been approved by |
…askrgr Rollup of 3 pull requests Successful merges: - rust-lang#94150 (rustdoc-json: Include GenericParamDefKind::Type::synthetic in JSON) - rust-lang#94833 ([2/2] Implement macro meta-variable expression) - rust-lang#94863 (Remove redundant slicing of whole ranges in `bootstrap`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The rustdoc JSON for
will effectively be
where a synthetic generic parameter called
impl Clone
with generic trait boundClone
is added to the function declaration.The generated HTML filters out these generic parameters by doing
self.params.iter().filter(|p| !p.is_synthetic_type_param())
, because thesynthetic generic paramter is not of interest to regular users.
For the same reason, we should expose whether or not a generic parameter is
synthetic or not also in the rustdoc JSON, so that rustdoc JSON clients can also
have the option to hide syntehtic generic parameters.
@rustbot modify labels: +A-rustdoc-json