Closed
Labels
Milestone
Description
This leaks. (and it fails to perform all the other side-effects one might expect from relevant destructors.)
use std::cast::transmute;
use std::libc::c_void;
struct Rattle { croak: ~str }
impl Drop for Rattle {
fn drop(&mut self) {
println!("Goodbye {}",self.croak);
}
}
struct NonCopyable {
r: Rattle,
p: *c_void
}
impl Drop for NonCopyable {
fn drop(&mut self) {
let p = self.p;
let _v = unsafe { transmute::<*c_void, ~int>(p) };
}
}
fn main() {
let t = ~0;
let p = unsafe { transmute::<~int, *c_void>(t) };
let _x = NonCopyable { r: Rattle{ croak: ~"assigned" }, p: p };
// assigning this to a variable makes it not leak
NonCopyable { r: Rattle{ croak: ~"unassigned" }, p: p };
}Namely, running it prints:
% rustc /tmp/issue4734.rs && /tmp/issue4734
warning: no debug symbols in executable (-arch x86_64)
Goodbye assigned
Activity
msullivan commentedon Jun 21, 2013
Confirmed as still a bug. Updated test case in description.
pnkfelix commentedon Aug 23, 2013
Visiting for bug triage, email from 2013-08-19
Updated test case with a more visible way to see what's going wrong.
It is probably related to #3511
alexcrichton commentedon Jan 20, 2014
#3511 has landed, but this has not been fixed.
nikomatsakis commentedon Jan 25, 2014
I expect this is due to that goofy "ignore" mode, which I think ought to be removed from trans. In controlflow.rs, there is this fragment:
I am pretty sure that
Ignoremode is not running the relevant destructors. At minimum, we should change this code to check whethertype_needs_dropand usetrans_to_lvalueif so.auto merge of #13390 : alexcrichton/rust/run-some-destructors, r=brson
Auto merge of rust-lang#6179 - flip1995:rewrite_use_self, r=phansch
Merge pull request rust-lang#4734 from rust-lang/rustup-2025-11-29
Merge rust-lang#4734