1
Fork 0

Rollup merge of #136424 - 11happy:overflow.hex.fix, r=fmease

fix: overflowing bin hex

**Overview:**
- This PR fixes #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;
  |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2025-02-28 21:41:58 +08:00 committed by GitHub
commit 743f26de64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 5 deletions

View file

@ -186,7 +186,7 @@ fn report_bin_hex_error(
lit_no_suffix,
negative_val: actually.clone(),
int_ty: int_ty.name_str(),
uint_ty: int_ty.to_unsigned().name_str(),
uint_ty: Integer::fit_unsigned(val).uint_ty_str(),
})
})
.flatten();