diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2019-07-24 17:23:23 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2019-07-26 11:30:39 +0200 |
| commit | 7f5c2dab9dfcf128336422bcefded78a99ff1c42 (patch) | |
| tree | e0a1460bc3ba1c51f98e464ad38a2e5976790935 /example/std_example.rs | |
| parent | 5180becc7c11573d267166437abf3d9951c6b0c7 (diff) | |
| download | rust-7f5c2dab9dfcf128336422bcefded78a99ff1c42.tar.gz rust-7f5c2dab9dfcf128336422bcefded78a99ff1c42.zip | |
Remove some unnecessary changes
Diffstat (limited to 'example/std_example.rs')
| -rw-r--r-- | example/std_example.rs | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/example/std_example.rs b/example/std_example.rs index 465b6143525..bd51a37f29f 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -3,6 +3,65 @@ use std::io::Write; use std::intrinsics; +fn main() { + let _ = ::std::iter::repeat('a' as u8).take(10).collect::<Vec<_>>(); + let stderr = ::std::io::stderr(); + let mut stderr = stderr.lock(); + + writeln!(stderr, "some {} text", "<unknown>").unwrap(); + + let _ = std::process::Command::new("true").env("c", "d").spawn(); + + println!("cargo:rustc-link-lib=z"); + + static ONCE: std::sync::Once = std::sync::ONCE_INIT; + ONCE.call_once(|| {}); + + LoopState::Continue(()) == LoopState::Break(()); + + // Make sure ByValPair values with differently sized components are correctly passed + map(None::<(u8, Box<Instruction>)>); + + println!("{}", 2.3f32.exp()); + println!("{}", 2.3f32.exp2()); + println!("{}", 2.3f32.abs()); + println!("{}", 2.3f32.sqrt()); + println!("{}", 2.3f32.floor()); + println!("{}", 2.3f32.ceil()); + println!("{}", 2.3f32.min(1.0)); + println!("{}", 2.3f32.max(1.0)); + + assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26); + assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7); + + checked_div_i128(0i128, 2i128); + checked_div_u128(0u128, 2u128); + assert_eq!(1u128 + 2, 3); + + assert_eq!(0b100010000000000000000000000000000u128 >> 10, 0b10001000000000000000000u128); + assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 >> 64, 0xFEDCBA98765432u128); + assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64, 0xFEDCBA98765432i128); + assert_eq!(353985398u128 * 932490u128, 330087843781020u128); +} + +#[derive(PartialEq)] +enum LoopState { + Continue(()), + Break(()) +} + +pub enum Instruction { + Increment, + Loop, +} + +fn map(a: Option<(u8, Box<Instruction>)>) -> Option<Box<Instruction>> { + match a { + None => None, + Some((_, instr)) => Some(instr), + } +} + fn checked_div_i128(lhs: i128, rhs: i128) -> Option<i128> { if rhs == 0 || (lhs == -170141183460469231731687303715884105728 && rhs == -1) { None @@ -17,20 +76,3 @@ fn checked_div_u128(lhs: u128, rhs: u128) -> Option<u128> { rhs => Some(unsafe { intrinsics::unchecked_div(lhs, rhs) }) } } - -fn main() { - assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26); - assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7); - - checked_div_i128(0i128, 2i128); - checked_div_u128(0u128, 2u128); - assert_eq!(1u128 + 2, 3); - - // overflow panic - // 0xFEDCBA987654321123456789ABCDEFu128 + 0xFEDCBA987654321123456789ABCDEFu128; - - println!("{}", 0b100010000000000000000000000000000u128 >> 10); - println!("{}", 0xFEDCBA987654321123456789ABCDEFu128 >> 64); - println!("{} >> 64 == {}", 0xFEDCBA987654321123456789ABCDEFu128 as i128, 0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64); - println!("{}", 353985398u128 * 932490u128); -} |
