Skip to content

Commit ccc8ce5

Browse files
committed
dont handle bool transmute
1 parent 2a5da7a commit ccc8ce5

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs

-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ impl<'a, 'tcx> UnnecessaryTransmuteChecker<'a, 'tcx> {
9898
(Uint(_), Float(ty)) => err(format!("{}::from_bits({arg})", ty.name_str())),
9999
// bool → { x8 }
100100
(Bool, Int(..) | Uint(..)) => err(format!("({arg}) as {}", fn_sig.output())),
101-
// u8 → bool
102-
(Uint(_), Bool) => err(format!("({arg} == 1)")),
103101
_ => return None,
104102
})
105103
}

tests/ui/transmute/unnecessary-transmutation.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ fn main() {
8181
let y: i64 = f64::to_bits(1f64).cast_signed();
8282
//~^ ERROR
8383

84-
let z: bool = (1u8 == 1);
85-
//~^ ERROR
84+
let z: bool = transmute(1u8);
85+
// clippy
8686
let z: u8 = (z) as u8;
8787
//~^ ERROR
8888

8989
let z: bool = transmute(1i8);
90-
// no error!
90+
// clippy
9191
let z: i8 = (z) as i8;
9292
//~^ ERROR
9393
}

tests/ui/transmute/unnecessary-transmutation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ fn main() {
8282
//~^ ERROR
8383

8484
let z: bool = transmute(1u8);
85-
//~^ ERROR
85+
// clippy
8686
let z: u8 = transmute(z);
8787
//~^ ERROR
8888

8989
let z: bool = transmute(1i8);
90-
// no error!
90+
// clippy
9191
let z: i8 = transmute(z);
9292
//~^ ERROR
9393
}

tests/ui/transmute/unnecessary-transmutation.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,6 @@ error: unnecessary transmute
239239
LL | let y: i64 = transmute(1f64);
240240
| ^^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(1f64).cast_signed()`
241241

242-
error: unnecessary transmute
243-
--> $DIR/unnecessary-transmutation.rs:84:23
244-
|
245-
LL | let z: bool = transmute(1u8);
246-
| ^^^^^^^^^^^^^^ help: replace this with: `(1u8 == 1)`
247-
248242
error: unnecessary transmute
249243
--> $DIR/unnecessary-transmutation.rs:86:21
250244
|
@@ -257,5 +251,5 @@ error: unnecessary transmute
257251
LL | let z: i8 = transmute(z);
258252
| ^^^^^^^^^^^^ help: replace this with: `(z) as i8`
259253

260-
error: aborting due to 36 previous errors
254+
error: aborting due to 35 previous errors
261255

0 commit comments

Comments
 (0)