-
Notifications
You must be signed in to change notification settings - Fork 13.4k
HACKY/INCOMPLETE: Add implied bounds to rustdoc-json #142264
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
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
Some changes occurred in src/tools/compiletest cc @jieyouxu These commits modify Please ensure that if you've changed the output:
|
r? @ghost |
This comment has been minimized.
This comment has been minimized.
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.
Only works on structs. […]
I don't think this isn't fundamental, but should be doable with more work.
It is "fundamental" in that it doesn't work for functions which is the real question here. CC Jubilee's mention of implicit implied outlives-bounds.
For functions, predicates_of
(more specifically, inferred_outlives_of
which is called under the hood) does not include implied outlives-bounds. CC https://rustc-dev-guide.rust-lang.org/traits/implied-bounds.html#implicit-implied-bounds
generics: clean_ty_generics( | ||
cx, | ||
cx.tcx.generics_of(def_id), | ||
cx.tcx.predicates_of(def_id), |
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.
Right. predicates_of
contains the (explicit) implied bounds because it's explicit_predicates_of
+ inferred_outlives_of
.
I would just call inferred_outlives_of
separately and not call predicates_of
here. This way, implied bounds can be marked as implied.
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.
d'oh that's much nicer, and solves all the problems with this approach, as we also get to keep using HIR for HTML!
a5cf688
to
1d077d3
Compare
Closing, as not the right approach. |
rustdoc: Refractor `clean_ty_generics` Refactoring towards rust-lang#142226 [Zulip Discussion](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Why.20sometimes.20.60predicates_of.60.20.28vs.20.60explicit_predicates_.2E.2E.2E/near/523182529) The old `clean_ty_generics` was almost always called with the same args, so rename it to `clean_ty_generics_inner`, and add a new wrapper that generates those args from a `DefId`. Having this be the main entrypoint to `clean_ty_generics` should make it easier to start calling `inferred_outlives_of` rust-lang#142264 (comment) (and is more readable even if we don't) Also, replaces all calls in rustdoc to `tcx.predicates_of` to `tcx.explicit_predicates_of`, which lets us remove `filter_non_trait_generics` r? `@fmease`
rustdoc: Refractor `clean_ty_generics` Refactoring towards rust-lang#142226 [Zulip Discussion](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Why.20sometimes.20.60predicates_of.60.20.28vs.20.60explicit_predicates_.2E.2E.2E/near/523182529) The old `clean_ty_generics` was almost always called with the same args, so rename it to `clean_ty_generics_inner`, and add a new wrapper that generates those args from a `DefId`. Having this be the main entrypoint to `clean_ty_generics` should make it easier to start calling `inferred_outlives_of` rust-lang#142264 (comment) (and is more readable even if we don't) Also, replaces all calls in rustdoc to `tcx.predicates_of` to `tcx.explicit_predicates_of`, which lets us remove `filter_non_trait_generics` r? ``@fmease``
rustdoc: Refractor `clean_ty_generics` Refactoring towards rust-lang#142226 [Zulip Discussion](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Why.20sometimes.20.60predicates_of.60.20.28vs.20.60explicit_predicates_.2E.2E.2E/near/523182529) The old `clean_ty_generics` was almost always called with the same args, so rename it to `clean_ty_generics_inner`, and add a new wrapper that generates those args from a `DefId`. Having this be the main entrypoint to `clean_ty_generics` should make it easier to start calling `inferred_outlives_of` rust-lang#142264 (comment) (and is more readable even if we don't) Also, replaces all calls in rustdoc to `tcx.predicates_of` to `tcx.explicit_predicates_of`, which lets us remove `filter_non_trait_generics` r? ```@fmease```
Rollup merge of #142275 - aDotInTheVoid:gen-ty-of, r=fmease rustdoc: Refractor `clean_ty_generics` Refactoring towards #142226 [Zulip Discussion](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Why.20sometimes.20.60predicates_of.60.20.28vs.20.60explicit_predicates_.2E.2E.2E/near/523182529) The old `clean_ty_generics` was almost always called with the same args, so rename it to `clean_ty_generics_inner`, and add a new wrapper that generates those args from a `DefId`. Having this be the main entrypoint to `clean_ty_generics` should make it easier to start calling `inferred_outlives_of` #142264 (comment) (and is more readable even if we don't) Also, replaces all calls in rustdoc to `tcx.predicates_of` to `tcx.explicit_predicates_of`, which lets us remove `filter_non_trait_generics` r? ```@fmease```
A hackattempt at #142226. CC @obi1kenobi @workingjubilee @fmease
This is a meant to show it's possible. The version that lands will probably be a new PR that learns from this.
How
Hir doesn't have implied bounds, so we need to get generics from
ty
. Rustdoc already has a codepath for that, but it's not the default becausety
is far more normalized, so the HTML output is farther from what the user wrote.Limitations
Only works on structs. Fixable by replacing all calls to
clean_generics
with calls toclean_ty_generics
, so we only get generics fromty
. Also would require replacing all calls totcx.explicit_predicates_of
to justpredicates_of
.I don't think this isn't fundamental, but should be doable with more work.
Doesn't differentiate implied vs explicit bounds. This is necessary for json (rustdoc-json: Show implied outlives-bounds #142226 (comment)), and pretty desirable for HTML
Makes the HTML output """worse""" (for some definition of worse)