Skip to content

Commit 025f76b

Browse files
committed
dont handle bool transmute
1 parent a932eb3 commit 025f76b

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ impl<'a, 'tcx> UnnecessaryTransmuteChecker<'a, 'tcx> {
7171
(Uint(_), Float(ty)) => err(format!("{}::from_bits({arg})", ty.name_str())),
7272
// bool → { x8 }
7373
(Bool, Int(..) | Uint(..)) => err(format!("({arg}) as {}", fn_sig.output())),
74-
// u8 → bool
75-
(Uint(_), Bool) => err(format!("({arg} == 1)")),
7674
_ => return None,
7775
})
7876
}

tests/ui/transmute/unnecessary-transmutation.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ fn main() {
7272
let y: u64 = f64::to_bits(2.0);
7373
//~^ ERROR
7474

75-
let z: bool = (1u8 == 1);
76-
//~^ ERROR
75+
let z: bool = transmute(1u8);
76+
// clippy
7777
let z: u8 = (z) as u8;
7878
//~^ ERROR
7979

8080
let z: bool = transmute(1i8);
81-
// no error!
81+
// clippy
8282
let z: i8 = (z) as i8;
8383
//~^ ERROR
8484
}

tests/ui/transmute/unnecessary-transmutation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ fn main() {
7373
//~^ ERROR
7474

7575
let z: bool = transmute(1u8);
76-
//~^ ERROR
76+
// clippy
7777
let z: u8 = transmute(z);
7878
//~^ ERROR
7979

8080
let z: bool = transmute(1i8);
81-
// no error!
81+
// clippy
8282
let z: i8 = transmute(z);
8383
//~^ ERROR
8484
}

tests/ui/transmute/unnecessary-transmutation.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ error: unnecessary transmute
213213
LL | let y: u64 = transmute(2.0);
214214
| ^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(2.0)`
215215

216-
error: unnecessary transmute
217-
--> $DIR/unnecessary-transmutation.rs:75:23
218-
|
219-
LL | let z: bool = transmute(1u8);
220-
| ^^^^^^^^^^^^^^ help: replace this with: `(1u8 == 1)`
221-
222216
error: unnecessary transmute
223217
--> $DIR/unnecessary-transmutation.rs:77:21
224218
|
@@ -231,5 +225,5 @@ error: unnecessary transmute
231225
LL | let z: i8 = transmute(z);
232226
| ^^^^^^^^^^^^ help: replace this with: `(z) as i8`
233227

234-
error: aborting due to 32 previous errors
228+
error: aborting due to 31 previous errors
235229

0 commit comments

Comments
 (0)