diff options
| author | bendn <bend.n@outlook.com> | 2025-04-29 13:06:21 +0700 |
|---|---|---|
| committer | bendn <bend.n@outlook.com> | 2025-05-15 20:20:39 +0700 |
| commit | de8e8641ae8194009b13dcca997e1eaa991b2888 (patch) | |
| tree | 1c81d656e2fbe824e3fc6585c5cb7e19f7dfd383 | |
| parent | 2a5da7acd4c3eae638aa1c46f3a537940e60a0e4 (diff) | |
| download | rust-de8e8641ae8194009b13dcca997e1eaa991b2888.tar.gz rust-de8e8641ae8194009b13dcca997e1eaa991b2888.zip | |
dont handle bool transmute
4 files changed, 7 insertions, 14 deletions
diff --git a/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs b/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs index 8da17a056e3..0514de3ea13 100644 --- a/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs +++ b/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs @@ -9,6 +9,7 @@ use crate::errors::UnnecessaryTransmute as Error; /// Check for transmutes that overlap with stdlib methods. /// For example, transmuting `[u8; 4]` to `u32`. +/// We chose not to lint u8 -> bool transmutes, see #140431 pub(super) struct CheckUnnecessaryTransmutes; impl<'tcx> crate::MirLint<'tcx> for CheckUnnecessaryTransmutes { @@ -98,8 +99,6 @@ impl<'a, 'tcx> UnnecessaryTransmuteChecker<'a, 'tcx> { (Uint(_), Float(ty)) => err(format!("{}::from_bits({arg})", ty.name_str())), // bool → { x8 } (Bool, Int(..) | Uint(..)) => err(format!("({arg}) as {}", fn_sig.output())), - // u8 → bool - (Uint(_), Bool) => err(format!("({arg} == 1)")), _ => return None, }) } diff --git a/tests/ui/transmute/unnecessary-transmutation.fixed b/tests/ui/transmute/unnecessary-transmutation.fixed index bf7d769348a..f6478c5aa5c 100644 --- a/tests/ui/transmute/unnecessary-transmutation.fixed +++ b/tests/ui/transmute/unnecessary-transmutation.fixed @@ -81,13 +81,13 @@ fn main() { let y: i64 = f64::to_bits(1f64).cast_signed(); //~^ ERROR - let z: bool = (1u8 == 1); - //~^ ERROR + let z: bool = transmute(1u8); + // clippy let z: u8 = (z) as u8; //~^ ERROR let z: bool = transmute(1i8); - // no error! + // clippy let z: i8 = (z) as i8; //~^ ERROR } diff --git a/tests/ui/transmute/unnecessary-transmutation.rs b/tests/ui/transmute/unnecessary-transmutation.rs index b9de529f1cc..ab0af03acc2 100644 --- a/tests/ui/transmute/unnecessary-transmutation.rs +++ b/tests/ui/transmute/unnecessary-transmutation.rs @@ -82,12 +82,12 @@ fn main() { //~^ ERROR let z: bool = transmute(1u8); - //~^ ERROR + // clippy let z: u8 = transmute(z); //~^ ERROR let z: bool = transmute(1i8); - // no error! + // clippy let z: i8 = transmute(z); //~^ ERROR } diff --git a/tests/ui/transmute/unnecessary-transmutation.stderr b/tests/ui/transmute/unnecessary-transmutation.stderr index a19f1bebf16..59e933bbc81 100644 --- a/tests/ui/transmute/unnecessary-transmutation.stderr +++ b/tests/ui/transmute/unnecessary-transmutation.stderr @@ -240,12 +240,6 @@ LL | let y: i64 = transmute(1f64); | ^^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(1f64).cast_signed()` error: unnecessary transmute - --> $DIR/unnecessary-transmutation.rs:84:23 - | -LL | let z: bool = transmute(1u8); - | ^^^^^^^^^^^^^^ help: replace this with: `(1u8 == 1)` - -error: unnecessary transmute --> $DIR/unnecessary-transmutation.rs:86:21 | LL | let z: u8 = transmute(z); @@ -257,5 +251,5 @@ error: unnecessary transmute LL | let z: i8 = transmute(z); | ^^^^^^^^^^^^ help: replace this with: `(z) as i8` -error: aborting due to 36 previous errors +error: aborting due to 35 previous errors |
