Skip to content

Instantly share code, notes, and snippets.

@ben0x539
Last active December 17, 2015 02:59
Show Gist options
  • Save ben0x539/5540095 to your computer and use it in GitHub Desktop.
Save ben0x539/5540095 to your computer and use it in GitHub Desktop.
use core::unstable::intrinsics;
struct S;
impl Drop for S {
fn finalize(&self) {}
}
fn discard(_s: S) {}
fn main() {
unsafe {
let p = libc::malloc(sys::size_of::<S>() as libc::size_t) as *mut S;
intrinsics::move_val_init(&mut *p, S);
// ... use p...
discard(*p);
libc::free(p as *libc::c_void);
}
}
baz.rs:15:19: 15:20 error: use of partially moved value: `p`
baz.rs:15 libc::free(p as *libc::c_void);
^
baz.rs:14:16: 14:18 note: subcomponent of `p` moved here because the subcomponent has type S, which is moved by default (use `copy` to override)
baz.rs:14 discard(*p);
^~
error: aborting due to previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment