Skip to content

ptr::read docs are bogus #21491

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

Closed
kmcallister opened this issue Jan 22, 2015 · 2 comments · Fixed by #21989
Closed

ptr::read docs are bogus #21491

kmcallister opened this issue Jan 22, 2015 · 2 comments · Fixed by #21989

Comments

@kmcallister
Copy link
Contributor

Reads the value from src without dropping it.

But in fact this code does run the destructor:

use std::{ptr, mem};

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        println!("drop day");
    }
} 

fn main() {
    let x = Foo;
    unsafe {
        ptr::read(&x as *const Foo);
        mem::forget(x);
    }
} 

It's not clear what "without dropping it" means. I suspect the point is that it won't mark the target (hence *const T) as destroyed, from an era when this was more of a dynamic notion than today. But at any rate, the docs should reflect reality. As far as I know this is the way to explicitly run a destructor in Rust — a nice duality because ptr::write is the "placement new" for uninitialized memory.

@kmcallister
Copy link
Contributor Author

cc @steveklabnik

@Gankra
Copy link
Contributor

Gankra commented Jan 22, 2015

I actually recently wrote this 😓

I think maybe this should instead say "without moving it"?

steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 6, 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 a pull request may close this issue.

2 participants