diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 07aba04ca0e..0ae90e7c1e7 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -3515,6 +3515,12 @@ fn trans_struct(block_context: block, span: span, fields: ~[ast::field], } } + // Add the drop flag if necessary. + if ty::ty_dtor(block_context.tcx(), class_id).is_some() { + let llflagptr = GEPi(block_context, dest_address, ~[0, 0]); + Store(block_context, C_u8(1), llflagptr); + } + // Now translate each field. let mut temp_cleanups = ~[]; for fields.each |field| { diff --git a/src/test/run-pass/struct-literal-dtor.rs b/src/test/run-pass/struct-literal-dtor.rs new file mode 100644 index 00000000000..fdece230ef8 --- /dev/null +++ b/src/test/run-pass/struct-literal-dtor.rs @@ -0,0 +1,8 @@ +struct foo { + x: ~str; + drop { #error["%s", self.x]; } +} + +fn main() { + let _z = foo { x: ~"Hello" }; +}