Skip to content

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

Merged
merged 4 commits into from
Nov 29, 2015

Conversation

sourcefrog
Copy link
Contributor

Based on the description in

//! Code for type-checking cast expressions.
and https://doc.rust-lang.org/nightly/nomicon/casts.html

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@sourcefrog
Copy link
Contributor Author

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.

@sourcefrog
Copy link
Contributor Author

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
@Gankra
Copy link
Contributor

Gankra commented Nov 28, 2015

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.

@Gankra
Copy link
Contributor

Gankra commented Nov 28, 2015

r? @steveklabnik

@steveklabnik
Copy link
Member

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+

@bors
Copy link
Collaborator

bors commented Nov 28, 2015

📌 Commit d695212 has been approved by steveklabnik

@steveklabnik
Copy link
Member

(@gankro we should chat about your nomicon feels sometime too)

@sourcefrog
Copy link
Contributor Author

Thanks for the speedy review. I'd like to clear up the phrasing a bit before this is actually merged.

@steveklabnik
Copy link
Member

@bors: r-

What parts in particular?

On Nov 28, 2015, 13:34 -0500, Martin Poolnotifications@github.com, wrote:

Thanks for the speedy review. I'd like to clear up the phrasing a bit before this is actually merged.


Reply to this email directly orview it on GitHub(#30088 (comment)).

@sourcefrog
Copy link
Contributor Author

Do you think it's clear enough?

It refers to some constants like Sized and C-like enum that aren't explained by this point. For Sized I could just point forward to the chapter on traits, and C-like enums are just enums whose values are all integers?

I think it's also possible to handle coercion by defining Deref?

@sourcefrog
Copy link
Contributor Author

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.

@steveklabnik
Copy link
Member

It refers to some constants like Sized and C-like enum that aren't explained by this point.

Since this is getting re-arranged in the near future, I'm not as worried about it as I normally would be.

@steveklabnik
Copy link
Member

I do still think this is great, thanks 👍

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 29, 2015

📌 Commit 797d543 has been approved by steveklabnik

@bors
Copy link
Collaborator

bors commented Nov 29, 2015

⌛ Testing commit 797d543 with merge 15ad1d1...

@bors bors merged commit 797d543 into rust-lang:master Nov 29, 2015

```rust
let a = "hello";
let b = a as String;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... this doesn't compile.

Copy link
Contributor Author

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

bors added a commit that referenced this pull request Nov 30, 2015
@sourcefrog
Copy link
Contributor Author

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.

@steveklabnik
Copy link
Member

It should have. I'm not sure why this passed.

@steveklabnik
Copy link
Member

I think it's a bug, I'm fixing it. Ugh. :(

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Nov 30, 2015
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.
bors added a commit that referenced this pull request Nov 30, 2015
In #29932, I moved the location of TRPL, but I missed making the changes
in mk/tests.mk. This led to #30088 landing with a broken example.

As such, #30113 will need to land before this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants