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.
|
|
|
|
|
2013-10-23 04:49:18 -04:00
|
|
|
#[feature(managed_boxes)];
|
|
|
|
|
2012-08-03 10:22:16 -07:00
|
|
|
// A test case for #2548.
|
|
|
|
|
2013-12-31 15:46:27 -08:00
|
|
|
use std::cell::Cell;
|
2012-08-03 10:22:16 -07:00
|
|
|
|
2013-12-31 15:46:27 -08:00
|
|
|
struct foo {
|
|
|
|
x: @Cell<int>,
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
|
|
|
|
2013-03-20 18:18:57 -07:00
|
|
|
#[unsafe_destructor]
|
2013-02-14 11:47:00 -08:00
|
|
|
impl Drop for foo {
|
2013-09-16 21:18:07 -04:00
|
|
|
fn drop(&mut self) {
|
2013-03-20 18:18:57 -07:00
|
|
|
unsafe {
|
2013-05-24 19:35:29 -07:00
|
|
|
println("Goodbye, World!");
|
2013-12-31 15:46:27 -08:00
|
|
|
self.x.set(self.x.get() + 1);
|
2013-03-20 18:18:57 -07:00
|
|
|
}
|
2012-08-03 10:22:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-31 15:46:27 -08:00
|
|
|
fn foo(x: @Cell<int>) -> foo {
|
2012-09-06 15:42:59 -07:00
|
|
|
foo { x: x }
|
|
|
|
}
|
|
|
|
|
2012-08-03 10:22:16 -07:00
|
|
|
fn main() {
|
2013-12-31 15:46:27 -08:00
|
|
|
let x = @Cell::new(0);
|
2012-08-03 10:22:16 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
let mut res = foo(x);
|
2013-01-10 13:57:38 -08:00
|
|
|
|
2013-02-12 18:34:48 -05:00
|
|
|
let mut v = ~[];
|
2013-07-11 12:05:17 -07:00
|
|
|
v = ~[(res)] + v; //~ failed to find an implementation of trait
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(v.len(), 2);
|
2012-08-03 10:22:16 -07:00
|
|
|
}
|
|
|
|
|
2013-12-31 15:46:27 -08:00
|
|
|
assert_eq!(x.get(), 1);
|
2012-08-03 10:22:16 -07:00
|
|
|
}
|