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