-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 should indicate variance on lifetime/type parameters #22108
Comments
Triage: no changes here |
@rust-lang/rustdoc is this something we intend to pursue? |
I'm not too sure how we could display this without cluttering up the display way more than we already have. Moreover, how do we collect this information? I don't have a good grasp of variance myself, much less whether we can just ask the compiler about a type/lifetime param to get an easy answer. I'm inclined to say "no", but the question of variance tends to crop up regularly enough that it may be worth leaving open for an intrepid compiler hacker. |
This would be super useful to build tooling around even if only exposed in JSON output (#76578). Variance changes are one of the more subtle kinds of API breakage, and anything we can do to make them easier to understand would be great. |
@sunshowers I would be willing to take a PR for this (especially if it's only in the JSON) but I have no idea how to implement it myself. |
We've discussed this today in a rustdoc meeting. The rustdoc team is generally in favor of providing this information but it's still unclear how exactly we want to present it in the UI. It's currently contested if we want to show it inline (i.e., inside code blocks & code snippets) or in a separate paragraph similar to trait object safety. On the other hand, providing this information in Rustdoc JSON should be pretty straightforward and the team members present in the meeting unanimously agreed that this would be useful to have especially for the semver checking tools out there. |
👋 cargo-semver-checks maintainer here, I'd be thrilled to plug this data into cargo-semver-checks and I'm happy to be a sounding board for the changes to the rustdoc JSON format needed to represent this data. Because of cargo-semver-checks' unique query-based architecture, almost all changes to the format are just a minor inconvenience instead of a big deal — so don't worry too much about breaking the tooling I maintain :) Thanks so much for working on this! |
[WIP] rustdoc (base+json): add support for variances I had this patch lying around for more than a month without much progress. Submitting this now to move things forward hopefully. Addresses part of rust-lang#22108. --- For transparency, I've stalled work on this because I haven't had the time to find ways to obtain or represent the “reason” / “provenance” of variances — a feature kindly requested by `@obi1kenobi,` maintainer of cargo-semver-checks. With “reason” we're referring to the set of constituent types that have had an influence on the variance of a given generic parameter. This information could then be used in the diagnostics of cargo-semver-checks à la “variance of param `T` of ty `S` changed from covariant to contravariant because you changed the type of field `f` from `T` to `fn(T)”. On second thought, this seems like a major add-on and I fear that it's infeasible to implement this (smh. exposing the necessary info from rustc). On the other hand, this feature probably has a large impact on the design of the final API (i.e., how we represent variances in rustdoc JSON). I definitely don't want to hand-roll variance computation inside rustdoc. --- TODOs: * clean up the implementation (see individual FIXMEs) * write docs for `rustdoc-json-types` * add rustdoc JSON tests r? ghost
This was discussed in todays T-rustdoc meeting TLDR:
|
This has come up a few times in IRC and I think it's a nice idea. It's already important for lifetime parameters, where variance is important today, and could be useful for type parameters as well if rust-lang/rfcs#738 is accepted.
The text was updated successfully, but these errors were encountered: