Skip to content

Commit 3b24e6c

Browse files
authored
Unrolled build for rust-lang#136424
Rollup merge of rust-lang#136424 - 11happy:overflow.hex.fix, r=fmease fix: overflowing bin hex **Overview:** - This PR fixes rust-lang#135404. **Testing** - Tested the updated functionality. - previously emitted diagnostics: ```bash error: literal out of range for `i32` --> src/main.rs:2:9 | 2 | _ = 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 `i128` instead = note: `#[deny(overflowing_literals)]` on by default help: to use as a negative number (decimal `-2`), consider using the type `u32` for the literal and cast it to `i32` | 2 | _ = 0x8FFF_FFFF_FFFF_FFFEu32 as i32; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` - current diagnostics: ```bash error: literal out of range for `i32` --> ../temp.rs:2:13 | 2 | let x = 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 = note: `#[deny(overflowing_literals)]` on by default help: to use as a negative number (decimal `-2`), consider using the type `u64` for the literal and cast it to `i32` | 2 | let x = 0x8FFF_FFFF_FFFF_FFFEu64 as i32; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
2 parents 2f58193 + dbf8fe0 commit 3b24e6c

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

compiler/rustc_lint/src/types/literal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn report_bin_hex_error(
186186
lit_no_suffix,
187187
negative_val: actually.clone(),
188188
int_ty: int_ty.name_str(),
189-
uint_ty: int_ty.to_unsigned().name_str(),
189+
uint_ty: Integer::fit_unsigned(val).uint_ty_str(),
190190
})
191191
})
192192
.flatten();

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
}

tests/ui/lint/type-overflow.stderr

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

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

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

0 commit comments

Comments
 (0)