Skip to content

Update the ways to get a pointer from a box in std::ptr docs #23312

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
Mar 13, 2015
Merged

Update the ways to get a pointer from a box in std::ptr docs #23312

merged 1 commit into from
Mar 13, 2015

Conversation

gkoz
Copy link
Contributor

@gkoz gkoz commented Mar 12, 2015

Show how to get a pointer without destroying the box.
Use boxed::into_raw instead of mem::transmute.

I removed the let my_num: *const i32 = mem::transmute(my_num); case altogether because we own the box, a *mut pointer is good anywhere a *const is needed, from_raw takes a mutable pointer and casting from a *const caused an ICE.

@gkoz
Copy link
Contributor Author

gkoz commented Mar 12, 2015

r? @steveklabnik

@rust-highfive rust-highfive assigned steveklabnik and unassigned huonw Mar 12, 2015
@rust-highfive
Copy link
Contributor

r? @huonw

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

@gkoz
Copy link
Contributor Author

gkoz commented Mar 12, 2015

r? @steveklabnik

//! types are the same size. Because `Box<T>` and `*mut T` have the same
//! representation they can be trivially,
//! though unsafely, transformed from one type to the other.
//! The `into_raw` function consumes an onwed box and returns
Copy link
Member

Choose a reason for hiding this comment

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

just 'box' not 'owned box'

@steveklabnik
Copy link
Member

r=me after some nits

@gkoz
Copy link
Contributor Author

gkoz commented Mar 12, 2015

Fixed the typos.

@gkoz
Copy link
Contributor Author

gkoz commented Mar 12, 2015

There's "owned box" in the subsection title. Not sure if "owned" should be removed there too

@steveklabnik
Copy link
Member

Yes, it should be, that term isn't used anymore.

Show how to get a pointer without destroying the box.
Use `boxed::into_raw` instead of `mem::transmute`.
@gkoz
Copy link
Contributor Author

gkoz commented Mar 12, 2015

Done!

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Mar 12, 2015

@bors r=steveklabnik 5d9ed0b

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 13, 2015
 Show how to get a pointer without destroying the box.
Use `boxed::into_raw` instead of `mem::transmute`.

I removed the `let my_num: *const i32 = mem::transmute(my_num);` case altogether because we own the box, a `*mut` pointer is good anywhere a `*const` is needed, `from_raw` takes a mutable pointer and casting from a `*const` caused an ICE.
@bors bors merged commit 5d9ed0b into rust-lang:master Mar 13, 2015
@Ms2ger
Copy link
Contributor

Ms2ger commented Mar 14, 2015

@gkoz: ICE? Did you file 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

Successfully merging this pull request may close these issues.

6 participants