2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-09-19 13:59:44 -07:00
|
|
|
// xfail-fast
|
2012-09-18 15:52:21 -07:00
|
|
|
#[legacy_modes];
|
|
|
|
|
2013-01-25 22:46:32 -08:00
|
|
|
struct Arg<T> {val: T, fin: extern fn(T)}
|
|
|
|
|
2013-01-28 10:46:43 -08:00
|
|
|
struct finish<T> {
|
2013-01-25 22:46:32 -08:00
|
|
|
arg: Arg<T>
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
|
|
|
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<T:Copy> Drop for finish<T> {
|
2012-11-28 15:42:16 -08:00
|
|
|
fn finalize(&self) {
|
2012-12-01 15:25:17 -08:00
|
|
|
(self.arg.fin)(self.arg.val);
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
2012-01-11 09:58:05 -08:00
|
|
|
}
|
2011-06-30 14:46:17 +02:00
|
|
|
|
2013-02-20 17:07:17 -08:00
|
|
|
fn finish<T:Copy>(arg: Arg<T>) -> finish<T> {
|
2012-09-05 15:58:43 -07:00
|
|
|
finish {
|
|
|
|
arg: arg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-03-26 18:35:18 -07:00
|
|
|
let box = @mut 10;
|
|
|
|
fn dec_box(&&i: @mut int) { *i -= 1; }
|
2011-06-30 14:46:17 +02:00
|
|
|
|
2013-02-15 02:44:18 -08:00
|
|
|
{ let _i = finish(Arg{val: box, fin: dec_box}); }
|
2011-07-27 14:19:39 +02:00
|
|
|
assert (*box == 9);
|
2011-08-12 06:37:25 -07:00
|
|
|
}
|