Skip to content

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

Merged
merged 1 commit into from
Dec 1, 2015

Conversation

klao
Copy link
Contributor

@klao klao commented Nov 30, 2015

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 the `d` box, not the
box in the `bar`'s stack frame.
@rust-highfive
Copy link
Contributor

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.

@Manishearth
Copy link
Member

r? @steveklabnik

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 30, 2015

📌 Commit 7728742 has been approved by steveklabnik

@bors
Copy link
Collaborator

bors commented Nov 30, 2015

⌛ Testing commit 7728742 with merge 937efb3...

@steveklabnik
Copy link
Member

Thank you! I agree that this could use some simplification.

@steveklabnik
Copy link
Member

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.

@bors
Copy link
Collaborator

bors commented Nov 30, 2015

💔 Test failed - auto-mac-64-nopt-t

@klao
Copy link
Contributor Author

klao commented Nov 30, 2015

Great explanation in the linked thread, thanks!

@steveklabnik
Copy link
Member

@bors: retry

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Nov 30, 2015
…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. :))
bors added a commit that referenced this pull request Dec 1, 2015
@bors bors merged commit 7728742 into rust-lang:master Dec 1, 2015
@klao klao deleted the fix-book-stack branch December 1, 2015 16:07
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.

5 participants