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.
13 #![feature(unsafe_destructor)]
24 fn new(number: uint, state: Rc<Cell<uint>>) -> Field {
32 #[unsafe_destructor] // because Field isn't Send
35 println!("Dropping field {}", self.number);
36 assert_eq!(self.state.get(), self.number);
37 self.state.set(self.state.get()+1);
53 #[unsafe_destructor] // because HasDropImpl isn't Send
54 impl Drop for HasDropImpl {
56 println!("HasDropImpl.drop()");
57 assert_eq!(self._one.state.get(), 0);
58 self._one.state.set(1);
63 let state = Rc::new(Cell::new(1));
64 let noImpl = NoDropImpl {
65 _one: Field::new(1, state.clone()),
66 _two: Field::new(2, state.clone()),
67 _three: Field::new(3, state.clone())
70 assert_eq!(state.get(), 4);
73 let hasImpl = HasDropImpl {
74 _one: Field::new(1, state.clone()),
75 _two: Field::new(2, state.clone()),
76 _three: Field::new(3, state.clone())
79 assert_eq!(state.get(), 4);