Skip to content

Commit 17d15c4

Browse files
committed
test: fix test case & add new one
Signed-off-by: 11happy <[email protected]>
1 parent 12be5bf commit 17d15c4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Diff for: tests/ui/lint/type-overflow.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ fn main() {
4141

4242
let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for `i32`
4343
//~| HELP consider using the type `u64` instead
44-
//~| HELP
44+
//~| HELP consider using the type `u64` for the literal and cast it to `i32`
4545

4646
let fail = -0b1111_1111i8; //~WARNING literal out of range for `i8`
4747
//~| HELP consider using the type `i16` instead
48+
49+
let fail = 0x8000_0000_0000_0000_0000_0000_FFFF_FFFE; //~WARNING literal out of range for `i32`
50+
//~| HELP consider using the type `u128` instead
51+
//~| HELP consider using the type `u128` for the literal and cast it to `i32`
4852
}

Diff for: tests/ui/lint/type-overflow.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ LL | let fail = 0x8FFF_FFFF_FFFF_FFFE;
110110
|
111111
= note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into the type `i32` and will become `-2i32`
112112
= help: consider using the type `u64` instead
113-
help: to use as a negative number (decimal `-2`), consider using the type `u32` for the literal and cast it to `i32`
113+
help: to use as a negative number (decimal `-2`), consider using the type `u64` for the literal and cast it to `i32`
114114
|
115-
LL | let fail = 0x8FFF_FFFF_FFFF_FFFEu32 as i32;
115+
LL | let fail = 0x8FFF_FFFF_FFFF_FFFEu64 as i32;
116116
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117117

118118
warning: literal out of range for `i8`
@@ -124,5 +124,18 @@ LL | let fail = -0b1111_1111i8;
124124
= note: the literal `0b1111_1111i8` (decimal `255`) does not fit into the type `i8`
125125
= note: and the value `-0b1111_1111i8` will become `1i8`
126126

127-
warning: 11 warnings emitted
127+
warning: literal out of range for `i32`
128+
--> $DIR/type-overflow.rs:49:16
129+
|
130+
LL | let fail = 0x8000_0000_0000_0000_0000_0000_FFFF_FFFE;
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
|
133+
= note: the literal `0x8000_0000_0000_0000_0000_0000_FFFF_FFFE` (decimal `170141183460469231731687303720179073022`) does not fit into the type `i32` and will become `-2i32`
134+
= help: consider using the type `u128` instead
135+
help: to use as a negative number (decimal `-2`), consider using the type `u128` for the literal and cast it to `i32`
136+
|
137+
LL | let fail = 0x8000_0000_0000_0000_0000_0000_FFFF_FFFEu128 as i32;
138+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139+
140+
warning: 12 warnings emitted
128141

0 commit comments

Comments
 (0)