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.
18 state: Rc<Cell<usize>>
22 fn new(number: usize, state: Rc<Cell<usize>>) -> Field {
32 println!("Dropping field {}", self.number);
33 assert_eq!(self.state.get(), self.number);
34 self.state.set(self.state.get()+1);
50 impl Drop for HasDropImpl {
52 println!("HasDropImpl.drop()");
53 assert_eq!(self._one.state.get(), 0);
54 self._one.state.set(1);
59 let state = Rc::new(Cell::new(1));
60 let noImpl = NoDropImpl {
61 _one: Field::new(1, state.clone()),
62 _two: Field::new(2, state.clone()),
63 _three: Field::new(3, state.clone())
66 assert_eq!(state.get(), 4);
69 let hasImpl = HasDropImpl {
70 _one: Field::new(1, state.clone()),
71 _two: Field::new(2, state.clone()),
72 _three: Field::new(3, state.clone())
75 assert_eq!(state.get(), 4);