1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // A battery of tests to ensure destructors of unboxed closure environments
12 // run at the right times.
14 // pretty-expanded FIXME #23616
16 #![feature(unboxed_closures)]
18 static mut DROP_COUNT: uint = 0;
20 fn drop_count() -> uint {
31 fn new() -> Droppable {
38 impl Drop for Droppable {
46 fn a<F:Fn(int, int) -> int>(f: F) -> int {
50 fn b<F:FnMut(int, int) -> int>(mut f: F) -> int {
54 fn c<F:FnOnce(int, int) -> int>(f: F) -> int {
60 a(move |a: int, b| { a + b });
62 assert_eq!(drop_count(), 0);
65 let z = &Droppable::new();
66 a(move |a: int, b| { z; a + b });
67 assert_eq!(drop_count(), 0);
69 assert_eq!(drop_count(), 1);
72 let z = &Droppable::new();
73 let zz = &Droppable::new();
74 a(move |a: int, b| { z; zz; a + b });
75 assert_eq!(drop_count(), 1);
77 assert_eq!(drop_count(), 3);
82 b(move |a: int, b| { a + b });
84 assert_eq!(drop_count(), 3);
87 let z = &Droppable::new();
88 b(move |a: int, b| { z; a + b });
89 assert_eq!(drop_count(), 3);
91 assert_eq!(drop_count(), 4);
94 let z = &Droppable::new();
95 let zz = &Droppable::new();
96 b(move |a: int, b| { z; zz; a + b });
97 assert_eq!(drop_count(), 4);
99 assert_eq!(drop_count(), 6);
104 c(move |a: int, b| { a + b });
106 assert_eq!(drop_count(), 6);
109 let z = Droppable::new();
110 c(move |a: int, b| { z; a + b });
111 assert_eq!(drop_count(), 7);
113 assert_eq!(drop_count(), 7);
116 let z = Droppable::new();
117 let zz = Droppable::new();
118 c(move |a: int, b| { z; zz; a + b });
119 assert_eq!(drop_count(), 9);
121 assert_eq!(drop_count(), 9);