forked from brson/miri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.rs
59 lines (47 loc) · 961 Bytes
/
option.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![feature(intrinsics, lang_items, no_core, fundamental)]
#![no_core]
pub mod marker {
use clone::Clone;
#[lang = "sized"]
#[fundamental]
pub trait Sized { }
#[lang = "copy"]
pub trait Copy : Clone { }
}
pub mod clone {
use marker::Sized;
pub trait Clone : Sized {
fn clone(&self) -> Self;
}
}
use self::Option::*;
#[derive(Clone, Copy)]
enum Option<T> {
None,
Some(T)
}
// Panic and assert
#[lang = "panic"] fn panic() -> ! { loop {} }
macro_rules! panic {
() => (
panic!("explicit panic")
);
($msg:expr) => ({
$crate::panic()
});
}
impl<T> Option<T> {
#[inline]
pub fn unwrap(self) -> T {
match self {
Some(val) => val,
None => panic!("called `Option::unwrap()` on a `None` value"),
}
}
}
fn main() {
let a : Option<i32> = Some(5i32);
let b : Option<i64> = Some(5i64);
a.unwrap();
b.unwrap();
}