-
Notifications
You must be signed in to change notification settings - Fork 501
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
Improve Type-Coersion Documentation #843
Conversation
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.
Thanks for picking this up!
@@ -91,7 +95,7 @@ the block has a known type. | |||
|
|||
Coercion is allowed between the following types: | |||
|
|||
* `T` to `U` if `T` is a subtype of `U` (*reflexive case*) | |||
* `T` to `U` if `T` is a [subtype] of `U` (*reflexive case*) |
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.
There seems to be an unanswered question here: https://github.com/rust-lang/reference/pull/342/files#r191050490
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.
I've had little experience with the term 'reflexive' in programming contexts, but in math, "is a subset of" is a reflexive relationship. I assume that "is a subtype of" would be the programming equivalent.
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.
Ah. I'm not super familiar with it, but since this is just adding a link, I won't hold up the PR on it. AIUI, the reflexive subtype would be "T is a subtype of T", not U (in the math sense, T is a subset of T).
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.
I guess.. Subtyping is an example of a reflexive relationship, because types are subtypes of themselves. So.. That means that a subtype coersion is reflexive, because it could be coercing to Self. That sounds really finicky now that I say it.
Co-authored-by: Eric Huss <eric@huss.org>
@ehuss What's the verdict on this? |
src/type-coercions.md
Outdated
The [type cast operator], `as`, is not a coersion site. However, most type | ||
conversions allowed by coersion can also be explicitly performed by `as`. |
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.
The phrasing here seems a little strange to me. Nothing suggests or implies that as
is a coercion site. The equivalence doesn't make sense because as
is an expression, not a location. It also says "most type conversions...", but then doesn't say which are allowed.
I think it would be best just to keep this simple and to the point. I still suggest my original wording, something like For explicit type coercions, see [type cast expressions].
.
Also, the word is spelled "coercion" with a c
.
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.
I'm trying to make the distinction that, if it's explicit, it's not a coercion. You're right that that wording is funky, though.
The [type cast operator], `as`, is not a coersion site. However, most type | ||
conversions allowed by coersion can also be explicitly performed by `as`. | ||
|
||
Coercions are originally defined in [RFC 401] and expanded upon in [RFC 1558]. | ||
|
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.
Try to avoid double blank lines.
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.
Thanks!
Update books ## reference 4 commits in 1b6c4b0afab97c0230433466c97167bbbe8445f6..25391dba46262f882fa846beefaff54a966a8fa5 2020-08-18 17:04:28 -0700 to 2020-09-02 07:22:55 -0700 - clarify when reading uninititalized memory is allowed (rust-lang/reference#852) - Update patterns chapter, add rest patterns. (rust-lang/reference#876) - Improve Type-Coersion Documentation (rust-lang/reference#843) - Added variable back into example. (rust-lang/reference#880) ## book 3 commits in c0a6a61b8205da14ac955425f74258ffd8ee065d..e5ed97128302d5fa45dbac0e64426bc7649a558c 2020-08-14 14:21:49 -0500 to 2020-08-31 12:53:40 -0500 - Fix type mismatch in listing 10-5 (rust-lang/book#2441) - Update ppendix-06-translation.md (rust-lang/book#2437) - Correct no-listing-10-result-in-tests: Take tests module out of the main function (rust-lang/book#2430) ## rust-by-example 3 commits in 80a10e22140e28392b99d24ed02f4c6d8cb770a0..19f0a0372af497b34369cf182d9d16156cab2969 2020-08-08 09:56:46 -0300 to 2020-08-26 09:38:48 -0300 - prefer `length` over `size` when talking about number of elements vs. bytesize (rust-lang/rust-by-example#1372) - Split out variable shadowing into a separate example (rust-lang/rust-by-example#1370) - Update extern crate related sections (rust-lang/rust-by-example#1369) ## edition-guide 1 commits in bd6e4a9f59c5c1545f572266af77f5c7a5bad6d1..81f16863014de60b53de401d71ff904d163ee030 2020-07-12 17:37:08 -0500 to 2020-08-27 13:56:31 -0700 - Fix a small typo. (rust-lang/edition-guide#218)
I've updated pull request #342 by @Havvy by fixing the merge conflicts, and additionally adding a fix to close #734 (Incorrect examples of type coercion).