2018-07-27 12:27:20 -05:00
|
|
|
#![feature(no_core, unboxed_closures)]
|
2018-06-17 11:05:11 -05:00
|
|
|
#![no_core]
|
2018-07-18 06:43:17 -05:00
|
|
|
#![allow(dead_code)]
|
2018-06-17 11:05:11 -05:00
|
|
|
|
2018-07-24 07:10:53 -05:00
|
|
|
extern crate mini_core;
|
2018-06-17 11:05:11 -05:00
|
|
|
|
2018-07-24 07:10:53 -05:00
|
|
|
use mini_core::*;
|
2018-07-20 07:20:37 -05:00
|
|
|
|
2018-06-27 08:23:40 -05:00
|
|
|
fn abc(a: u8) -> u8 {
|
2018-06-17 11:05:11 -05:00
|
|
|
a * 2
|
|
|
|
}
|
|
|
|
|
2018-06-27 08:23:40 -05:00
|
|
|
fn bcd(b: bool, a: u8) -> u8 {
|
2018-06-17 11:05:11 -05:00
|
|
|
if b {
|
|
|
|
a * 2
|
|
|
|
} else {
|
|
|
|
a * 3
|
|
|
|
}
|
2018-06-20 08:15:28 -05:00
|
|
|
}
|
2018-06-17 12:10:00 -05:00
|
|
|
|
2018-07-18 06:43:17 -05:00
|
|
|
fn call() {
|
2018-06-17 12:10:00 -05:00
|
|
|
abc(42);
|
|
|
|
}
|
2018-06-18 11:39:07 -05:00
|
|
|
|
|
|
|
fn indirect_call() {
|
|
|
|
let f: fn() = call;
|
|
|
|
f();
|
2018-07-18 06:43:17 -05:00
|
|
|
}
|
2018-06-23 11:26:54 -05:00
|
|
|
|
|
|
|
enum BoolOption {
|
|
|
|
Some(bool),
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn option_unwrap_or(o: BoolOption, d: bool) -> bool {
|
|
|
|
match o {
|
|
|
|
BoolOption::Some(b) => b,
|
|
|
|
BoolOption::None => d,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 08:23:40 -05:00
|
|
|
fn ret_42() -> u8 {
|
2018-06-23 11:26:54 -05:00
|
|
|
42
|
2018-06-18 11:39:07 -05:00
|
|
|
}
|
2018-07-14 09:39:49 -05:00
|
|
|
|
|
|
|
fn return_str() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn promoted_val() -> &'static u8 {
|
|
|
|
&(1 * 2)
|
|
|
|
}
|
2018-07-18 07:21:13 -05:00
|
|
|
|
|
|
|
fn cast_ref_to_raw_ptr(abc: &u8) -> *const u8 {
|
|
|
|
abc as *const u8
|
|
|
|
}
|
2018-07-18 08:17:22 -05:00
|
|
|
|
|
|
|
fn cmp_raw_ptr(a: *const u8, b: *const u8) -> bool {
|
|
|
|
a == b
|
|
|
|
}
|
2018-07-18 09:22:29 -05:00
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
|
2018-07-18 09:22:29 -05:00
|
|
|
(
|
2018-07-31 05:25:16 -05:00
|
|
|
a as u8, a as u16, a as u32, a as usize, a as i8, a as i16, a as i32, a as isize, b as u8,
|
|
|
|
b as u32,
|
2018-07-18 09:22:29 -05:00
|
|
|
)
|
2018-12-22 10:42:38 -06:00
|
|
|
}
|
2018-07-18 10:07:10 -05:00
|
|
|
|
2018-07-19 12:37:34 -05:00
|
|
|
fn char_cast(c: char) -> u8 {
|
|
|
|
c as u8
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
pub struct DebugTuple(());
|
2018-07-18 10:07:10 -05:00
|
|
|
|
|
|
|
fn debug_tuple() -> DebugTuple {
|
|
|
|
DebugTuple(())
|
|
|
|
}
|
2018-07-20 07:20:37 -05:00
|
|
|
|
2018-07-21 11:38:08 -05:00
|
|
|
fn size_of<T>() -> usize {
|
2019-02-06 11:49:59 -06:00
|
|
|
intrinsics::size_of::<T>()
|
2018-07-21 11:38:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn use_size_of() -> usize {
|
|
|
|
size_of::<u64>()
|
2018-07-20 07:20:37 -05:00
|
|
|
}
|
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) {
|
2018-07-21 11:38:08 -05:00
|
|
|
intrinsics::copy::<u8>(src, dst, 1);
|
2018-12-22 10:42:38 -06:00
|
|
|
}
|
2018-07-21 11:38:08 -05:00
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) {
|
|
|
|
let copy2 = &intrinsics::copy::<u8>;
|
2018-07-20 07:20:37 -05:00
|
|
|
copy2(src, dst, 1);
|
2018-12-22 10:42:38 -06:00
|
|
|
}
|
2018-07-21 11:44:34 -05:00
|
|
|
|
2019-02-06 11:49:59 -06:00
|
|
|
const ABC: u8 = 6 * 7;
|
2018-07-21 11:44:34 -05:00
|
|
|
|
|
|
|
fn use_const() -> u8 {
|
2019-02-06 11:49:59 -06:00
|
|
|
ABC
|
2018-07-21 11:44:34 -05:00
|
|
|
}
|
2018-07-20 06:38:49 -05:00
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
pub fn call_closure_3arg() {
|
2018-07-31 05:25:16 -05:00
|
|
|
(|_, _, _| {})(0u8, 42u16, 0u8)
|
2018-07-27 12:01:38 -05:00
|
|
|
}
|
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
pub fn call_closure_2arg() {
|
2018-07-31 05:25:16 -05:00
|
|
|
(|_, _| {})(0u8, 42u16)
|
2018-07-20 06:38:49 -05:00
|
|
|
}
|
2018-07-26 03:48:50 -05:00
|
|
|
|
2018-07-27 12:27:20 -05:00
|
|
|
struct IsNotEmpty;
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
impl<'a, 'b> FnOnce<(&'a &'b [u16],)> for IsNotEmpty {
|
2018-12-22 10:42:38 -06:00
|
|
|
type Output = (u8, u8);
|
2018-07-27 12:27:20 -05:00
|
|
|
|
|
|
|
#[inline]
|
2018-12-22 10:42:38 -06:00
|
|
|
extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u16],)) -> (u8, u8) {
|
2018-07-27 12:27:20 -05:00
|
|
|
self.call_mut(arg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
impl<'a, 'b> FnMut<(&'a &'b [u16],)> for IsNotEmpty {
|
2018-07-27 12:27:20 -05:00
|
|
|
#[inline]
|
2019-02-06 11:49:59 -06:00
|
|
|
extern "rust-call" fn call_mut(&mut self, _arg: (&'a &'b [u16],)) -> (u8, u8) {
|
2018-12-22 10:42:38 -06:00
|
|
|
(0, 42)
|
2018-07-27 12:27:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
pub fn call_is_not_empty() {
|
|
|
|
IsNotEmpty.call_once((&(&[0u16] as &[_]),));
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:48:50 -05:00
|
|
|
fn eq_char(a: char, b: char) -> bool {
|
|
|
|
a == b
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn transmute(c: char) -> u32 {
|
|
|
|
intrinsics::transmute(c)
|
|
|
|
}
|
2018-07-29 10:22:40 -05:00
|
|
|
|
2018-08-22 08:38:10 -05:00
|
|
|
unsafe fn deref_str_ptr(s: *const str) -> &'static str {
|
2018-08-08 03:39:10 -05:00
|
|
|
&*s
|
2018-08-22 08:38:10 -05:00
|
|
|
}
|
2018-08-08 05:22:16 -05:00
|
|
|
|
|
|
|
fn use_array(arr: [u8; 3]) -> u8 {
|
|
|
|
arr[1]
|
|
|
|
}
|
2018-08-08 05:30:25 -05:00
|
|
|
|
|
|
|
fn repeat_array() -> [u8; 3] {
|
|
|
|
[0; 3]
|
|
|
|
}
|
2018-08-08 07:39:46 -05:00
|
|
|
|
2018-08-22 08:38:56 -05:00
|
|
|
fn array_as_slice(arr: &[u8; 3]) -> &[u8] {
|
|
|
|
arr
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
|
2018-08-08 07:39:46 -05:00
|
|
|
intrinsics::ctlz_nonzero(a)
|
2018-12-22 10:42:38 -06:00
|
|
|
}
|
2018-08-09 04:07:10 -05:00
|
|
|
|
|
|
|
fn ptr_as_usize(ptr: *const u8) -> usize {
|
|
|
|
ptr as usize
|
|
|
|
}
|
2018-08-09 04:16:46 -05:00
|
|
|
|
|
|
|
fn float_cast(a: f32, b: f64) -> (f64, f32) {
|
|
|
|
(a as f64, b as f32)
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:42:38 -06:00
|
|
|
fn int_to_float(a: u8, b: i32) -> (f64, f32) {
|
2018-08-09 04:16:46 -05:00
|
|
|
(a as f64, b as f32)
|
2018-12-22 10:42:38 -06:00
|
|
|
}
|
2018-08-09 04:41:34 -05:00
|
|
|
|
|
|
|
fn make_array() -> [u8; 3] {
|
|
|
|
[42, 0, 5]
|
|
|
|
}
|
2018-08-13 08:56:01 -05:00
|
|
|
|
|
|
|
fn some_promoted_tuple() -> &'static (&'static str, &'static str) {
|
|
|
|
&("abc", "some")
|
|
|
|
}
|
2018-08-25 04:22:48 -05:00
|
|
|
|
|
|
|
fn index_slice(s: &[u8]) -> u8 {
|
|
|
|
s[2]
|
|
|
|
}
|
2018-09-16 08:28:27 -05:00
|
|
|
|
|
|
|
pub struct StrWrapper {
|
|
|
|
s: str,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn str_wrapper_get(w: &StrWrapper) -> &str {
|
|
|
|
&w.s
|
|
|
|
}
|
2018-09-30 09:33:55 -05:00
|
|
|
|
|
|
|
fn i16_as_i8(a: i16) -> i8 {
|
|
|
|
a as i8
|
|
|
|
}
|
2018-10-06 04:21:18 -05:00
|
|
|
|
|
|
|
struct Unsized(u8, str);
|
|
|
|
|
|
|
|
fn get_sized_field_ref_from_unsized_type(u: &Unsized) -> &u8 {
|
|
|
|
&u.0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_unsized_field_ref_from_unsized_type(u: &Unsized) -> &str {
|
|
|
|
&u.1
|
|
|
|
}
|
2019-08-30 08:41:33 -05:00
|
|
|
|
|
|
|
pub fn reuse_byref_argument_storage(a: (u8, u16, u32)) -> u8 {
|
|
|
|
a.0
|
|
|
|
}
|