Skip to content

Commit 8b3d207

Browse files
committed
Only run tests if pointer width is 64bit
If the pointer width of the architechture is 32bit or something else, then the tests will most likely produce different results.
1 parent 391d53d commit 8b3d207

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

tests/ui/fn_to_numeric_cast_with_truncation.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// only-64bit
12
#![feature(tool_lints)]
23

34
#![warn(clippy::fn_to_numeric_cast_with_truncation)]
@@ -13,11 +14,12 @@ fn test_fn_to_numeric_cast_with_truncation() {
1314
let _ = foo as u16;
1415
let _ = foo as u32;
1516

16-
// TODO: Is it bad to have these tests?
17-
// Running the tests on a different architechture will
18-
// produce different results
17+
// These should not lint, because because casting to these types
18+
// does not truncate the function pointer address.
1919
let _ = foo as u64;
2020
let _ = foo as i64;
21+
let _ = foo as u128;
22+
let _ = foo as i128;
2123
}
2224

2325
fn main() {}

tests/ui/fn_to_numeric_cast_with_truncation.stderr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
error: casting function pointer `foo` to `i8`, which truncates the value
2-
--> $DIR/fn_to_numeric_cast_with_truncation.rs:9:13
3-
|
4-
9 | let _ = foo as i8;
5-
| ^^^^^^^^^ help: try: `foo as usize`
6-
|
7-
= note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings`
2+
--> $DIR/fn_to_numeric_cast_with_truncation.rs:10:13
3+
|
4+
10 | let _ = foo as i8;
5+
| ^^^^^^^^^ help: try: `foo as usize`
6+
|
7+
= note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings`
88

99
error: casting function pointer `foo` to `i16`, which truncates the value
10-
--> $DIR/fn_to_numeric_cast_with_truncation.rs:10:13
10+
--> $DIR/fn_to_numeric_cast_with_truncation.rs:11:13
1111
|
12-
10 | let _ = foo as i16;
12+
11 | let _ = foo as i16;
1313
| ^^^^^^^^^^ help: try: `foo as usize`
1414

1515
error: casting function pointer `foo` to `i32`, which truncates the value
16-
--> $DIR/fn_to_numeric_cast_with_truncation.rs:11:13
16+
--> $DIR/fn_to_numeric_cast_with_truncation.rs:12:13
1717
|
18-
11 | let _ = foo as i32;
18+
12 | let _ = foo as i32;
1919
| ^^^^^^^^^^ help: try: `foo as usize`
2020

2121
error: casting function pointer `foo` to `u8`, which truncates the value
22-
--> $DIR/fn_to_numeric_cast_with_truncation.rs:12:13
22+
--> $DIR/fn_to_numeric_cast_with_truncation.rs:13:13
2323
|
24-
12 | let _ = foo as u8;
24+
13 | let _ = foo as u8;
2525
| ^^^^^^^^^ help: try: `foo as usize`
2626

2727
error: casting function pointer `foo` to `u16`, which truncates the value
28-
--> $DIR/fn_to_numeric_cast_with_truncation.rs:13:13
28+
--> $DIR/fn_to_numeric_cast_with_truncation.rs:14:13
2929
|
30-
13 | let _ = foo as u16;
30+
14 | let _ = foo as u16;
3131
| ^^^^^^^^^^ help: try: `foo as usize`
3232

3333
error: casting function pointer `foo` to `u32`, which truncates the value
34-
--> $DIR/fn_to_numeric_cast_with_truncation.rs:14:13
34+
--> $DIR/fn_to_numeric_cast_with_truncation.rs:15:13
3535
|
36-
14 | let _ = foo as u32;
36+
15 | let _ = foo as u32;
3737
| ^^^^^^^^^^ help: try: `foo as usize`
3838

3939
error: aborting due to 6 previous errors

0 commit comments

Comments
 (0)