rust
rust copied to clipboard
Rustdoc should indicate variance on lifetime/type parameters
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.
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 (https://github.com/rust-lang/rust/issues/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.
Same here, will have to learn a bit more about the compiler representation of variance, but language-wise, it is a topic I am well acquainted with and would like to push for it 🙂 (will probably team up with @jyn514 💪).
@rustbot claim
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.
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!
This was discussed in todays T-rustdoc meeting
TLDR:
- @fmease working on a JSON only implementation
- Got delayed investigating adding "cause of variance" information
- I'm opposed to adding this to JSON
- but it would be useful for cargo-semver-checks to have (it'd need to calulate these anyway to show a great error)