Last active
December 17, 2015 02:59
-
-
Save ben0x539/5540095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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