rust/example.rs

87 lines
1.3 KiB
Rust
Raw Normal View History

2018-06-17 16:05:11 +00:00
#![feature(no_core, lang_items)]
#![no_core]
#[lang="sized"]
trait Sized {}
#[lang="copy"]
trait Copy {}
#[lang="freeze"]
trait Freeze {}
#[lang="mul"]
trait Mul<RHS = Self> {
type Output;
#[must_use]
fn mul(self, rhs: RHS) -> Self::Output;
}
impl Mul for u8 {
type Output = Self;
2018-06-17 16:05:11 +00:00
fn mul(self, rhs: Self) -> Self {
2018-06-17 16:05:11 +00:00
self * rhs
}
}
#[lang="panic"]
fn panic(_expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
loop {}
}
2018-06-23 16:26:54 +00:00
#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
// Code here does not matter - this is replaced by the
// real drop glue by the compiler.
drop_in_place(to_drop);
}
fn abc(a: u8) -> u8 {
2018-06-17 16:05:11 +00:00
a * 2
}
fn bcd(b: bool, a: u8) -> u8 {
2018-06-17 16:05:11 +00:00
if b {
a * 2
} else {
a * 3
}
}
2018-06-17 17:10:00 +00:00
2018-06-23 16:26:54 +00:00
// FIXME make calls work
/*fn call() {
2018-06-17 17:10:00 +00:00
abc(42);
}
2018-06-18 16:39:07 +00:00
fn indirect_call() {
let f: fn() = call;
f();
2018-06-23 16:26:54 +00:00
}*/
enum BoolOption {
Some(bool),
None,
}
fn option_unwrap_or(o: BoolOption, d: bool) -> bool {
match o {
BoolOption::Some(b) => b,
BoolOption::None => d,
}
}
fn ret_42() -> u8 {
2018-06-23 16:26:54 +00:00
42
2018-06-18 16:39:07 +00:00
}
fn return_str() -> &'static str {
"hello world"
}
fn promoted_val() -> &'static u8 {
&(1 * 2)
}