-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add some documentation about what as
casts are legal
#30088
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
I don't feel this is really clear enough at the level of the Rust book, yet, but it's a start. There doesn't seem to be any definition of the concept of coercion yet. |
Thanks to Adrian in http://stackoverflow.com/a/33884290/243712 for pointing this out. |
Trying to summarize here only the cases that will make sense at the level of the rust book
Note that https://doc.rust-lang.org/nomicon/casts.html and https://doc.rust-lang.org/nomicon/coercions.html exist. I'm honestly a bit dubious of their existence, though. They were more motivated when I was trying to make the nomicon totally stand-alone and/or a substitute for the reference. Migrating all this content to The Book proper seems like a reasonable choice. |
Part of the problem with this is that it introduces a forward reference to raw pointers, but, I'm planning on a reorganization of the book anyway, so having this text around can still be useful. Thanks for adding this! @bors: r+ |
📌 Commit d695212 has been approved by |
(@gankro we should chat about your nomicon feels sometime too) |
Thanks for the speedy review. I'd like to clear up the phrasing a bit before this is actually merged. |
@bors: r- What parts in particular? On Nov 28, 2015, 13:34 -0500, Martin Poolnotifications@github.com, wrote:
|
Do you think it's clear enough? It refers to some constants like I think it's also possible to handle coercion by defining |
OK, I think this is clearer. I copied some text about the semantics of numeric casts from the nomicon, which seemed appropriate for an introduction. If you think this is clear enough and correct, please go ahead and merge. |
Since this is getting re-arranged in the near future, I'm not as worried about it as I normally would be. |
I do still think this is great, thanks 👍 @bors: r+ rollup |
📌 Commit 797d543 has been approved by |
⌛ Testing commit 797d543 with merge 15ad1d1... |
|
||
```rust | ||
let a = "hello"; | ||
let b = a as String; |
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.
... this doesn't compile.
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'll send a follow-up
Sorry, thanks to @Ms2ger for pointing this out in #30088 (comment)
Is it considered a bug in rustbook, or in the rust tree's use of it, that it doesn't test the examples? I did run the tests on this and I guess bors did too. |
It should have. I'm not sure why this passed. |
I think it's a bug, I'm fixing it. Ugh. :( |
In rust-lang#29932, I moved the location of TRPL, but I missed making the changes in mk/tests.mk. This led to rust-lang#30088 landing with a broken example. As such, rust-lang#30113 will need to land before this.
Based on the description in
rust/src/librustc_typeck/check/cast.rs
Line 11 in 219eca1