]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/option-unwrap.rs
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / test / run-pass / option-unwrap.rs
1 #![allow(non_camel_case_types)]
2 use std::cell::Cell;
3
4 struct dtor<'a> {
5     x: &'a Cell<isize>,
6 }
7
8 impl<'a> Drop for dtor<'a> {
9     fn drop(&mut self) {
10         self.x.set(self.x.get() - 1);
11     }
12 }
13
14 fn unwrap<T>(o: Option<T>) -> T {
15     match o {
16       Some(v) => v,
17       None => panic!()
18     }
19 }
20
21 pub fn main() {
22     let x = &Cell::new(1);
23
24     {
25         let b = Some(dtor { x:x });
26         let _c = unwrap(b);
27     }
28
29     assert_eq!(x.get(), 0);
30 }