Summary
The clippy lint transmutes_expressible_as_ptr_casts calls into rustc_hir_typeck::cast::check_cast to check if a cast from one type to another would type-check. When the cast is invalid, there shouldn't be any diagnostics from either rustc or clippy. This is mostly ensured by the check_cast helper discards only running the "check" part and not the "report cast error" part, but but there are a few errors and lints that are reported in the "check" phase. Those are shown when the clippy lint considers a transmute that rustc would lint/error on.
Note: I'm reporting this in the clippy issue tracker because it's only user-visible through clippy, but it seems likely that the root cause and fix are in rustc.
Reproducer
Code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=d4303b7bc7f0a6253a61b325976cc185
#[repr(u32)]
enum Foo { A }
impl Drop for Foo {
fn drop(&mut self) {}
}
pub fn foo() -> u32 {
unsafe {
std::mem::transmute::<Foo, u32>(Foo::A)
}
}
Current output:
Checking playground v0.0.1 (/playground)
error: cannot cast enum `Foo` into integer `u32` because it implements `Drop`
error: could not compile `playground` (lib) due to 1 previous error
Desired output:
(No diagnostic)
Version
Additional Labels
No response
Summary
The clippy lint
transmutes_expressible_as_ptr_castscalls intorustc_hir_typeck::cast::check_castto check if a cast from one type to another would type-check. When the cast is invalid, there shouldn't be any diagnostics from either rustc or clippy. This is mostly ensured by thecheck_casthelper discards only running the "check" part and not the "report cast error" part, but but there are a few errors and lints that are reported in the "check" phase. Those are shown when the clippy lint considers a transmute that rustc would lint/error on.Note: I'm reporting this in the clippy issue tracker because it's only user-visible through clippy, but it seems likely that the root cause and fix are in rustc.
Reproducer
Code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=d4303b7bc7f0a6253a61b325976cc185
Current output:
Desired output:
(No diagnostic)
Version
Additional Labels
No response