Skip to content

dont handle bool transmute #140431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,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,
})
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/transmute/unnecessary-transmutation.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ fn main() {
let y: u64 = f64::to_bits(2.0);
//~^ 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
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/transmute/unnecessary-transmutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,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
}
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/transmute/unnecessary-transmutation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ error: unnecessary transmute
LL | let y: u64 = transmute(2.0);
| ^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(2.0)`

error: unnecessary transmute
--> $DIR/unnecessary-transmutation.rs:75:23
|
LL | let z: bool = transmute(1u8);
| ^^^^^^^^^^^^^^ help: replace this with: `(1u8 == 1)`

error: unnecessary transmute
--> $DIR/unnecessary-transmutation.rs:77:21
|
Expand All @@ -231,5 +225,5 @@ error: unnecessary transmute
LL | let z: i8 = transmute(z);
| ^^^^^^^^^^^^ help: replace this with: `(z) as i8`

error: aborting due to 32 previous errors
error: aborting due to 31 previous errors

Loading