-
Notifications
You must be signed in to change notification settings - Fork 277
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
Simplify "Subtyping and Variance" section #262
Comments
You can absolutely have unrelated lifetimes --
the duration of a and b has no relationship, but c is known to cover both of their ranges. Thus |
@Gankra thanks for the correction! I still think the metaphor is confusing due to the inversion described in the "Main metaphor is confusing" section. For example, if we were to try to annotate your code snippet with the existing Animal metaphor:
Using another metaphor, such as the proposal of users/privilege levels, we could model this as
|
Also, after reading the section I found that the writing could do with some polishing. Mainly phrases that were too long:
These could be split up into smaller ones that are easier to digest. It's a popular technical writing recommendation. It's specially important if you're treating complex topics, like this one. The "however" in here should also have a comma afterwards:
And here:
And here:
I read
I would strongly recommend to install a grammar checker to detect these cases automatically. I personally did recently and it's incredibly helpful to make my writing more clear and concise. I personally use grammar-guard, which is a plugin for NeoVim, but there's a ton of them out there. Thanks for all the work on the Rustnomicon! |
I recently ran into several people who, because of the main metaphor, believed that supertraits/subtraits were a subtype relationship in Rust, and believed that it was this and lifetimes that variance applied to. So, I came to file an issue about this, but this one seems close enough (maybe I'm mistaken). At the very least, I'd like to say that I think this needs work still. EDIT: Ah, I guess there's an open PR about it. Sorry. |
For reference, the PR that the preceding comment refers to is #340, which is associated with issue #339. The “main metaphor” has been completely removed, preferring a more focused conversation on the abstract concepts. Considering this, could this issue be closed? If there are still standing points, maybe they could be merged into #339. |
I think the Subtyping and Variance section could be improved by some changes for simplicity and clarity. Here are a few initial thoughts. If any of these seem worth pursuing, I'm eager to take a stab at addressing them!
Main metaphor is confusing
The class-based subtyping of Animals and Cats/Dogs feels backwards. Indeed, the section itself even notes:
Some of the confusion noted by the author of issue 124 might be resolved with a metaphor whose relationships are closer analogs to Rust's lifetime relationships. For example, we could frame lifetime relationships in terms of privilege levels:
'a
which has a shorter lifetime.The early examples of the section might look something like this:
Dog subtype is confusing
Dog is presented as a "sibling" to Cat; that is, the only relationship between the two is that they are both subtypes of Animal. However, when it comes to lifetimes,'a
and'b
will always be related by a hierarchical relationship. Either'a
is more long-lived than'b
, or, if they live for the same amount of time, they're really just the same lifetime.Circling back to the privilege level analogy, Dog could be replaced by an account with guest-level privileges.This section wasn't quite accurate - see comments below.
Type lifetimes should be explicitly called out
One source of confusion for me, similar to the one raised in this comment, was that the section talks about variances over some type
T
. However, typeT
implictly has a lifetime, and the variance we're concerned with is really variances over this lifetime. This concept is never explicitly mentioned. I think a comment about this near the start of the Variance section would help.Justification of rules feels inverted
The quoted text implies that the problematic code snippet is fixed by referencing the variance table. This feels like the reverse framing of the true issue. It's more that the problematic code snippet is an example of a class of problems that necessitates the variance rule.
The text was updated successfully, but these errors were encountered: