-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix pointer value in the 'complex example' on stack/heap #30115
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
The `f` argument will reference the actual value in the `d` box, not the box in the `bar`'s stack frame.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@bors: r+ rollup |
📌 Commit 7728742 has been approved by |
⌛ Testing commit 7728742 with merge 937efb3... |
Thank you! I agree that this could use some simplification. |
Oh, and for why: https://users.rust-lang.org/t/im-having-trouble-following-an-example-in-the-stack-and-the-heap/3666/6 <- we found this bug recently, but I hadn't had the time to update the example. |
💔 Test failed - auto-mac-64-nopt-t |
Great explanation in the linked thread, thanks! |
@bors: retry |
…teveklabnik The `f` argument will reference the actual value in the `d` box, not the box in the `bar`'s stack frame. I am just learning Rust, so I don't know how to explain this well, but just from `f`'s type it is clear that it will be a pointer to an `i32`, not a pointer to a pointer. Some `println!("{:p}", ...)`'s can easily confirm this. I would actually suggest to remove/simplify this part of the example. This is a subtle issue that can easily confuse people at the early stages of familiarizing with the language. (As I got confused by it. :))
The
f
argument will reference the actual value in thed
box, not the box in thebar
's stack frame.I am just learning Rust, so I don't know how to explain this well, but just from
f
's type it is clear that it will be a pointer to ani32
, not a pointer to a pointer. Someprintln!("{:p}", ...)
's can easily confirm this.I would actually suggest to remove/simplify this part of the example. This is a subtle issue that can easily confuse people at the early stages of familiarizing with the language. (As I got confused by it. :))