Skip to content

Commit 4567f22

Browse files
committed
remove useless ident() functions in const tests and replace the useful ones by black_box (with a comment)
1 parent 6312b89 commit 4567f22

7 files changed

+57
-72
lines changed

src/test/run-pass/const-int-conversion.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
88
const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
99
const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
1010

11-
fn ident<T>(ident: T) -> T {
12-
ident
13-
}
14-
1511
fn main() {
16-
assert_eq!(REVERSE, ident(0x1e6a2c48));
17-
assert_eq!(FROM_BE_BYTES, ident(0x12_34_56_78));
18-
assert_eq!(FROM_LE_BYTES, ident(0x78_56_34_12));
19-
assert_eq!(FROM_NE_BYTES, ident(i32::min_value()));
20-
assert_eq!(TO_BE_BYTES, ident([0x12, 0x34, 0x56, 0x78]));
21-
assert_eq!(TO_LE_BYTES, ident([0x78, 0x56, 0x34, 0x12]));
22-
assert_eq!(TO_NE_BYTES, ident([0x80, 0, 0, 0]));
12+
assert_eq!(REVERSE, 0x1e6a2c48);
13+
assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
14+
assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
15+
assert_eq!(FROM_NE_BYTES, i32::min_value());
16+
assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
17+
assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
18+
assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
2319
}

src/test/run-pass/const-int-overflowing.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
1616
const NEG_A: (u32, bool) = 0u32.overflowing_neg();
1717
const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
1818

19-
fn ident<T>(ident: T) -> T {
20-
ident
21-
}
22-
2319
fn main() {
24-
assert_eq!(ADD_A, ident((7, false)));
25-
assert_eq!(ADD_B, ident((0, true)));
20+
assert_eq!(ADD_A, (7, false));
21+
assert_eq!(ADD_B, (0, true));
2622

27-
assert_eq!(SUB_A, ident((3, false)));
28-
assert_eq!(SUB_B, ident((u32::max_value(), true)));
23+
assert_eq!(SUB_A, (3, false));
24+
assert_eq!(SUB_B, (u32::max_value(), true));
2925

30-
assert_eq!(MUL_A, ident((10, false)));
31-
assert_eq!(MUL_B, ident((1410065408, true)));
26+
assert_eq!(MUL_A, (10, false));
27+
assert_eq!(MUL_B, (1410065408, true));
3228

33-
assert_eq!(SHL_A, ident((0x10, false)));
34-
assert_eq!(SHL_B, ident((0x10, true)));
29+
assert_eq!(SHL_A, (0x10, false));
30+
assert_eq!(SHL_B, (0x10, true));
3531

36-
assert_eq!(SHR_A, ident((0x1, false)));
37-
assert_eq!(SHR_B, ident((0x1, true)));
32+
assert_eq!(SHR_A, (0x1, false));
33+
assert_eq!(SHR_B, (0x1, true));
3834

39-
assert_eq!(NEG_A, ident((0, false)));
40-
assert_eq!(NEG_B, ident((1, true)));
35+
assert_eq!(NEG_A, (0, false));
36+
assert_eq!(NEG_B, (1, true));
4137
}

src/test/run-pass/const-int-rotate.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,21 @@ const ZERO_ROTATE_RIGHT: i8 = 0b0111_1001i8.rotate_right(0);
2121
const MULTIPLE_ROTATE_LEFT: i32 = 0b0010_0001i32.rotate_left(128);
2222
const MULTIPLE_ROTATE_RIGHT: i32 = 0b0010_0001i32.rotate_right(128);
2323

24-
fn ident<T>(ident: T) -> T {
25-
ident
26-
}
27-
2824
fn main() {
29-
assert_eq!(LEFT, ident(0xb301));
30-
assert_eq!(RIGHT, ident(0x0100_00b3));
25+
assert_eq!(LEFT, 0xb301);
26+
assert_eq!(RIGHT, 0x0100_00b3);
3127

32-
assert_eq!(LEFT_OVERFLOW, ident(0));
33-
assert_eq!(RIGHT_OVERFLOW, ident(0));
34-
assert_eq!(ONE_LEFT_OVERFLOW, ident(0b0001_0000_0000_0000));
35-
assert_eq!(ONE_RIGHT_OVERFLOW, ident(0b0001_0000));
28+
assert_eq!(LEFT_OVERFLOW, 0);
29+
assert_eq!(RIGHT_OVERFLOW, 0);
30+
assert_eq!(ONE_LEFT_OVERFLOW, 0b0001_0000_0000_0000);
31+
assert_eq!(ONE_RIGHT_OVERFLOW, 0b0001_0000);
3632

37-
assert_eq!(NON_ZERO_LEFT_OVERFLOW, ident(0b0010_0000_0000_0000));
38-
assert_eq!(NON_ZERO_RIGHT_OVERFLOW, ident(0b0000_0000_0010_0000));
33+
assert_eq!(NON_ZERO_LEFT_OVERFLOW, 0b0010_0000_0000_0000);
34+
assert_eq!(NON_ZERO_RIGHT_OVERFLOW, 0b0000_0000_0010_0000);
3935

40-
assert_eq!(ZERO_ROTATE_LEFT, ident(0b0010_0001));
41-
assert_eq!(ZERO_ROTATE_RIGHT, ident(0b0111_1001));
36+
assert_eq!(ZERO_ROTATE_LEFT, 0b0010_0001);
37+
assert_eq!(ZERO_ROTATE_RIGHT, 0b0111_1001);
4238

43-
assert_eq!(MULTIPLE_ROTATE_LEFT, ident(0b0010_0001));
44-
assert_eq!(MULTIPLE_ROTATE_RIGHT, ident(0b0010_0001));
39+
assert_eq!(MULTIPLE_ROTATE_LEFT, 0b0010_0001);
40+
assert_eq!(MULTIPLE_ROTATE_RIGHT, 0b0010_0001);
4541
}

src/test/run-pass/const-int-wrapping.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ const SHR_B: u32 = 128u32.wrapping_shr(128);
1616
const NEG_A: u32 = 5u32.wrapping_neg();
1717
const NEG_B: u32 = 1234567890u32.wrapping_neg();
1818

19-
fn ident<T>(ident: T) -> T {
20-
ident
21-
}
22-
2319
fn main() {
24-
assert_eq!(ADD_A, ident(255));
25-
assert_eq!(ADD_B, ident(199));
20+
assert_eq!(ADD_A, 255);
21+
assert_eq!(ADD_B, 199);
2622

27-
assert_eq!(SUB_A, ident(0));
28-
assert_eq!(SUB_B, ident(101));
23+
assert_eq!(SUB_A, 0);
24+
assert_eq!(SUB_B, 101);
2925

30-
assert_eq!(MUL_A, ident(120));
31-
assert_eq!(MUL_B, ident(44));
26+
assert_eq!(MUL_A, 120);
27+
assert_eq!(MUL_B, 44);
3228

33-
assert_eq!(SHL_A, ident(128));
34-
assert_eq!(SHL_B, ident(1));
29+
assert_eq!(SHL_A, 128);
30+
assert_eq!(SHL_B, 1);
3531

36-
assert_eq!(SHR_A, ident(1));
37-
assert_eq!(SHR_B, ident(128));
32+
assert_eq!(SHR_A, 1);
33+
assert_eq!(SHR_B, 128);
3834

39-
assert_eq!(NEG_A, ident(4294967291));
40-
assert_eq!(NEG_B, ident(3060399406));
35+
assert_eq!(NEG_A, 4294967291);
36+
assert_eq!(NEG_B, 3060399406);
4137
}

src/test/run-pass/consts/const-endianess.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(test)]
33

44
extern crate test;
5-
use test::black_box as b;
5+
use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
66

77
const BE_U32: u32 = 55u32.to_be();
88
const LE_U32: u32 = 55u32.to_le();
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// run-pass
22

3+
#![feature(ptr_internals, test)]
4+
5+
extern crate test;
6+
use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
7+
38
use std::ptr::NonNull;
49

510
const DANGLING: NonNull<u32> = NonNull::dangling();
611
const CASTED: NonNull<u32> = NonNull::cast(NonNull::<i32>::dangling());
712

8-
fn ident<T>(ident: T) -> T {
9-
ident
10-
}
11-
1213
pub fn main() {
13-
assert_eq!(DANGLING, ident(NonNull::dangling()));
14-
assert_eq!(CASTED, ident(NonNull::dangling()));
14+
assert_eq!(DANGLING, b(NonNull::dangling()));
15+
assert_eq!(CASTED, b(NonNull::dangling()));
1516
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// run-pass
22

3-
#![feature(ptr_internals)]
3+
#![feature(ptr_internals, test)]
4+
5+
extern crate test;
6+
use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
47

58
use std::ptr::Unique;
69

7-
const PTR: *mut u32 = Unique::empty().as_ptr();
810

9-
fn ident<T>(ident: T) -> T {
10-
ident
11-
}
11+
const PTR: *mut u32 = Unique::empty().as_ptr();
1212

1313
pub fn main() {
14-
assert_eq!(PTR, ident(Unique::<u32>::empty().as_ptr()));
14+
assert_eq!(PTR, b(Unique::<u32>::empty()).as_ptr());
1515
}

0 commit comments

Comments
 (0)