2015-11-12 16:13:05 -06:00
|
|
|
#![feature(custom_attribute)]
|
2015-11-12 15:50:58 -06:00
|
|
|
#![allow(dead_code, unused_attributes)]
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
2015-11-12 16:13:05 -06:00
|
|
|
fn ret() -> i32 {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
2015-11-12 17:24:43 -06:00
|
|
|
fn neg() -> i32 {
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
2015-11-12 16:13:05 -06:00
|
|
|
fn add() -> i32 {
|
|
|
|
1 + 2
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
|
|
|
fn empty() {}
|
|
|
|
|
|
|
|
#[miri_run]
|
|
|
|
fn tuple() -> (i32,) {
|
|
|
|
(1,)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[miri_run]
|
|
|
|
fn tuple_2() -> (i32, i32) {
|
|
|
|
(1, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[miri_run]
|
|
|
|
fn tuple_5() -> (i32, i32, i32, i32, i32) {
|
|
|
|
(1, 2, 3, 4, 5)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[miri_run]
|
2015-11-12 16:13:05 -06:00
|
|
|
fn indirect_add() -> i32 {
|
2015-11-12 15:50:58 -06:00
|
|
|
let x = 1;
|
|
|
|
let y = 2;
|
|
|
|
x + y
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
2015-11-12 18:00:22 -06:00
|
|
|
fn arith() -> i32 {
|
|
|
|
3*3 + 4*4
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
|
|
|
fn boolean() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[miri_run]
|
2015-11-19 03:23:50 -06:00
|
|
|
fn if_false() -> i32 {
|
|
|
|
if false { 1 } else { 0 }
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
2015-11-19 03:23:50 -06:00
|
|
|
fn if_true() -> i32 {
|
|
|
|
if true { 1 } else { 0 }
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(2)")]
|
|
|
|
// fn call() -> i32 {
|
|
|
|
// fn increment(x: i32) -> i32 {
|
|
|
|
// x + 1
|
|
|
|
// }
|
2015-11-19 07:07:47 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// increment(1)
|
|
|
|
// }
|
2015-11-19 07:07:47 -06:00
|
|
|
|
2016-01-15 16:04:32 -06:00
|
|
|
// #[miri_run(expected = "Int(3628800)")]
|
|
|
|
// fn factorial_loop() -> i32 {
|
|
|
|
// let mut product = 1;
|
|
|
|
// let mut i = 1;
|
2015-11-19 07:10:17 -06:00
|
|
|
|
2016-01-15 16:04:32 -06:00
|
|
|
// while i <= 10 {
|
|
|
|
// product *= i;
|
|
|
|
// i += 1;
|
|
|
|
// }
|
2015-11-19 07:10:17 -06:00
|
|
|
|
2016-01-15 16:04:32 -06:00
|
|
|
// product
|
|
|
|
// }
|
2015-11-19 07:10:17 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(3628800)")]
|
|
|
|
// fn factorial_recursive() -> i32 {
|
|
|
|
// fn fact(n: i32) -> i32 {
|
|
|
|
// if n == 0 {
|
|
|
|
// 1
|
|
|
|
// } else {
|
|
|
|
// n * fact(n - 1)
|
|
|
|
// }
|
|
|
|
// }
|
2015-11-19 07:10:17 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// fact(10)
|
|
|
|
// }
|
2015-11-19 07:10:17 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run]
|
|
|
|
// fn match_bool() -> i32 {
|
|
|
|
// let b = true;
|
|
|
|
// match b {
|
|
|
|
// true => 1,
|
|
|
|
// false => 0,
|
|
|
|
// }
|
|
|
|
// }
|
2015-11-19 16:49:13 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
#[miri_run]
|
2015-11-19 16:49:13 -06:00
|
|
|
fn match_int() -> i32 {
|
|
|
|
let n = 2;
|
|
|
|
match n {
|
|
|
|
0 => 0,
|
|
|
|
1 => 10,
|
|
|
|
2 => 20,
|
|
|
|
3 => 30,
|
|
|
|
_ => 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(1)")]
|
|
|
|
// fn one_line_ref() -> i32 {
|
|
|
|
// *&1
|
|
|
|
// }
|
2015-12-28 22:24:05 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(1)")]
|
|
|
|
// fn basic_ref() -> i32 {
|
|
|
|
// let x = &1;
|
|
|
|
// *x
|
|
|
|
// }
|
2015-12-28 22:24:05 -06:00
|
|
|
|
2016-01-15 16:04:32 -06:00
|
|
|
// #[miri_run(expected = "Int(3)")]
|
2016-03-07 08:27:19 -06:00
|
|
|
// fn basic_ref_mut() -> i32 {
|
|
|
|
// let x = &mut 1;
|
|
|
|
// *x += 2;
|
|
|
|
// *x
|
2016-01-15 16:04:32 -06:00
|
|
|
// }
|
2015-12-28 22:24:05 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// // #[miri_run(expected = "Int(3)")]
|
|
|
|
// // fn basic_ref_mut_var() -> i32 {
|
|
|
|
// // let mut a = 1;
|
|
|
|
// // {
|
|
|
|
// // let x = &mut a;
|
|
|
|
// // *x += 2;
|
|
|
|
// // }
|
|
|
|
// // a
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// #[miri_run(expected = "Int(4)")]
|
|
|
|
// fn match_int_range() -> i32 {
|
|
|
|
// let n = 42;
|
|
|
|
// match n {
|
|
|
|
// 0...9 => 0,
|
|
|
|
// 10...19 => 1,
|
|
|
|
// 20...29 => 2,
|
|
|
|
// 30...39 => 3,
|
|
|
|
// 40...49 => 4,
|
|
|
|
// _ => 5,
|
|
|
|
// }
|
|
|
|
// }
|
2015-11-21 01:31:09 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// enum MyOption<T> {
|
|
|
|
// Some { data: T },
|
|
|
|
// None,
|
|
|
|
// }
|
2015-11-21 01:31:09 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(13)")]
|
|
|
|
// fn match_my_opt_some() -> i32 {
|
|
|
|
// let x = MyOption::Some { data: 13 };
|
|
|
|
// match x {
|
|
|
|
// MyOption::Some { data } => data,
|
|
|
|
// MyOption::None => 42,
|
|
|
|
// }
|
|
|
|
// }
|
2015-12-28 22:04:34 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(42)")]
|
|
|
|
// fn match_my_opt_none() -> i32 {
|
|
|
|
// let x = MyOption::None;
|
|
|
|
// match x {
|
|
|
|
// MyOption::Some { data } => data,
|
|
|
|
// MyOption::None => 42,
|
|
|
|
// }
|
|
|
|
// }
|
2015-12-17 14:03:26 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// #[miri_run(expected = "Int(13)")]
|
|
|
|
// fn match_opt_some() -> i32 {
|
|
|
|
// let x = Some(13);
|
|
|
|
// match x {
|
|
|
|
// Some(data) => data,
|
|
|
|
// None => 42,
|
|
|
|
// }
|
|
|
|
// }
|
2015-12-17 14:03:01 -06:00
|
|
|
|
2016-03-07 08:27:19 -06:00
|
|
|
// /// Test calling a very simple function from the standard library.
|
|
|
|
// #[miri_run(expected = "Int(1)")]
|
|
|
|
// fn cross_crate_fn_call() -> i32 {
|
|
|
|
// if 1i32.is_positive() { 1 } else { 0 }
|
|
|
|
// }
|