2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
#![allow(overflowing_literals)]
|
|
|
|
|
2012-02-22 05:01:33 +00:00
|
|
|
// Testing shifts for various combinations of integers
|
|
|
|
// Issue #1570
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2012-02-22 05:01:33 +00:00
|
|
|
test_misc();
|
|
|
|
test_expr();
|
|
|
|
test_const();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_misc() {
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(1 << 1 << 1 << 1 << 1 << 1, 32);
|
2012-02-22 05:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_expr() {
|
2015-03-26 00:06:52 +00:00
|
|
|
let v10 = 10 as usize;
|
2012-02-22 05:01:33 +00:00
|
|
|
let v4 = 4 as u8;
|
|
|
|
let v2 = 2 as u8;
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(v10 >> v2 as usize, v2 as usize);
|
|
|
|
assert_eq!(v10 << v4 as usize, 160 as usize);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
|
|
|
let v10 = 10 as u8;
|
2015-03-26 00:06:52 +00:00
|
|
|
let v4 = 4 as usize;
|
|
|
|
let v2 = 2 as usize;
|
|
|
|
assert_eq!(v10 >> v2 as usize, v2 as u8);
|
|
|
|
assert_eq!(v10 << v4 as usize, 160 as u8);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
let v10 = 10 as isize;
|
2012-02-22 05:01:33 +00:00
|
|
|
let v4 = 4 as i8;
|
|
|
|
let v2 = 2 as i8;
|
2015-03-26 00:06:52 +00:00
|
|
|
assert_eq!(v10 >> v2 as usize, v2 as isize);
|
|
|
|
assert_eq!(v10 << v4 as usize, 160 as isize);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
|
|
|
let v10 = 10 as i8;
|
2015-03-26 00:06:52 +00:00
|
|
|
let v4 = 4 as isize;
|
|
|
|
let v2 = 2 as isize;
|
|
|
|
assert_eq!(v10 >> v2 as usize, v2 as i8);
|
|
|
|
assert_eq!(v10 << v4 as usize, 160 as i8);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
let v10 = 10 as usize;
|
|
|
|
let v4 = 4 as isize;
|
|
|
|
let v2 = 2 as isize;
|
|
|
|
assert_eq!(v10 >> v2 as usize, v2 as usize);
|
|
|
|
assert_eq!(v10 << v4 as usize, 160 as usize);
|
2012-02-22 05:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_const() {
|
2015-03-26 00:06:52 +00:00
|
|
|
static r1_1: usize = 10_usize >> 2_usize;
|
|
|
|
static r2_1: usize = 10_usize << 4_usize;
|
|
|
|
assert_eq!(r1_1, 2 as usize);
|
|
|
|
assert_eq!(r2_1, 160 as usize);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
2015-02-18 10:42:01 +00:00
|
|
|
static r1_2: u8 = 10u8 >> 2_usize;
|
|
|
|
static r2_2: u8 = 10u8 << 4_usize;
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(r1_2, 2 as u8);
|
|
|
|
assert_eq!(r2_2, 160 as u8);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
static r1_3: isize = 10 >> 2_usize;
|
|
|
|
static r2_3: isize = 10 << 4_usize;
|
|
|
|
assert_eq!(r1_3, 2 as isize);
|
|
|
|
assert_eq!(r2_3, 160 as isize);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
2015-02-18 10:42:01 +00:00
|
|
|
static r1_4: i8 = 10i8 >> 2_usize;
|
|
|
|
static r2_4: i8 = 10i8 << 4_usize;
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(r1_4, 2 as i8);
|
|
|
|
assert_eq!(r2_4, 160 as i8);
|
2012-02-22 05:01:33 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
static r1_5: usize = 10_usize >> 2_usize;
|
|
|
|
static r2_5: usize = 10_usize << 4_usize;
|
|
|
|
assert_eq!(r1_5, 2 as usize);
|
|
|
|
assert_eq!(r2_5, 160 as usize);
|
2012-02-22 05:01:33 +00:00
|
|
|
}
|