Skip to content

Improve ptr::read docs #21989

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
Feb 7, 2015
Merged

Improve ptr::read docs #21989

merged 1 commit into from
Feb 7, 2015

Conversation

steveklabnik
Copy link
Member

@Gankra
Copy link
Contributor

Gankra commented Feb 6, 2015

@bors r+ ccb5 rollup

@kmcallister
Copy link
Contributor

How about "...leaves the memory in src unchanged, but runs the destructor"? I think that's an important part.

@Gankra
Copy link
Contributor

Gankra commented Feb 6, 2015

With non-zeroing drop, this would be an accurate description of a normal drop, no?

@huonw
Copy link
Member

huonw commented Feb 6, 2015

@kmcallister it doesn't run the destructor

@kmcallister
Copy link
Contributor

@huonw: How else do you explain the behavior of my test program in #21491? afaik, ptr::read is the standard way to explicitly call a destructor in Rust.

@huonw
Copy link
Member

huonw commented Feb 6, 2015

The value is memcpy'd onto the stack and ignored, so the destructor is run there. Something like let x: T = ptr::read(some_ptr); runs no destructors: just copies the value into x on the stack.

@kmcallister
Copy link
Contributor

Fair enough, I see what you mean. I feel like the idiom of discarding ptr::read(some_ptr) to run a destructor is too confusing if we don't mention it here, but I'm not sure.

@steveklabnik
Copy link
Member Author

I'm happy to adapt this to whatever everyone decides is best :)

@Gankra
Copy link
Contributor

Gankra commented Feb 6, 2015

How about "Copies the value behind the pointer regardless of whether it is Copy" or something to that effect.

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 6, 2015
@bors bors merged commit ccb513e into rust-lang:master Feb 7, 2015
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.

ptr::read docs are bogus
5 participants