You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Destructor for @Trait is not run in certain circumstances #10802
I'm not sure if this is a duplicate of an existing issue, there are many destructor related issues open already. But anyways, here it is:
#[feature(managed_boxes)];structDroppableStruct{a:int}implDropforDroppableStruct{fndrop(&mutself){println!("Dropping");}}traitMyTrait{}implMyTraitforDroppableStruct{}structWhatever<'a>{w:&'aMyTrait}impl<'a>Whatever<'a>{fnnew<'b>(w:&'bMyTrait) -> Whatever<'b>{Whatever{w: w }}}fnmain(){letmut f = DroppableStruct;let _a = Whatever::new(@f as @MyTrait);}
This doesn't run the destructor of DroppableStruct. This is pretty much as minimal as I could get the example, many changes make it work. E.g. changing the main function body to:
let f = DroppableStruct{a:1};let b = @f as @MyTrait;let _a = Whatever::new(b);
makes the destructor work. Also, not saving the Whatever struct in a variable makes it work. Also, not saving the @MyTrait in Whatever makes it work. Good luck.
Update: removed mut, was not relevant.
Update2: added a field to the struct to show it's not an issue about zero-sized structs.
Activity
emberian commentedon Dec 4, 2013
cc @nikomatsakis
flaper87 commentedon Apr 14, 2014
It's no longer possible to cast to
@-traits as of b2d30b7I tried to reproduced this bug using
~and&pointers but it worked as expected.emberian commentedon Apr 14, 2014
@flaper87 is there a testcase which covers this?
flaper87 commentedon Apr 14, 2014
@cmr I had seen it before but I can't find it anymore. Re-opening and flagging as needs test:
test: Add tests for closed issues
auto merge of #13811 : alexcrichton/rust/closed-issues, r=sfackler
Auto merge of rust-lang#10802 - flip1995:rustup, r=flip1995
Merge rust-lang#10802