rust icon indicating copy to clipboard operation
rust copied to clipboard

Rustdoc should indicate variance on lifetime/type parameters

Open tomjakubowski opened this issue 10 years ago • 9 comments

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.

tomjakubowski avatar Feb 09 '15 06:02 tomjakubowski

Triage: no changes here

steveklabnik avatar Mar 04 '16 17:03 steveklabnik

@rust-lang/rustdoc is this something we intend to pursue?

steveklabnik avatar Sep 24 '18 18:09 steveklabnik

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.

QuietMisdreavus avatar Nov 02 '18 15:11 QuietMisdreavus

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 avatar Dec 08 '20 23:12 sunshowers

@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.

jyn514 avatar Dec 16 '20 02:12 jyn514

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

danielhenrymantilla avatar Dec 16 '20 15:12 danielhenrymantilla

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.

fmease avatar Feb 12 '24 23:02 fmease

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!

obi1kenobi avatar Feb 12 '24 23:02 obi1kenobi

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)

aDotInTheVoid avatar May 13 '24 19:05 aDotInTheVoid