Skip to content
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

Do not use as to convert reference to pointer #3305

Open
2 tasks done
SoniEx2 opened this issue Aug 11, 2022 · 2 comments
Open
2 tasks done

Do not use as to convert reference to pointer #3305

SoniEx2 opened this issue Aug 11, 2022 · 2 comments
Milestone

Comments

@SoniEx2
Copy link

SoniEx2 commented Aug 11, 2022

  • I have checked the latest main branch to see if this has already been fixed
  • I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer

Description of the problem:

This uses as to convert the reference to a pointer. We've ran into issues in the past with as, e.g. RustyYato/cell-project#4. Specifically, it breaks inference in a bad way.

Suggested fix:

Use type ascription instead of as, e.g. let r1: *const i32.

@carols10cents carols10cents added this to the ch19 milestone Aug 19, 2022
@SoniEx2
Copy link
Author

SoniEx2 commented Aug 27, 2022

we can't remember what we were doing where it broke inference... we're struggling to figure out a test case which demonstrates it tho. sorry about that.

@SoniEx2
Copy link
Author

SoniEx2 commented Aug 27, 2022

found it: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4a7780954f610b8c4adff2d19925b824

(ps: we believe this example to be unsound, specifically due to the Drop impl, but we digress. the main thing we're trying to point out is the difference between as and type ascription and the Drop impl doesn't actually matter for that.)

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

No branches or pull requests

2 participants