From 17d15c424bf73c738e47410f6ac2a6a5c859f206 Mon Sep 17 00:00:00 2001 From: 11happy Date: Sun, 9 Feb 2025 11:58:28 +0530 Subject: [PATCH] test: fix test case & add new one Signed-off-by: 11happy --- tests/ui/lint/type-overflow.rs | 6 +++++- tests/ui/lint/type-overflow.stderr | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/ui/lint/type-overflow.rs b/tests/ui/lint/type-overflow.rs index 1e74a8925f621..16a021da06581 100644 --- a/tests/ui/lint/type-overflow.rs +++ b/tests/ui/lint/type-overflow.rs @@ -41,8 +41,12 @@ fn main() { let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for `i32` //~| HELP consider using the type `u64` instead - //~| HELP + //~| HELP consider using the type `u64` for the literal and cast it to `i32` let fail = -0b1111_1111i8; //~WARNING literal out of range for `i8` //~| HELP consider using the type `i16` instead + + let fail = 0x8000_0000_0000_0000_0000_0000_FFFF_FFFE; //~WARNING literal out of range for `i32` + //~| HELP consider using the type `u128` instead + //~| HELP consider using the type `u128` for the literal and cast it to `i32` } diff --git a/tests/ui/lint/type-overflow.stderr b/tests/ui/lint/type-overflow.stderr index 9fdb05ed1c036..96bb5a1af48a2 100644 --- a/tests/ui/lint/type-overflow.stderr +++ b/tests/ui/lint/type-overflow.stderr @@ -110,9 +110,9 @@ LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; | = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into the type `i32` and will become `-2i32` = help: consider using the type `u64` instead -help: to use as a negative number (decimal `-2`), consider using the type `u32` for the literal and cast it to `i32` +help: to use as a negative number (decimal `-2`), consider using the type `u64` for the literal and cast it to `i32` | -LL | let fail = 0x8FFF_FFFF_FFFF_FFFEu32 as i32; +LL | let fail = 0x8FFF_FFFF_FFFF_FFFEu64 as i32; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ warning: literal out of range for `i8` @@ -124,5 +124,18 @@ LL | let fail = -0b1111_1111i8; = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into the type `i8` = note: and the value `-0b1111_1111i8` will become `1i8` -warning: 11 warnings emitted +warning: literal out of range for `i32` + --> $DIR/type-overflow.rs:49:16 + | +LL | let fail = 0x8000_0000_0000_0000_0000_0000_FFFF_FFFE; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the literal `0x8000_0000_0000_0000_0000_0000_FFFF_FFFE` (decimal `170141183460469231731687303720179073022`) does not fit into the type `i32` and will become `-2i32` + = help: consider using the type `u128` instead +help: to use as a negative number (decimal `-2`), consider using the type `u128` for the literal and cast it to `i32` + | +LL | let fail = 0x8000_0000_0000_0000_0000_0000_FFFF_FFFEu128 as i32; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +warning: 12 warnings emitted