]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/option-unwrap.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / option-unwrap.rs
CommitLineData
223e47cc
LB
1// Copyright 2012 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.
4//
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.
10
c34b1796 11
1a4d82fc 12#![feature(unsafe_destructor)]
223e47cc 13
1a4d82fc
JJ
14use std::cell::Cell;
15
16struct dtor<'a> {
c34b1796 17 x: &'a Cell<isize>,
223e47cc
LB
18}
19
20#[unsafe_destructor]
1a4d82fc
JJ
21impl<'a> Drop for dtor<'a> {
22 fn drop(&mut self) {
23 self.x.set(self.x.get() - 1);
223e47cc
LB
24 }
25}
26
970d7e83 27fn unwrap<T>(o: Option<T>) -> T {
223e47cc
LB
28 match o {
29 Some(v) => v,
1a4d82fc 30 None => panic!()
223e47cc
LB
31 }
32}
33
34pub fn main() {
1a4d82fc 35 let x = &Cell::new(1);
223e47cc
LB
36
37 {
38 let b = Some(dtor { x:x });
1a4d82fc 39 let _c = unwrap(b);
223e47cc
LB
40 }
41
1a4d82fc 42 assert_eq!(x.get(), 0);
223e47cc 43}