Skip to content

Commit 1517a41

Browse files
committed
Add test cases and test for HELP
1 parent 330be17 commit 1517a41

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

tests/ui/lint/type-overflow.rs

+26
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,46 @@
33

44
fn main() {
55
let error = 255i8; //~WARNING literal out of range for `i8`
6+
//~^ HELP consider using the type `u8` instead
67

78
let ok = 0b1000_0001; // should be ok -> i32
89
let ok = 0b0111_1111i8; // should be ok -> 127i8
910

1011
let fail = 0b1000_0001i8; //~WARNING literal out of range for `i8`
12+
//~^ HELP consider using the type `u8` instead
13+
//~| HELP consider using the type `u8` for the literal and cast it to `i8`
1114

1215
let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for `i64`
16+
//~^ HELP consider using the type `u64` instead
17+
//~| HELP consider using the type `u64` for the literal and cast it to `i64`
1318

1419
let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for `u32`
20+
//~^ HELP consider using the type `u64` instead
1521

1622
let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
1723
//~^ WARNING literal out of range for `i128`
24+
//~| HELP consider using the type `u128` instead
25+
//~| HELP consider using the type `u128` for the literal and cast it to `i128`
26+
27+
let fail = 0x8000_0000_0000_0000_0000_0000_0000_0000;
28+
//~^ WARNING literal out of range for `i32`
29+
//~| HELP consider using the type `u128` instead
30+
31+
let fail = -0x8000_0000_0000_0000_0000_0000_0000_0000;
32+
//~^ WARNING literal out of range for `i32`
33+
//~| HELP consider using the type `i128` instead
34+
35+
let fail = -0x8000_0000_0000_0000_0000_0000_0000_0001i128;
36+
//~^ WARNING literal out of range for `i128`
37+
38+
let fail = 340282366920938463463374607431768211455i8;
39+
//~^ WARNING literal out of range for `i8`
40+
//~| HELP consider using the type `u128` instead
1841

1942
let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for `i32`
43+
//~| HELP consider using the type `i128` instead
44+
//~| HELP
2045

2146
let fail = -0b1111_1111i8; //~WARNING literal out of range for `i8`
47+
//~| HELP consider using the type `i16` instead
2248
}

tests/ui/lint/type-overflow.stderr

+44-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![warn(overflowing_literals)]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: literal out of range for `i8`
16-
--> $DIR/type-overflow.rs:10:16
16+
--> $DIR/type-overflow.rs:11:16
1717
|
1818
LL | let fail = 0b1000_0001i8;
1919
| ^^^^^^^^^^^^^
@@ -29,7 +29,7 @@ LL | let fail = 0b1000_0001u8 as i8;
2929
| ~~~~~~~~~~~~~~~~~~~
3030

3131
warning: literal out of range for `i64`
32-
--> $DIR/type-overflow.rs:12:16
32+
--> $DIR/type-overflow.rs:15:16
3333
|
3434
LL | let fail = 0x8000_0000_0000_0000i64;
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -45,15 +45,15 @@ LL | let fail = 0x8000_0000_0000_0000u64 as i64;
4545
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4646

4747
warning: literal out of range for `u32`
48-
--> $DIR/type-overflow.rs:14:16
48+
--> $DIR/type-overflow.rs:19:16
4949
|
5050
LL | let fail = 0x1_FFFF_FFFFu32;
5151
| ^^^^^^^^^^^^^^^^ help: consider using the type `u64` instead: `0x1_FFFF_FFFFu64`
5252
|
5353
= note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into the type `u32` and will become `4294967295u32`
5454

5555
warning: literal out of range for `i128`
56-
--> $DIR/type-overflow.rs:16:22
56+
--> $DIR/type-overflow.rs:22:22
5757
|
5858
LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,44 @@ LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000u128 as i128;
6666
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6767

6868
warning: literal out of range for `i32`
69-
--> $DIR/type-overflow.rs:19:16
69+
--> $DIR/type-overflow.rs:27:16
70+
|
71+
LL | let fail = 0x8000_0000_0000_0000_0000_0000_0000_0000;
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
|
74+
= note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into the type `i32` and will become `0i32`
75+
= help: consider using the type `u128` instead
76+
77+
warning: literal out of range for `i32`
78+
--> $DIR/type-overflow.rs:31:17
79+
|
80+
LL | let fail = -0x8000_0000_0000_0000_0000_0000_0000_0000;
81+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
|
83+
= note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into the type `i32`
84+
= note: and the value `-0x8000_0000_0000_0000_0000_0000_0000_0000` will become `0i32`
85+
= help: consider using the type `i128` instead
86+
87+
warning: literal out of range for `i128`
88+
--> $DIR/type-overflow.rs:35:17
89+
|
90+
LL | let fail = -0x8000_0000_0000_0000_0000_0000_0000_0001i128;
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92+
|
93+
= note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0001i128` (decimal `170141183460469231731687303715884105729`) does not fit into the type `i128`
94+
= note: and the value `-0x8000_0000_0000_0000_0000_0000_0000_0001i128` will become `170141183460469231731687303715884105727i128`
95+
96+
warning: literal out of range for `i8`
97+
--> $DIR/type-overflow.rs:38:16
98+
|
99+
LL | let fail = 340282366920938463463374607431768211455i8;
100+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101+
|
102+
= note: the literal `340282366920938463463374607431768211455i8` does not fit into the type `i8` whose range is `-128..=127`
103+
= help: consider using the type `u128` instead
104+
105+
warning: literal out of range for `i32`
106+
--> $DIR/type-overflow.rs:42:16
70107
|
71108
LL | let fail = 0x8FFF_FFFF_FFFF_FFFE;
72109
| ^^^^^^^^^^^^^^^^^^^^^
@@ -79,13 +116,13 @@ LL | let fail = 0x8FFF_FFFF_FFFF_FFFEu32 as i32;
79116
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80117

81118
warning: literal out of range for `i8`
82-
--> $DIR/type-overflow.rs:21:17
119+
--> $DIR/type-overflow.rs:46:17
83120
|
84121
LL | let fail = -0b1111_1111i8;
85122
| ^^^^^^^^^^^^^ help: consider using the type `i16` instead: `0b1111_1111i16`
86123
|
87124
= note: the literal `0b1111_1111i8` (decimal `255`) does not fit into the type `i8`
88125
= note: and the value `-0b1111_1111i8` will become `1i8`
89126

90-
warning: 7 warnings emitted
127+
warning: 11 warnings emitted
91128

0 commit comments

Comments
 (0)