From e7dbf42214c5dfe39b8fd6896171aaa8feee7582 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 24 Apr 2012 14:16:50 -0700 Subject: [PATCH] rustc: Fix type_need_unwind_cleanup. Closes #2272 --- src/rustc/middle/ty.rs | 8 ++++++-- src/test/compile-fail/class-implements-int.rs | 7 ------- src/test/compile-fail/infinite-instantiation.rs | 2 -- src/test/run-fail/issue-2272.rs | 12 ++++++++++++ 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/test/run-fail/issue-2272.rs diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 2d5a68d08ab8..68da6e6d734f 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -1176,7 +1176,8 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, let mut encountered_box = encountered_box; let mut needs_unwind_cleanup = false; maybe_walk_ty(ty) {|ty| - alt get(ty).struct { + let old_encountered_box = encountered_box; + let result = alt get(ty).struct { ty_box(_) | ty_opaque_box { encountered_box = true; true @@ -1216,7 +1217,10 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, needs_unwind_cleanup = true; false } - } + }; + + encountered_box = old_encountered_box; + result } ret needs_unwind_cleanup; diff --git a/src/test/compile-fail/class-implements-int.rs b/src/test/compile-fail/class-implements-int.rs index 70eca5e07425..7a2a7ad4f949 100644 --- a/src/test/compile-fail/class-implements-int.rs +++ b/src/test/compile-fail/class-implements-int.rs @@ -1,10 +1,3 @@ -// xfail-test -/* - tjc: currently this results in a memory leak after a call to - span_fatal in typeck. I think it's the same issue as #2272, because - if I make type_needs_unwind_cleanup always return true, the test passes. - FIXME: Un-xfail this when #2272 is fixed. - */ class cat implements int { //! ERROR can only implement interface types let meows: uint; new(in_x : uint) { self.meows = in_x; } diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index 5bf485ba5353..fa49f605306f 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -1,7 +1,5 @@ // error-pattern: overly deep expansion // issue 2258 -// This is currently exposing a memory leak, and xfailed for that reason -// xfail-test iface to_opt { fn to_option() -> option; diff --git a/src/test/run-fail/issue-2272.rs b/src/test/run-fail/issue-2272.rs new file mode 100644 index 000000000000..5aa1f4a92f6d --- /dev/null +++ b/src/test/run-fail/issue-2272.rs @@ -0,0 +1,12 @@ +// error-pattern:explicit failure +// Issue #2272 - unwind this without leaking the unique pointer + +fn main() { + let _x = { + y: { + z: @0 + }, + a: ~0 + }; + fail; +} \ No newline at end of file