mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Don't lint transmute_undefined_repr
on unions.
This commit is contained in:
parent
7fd52b5e3c
commit
911e10562a
2 changed files with 6 additions and 1 deletions
|
@ -312,6 +312,8 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
|
|||
ty::Adt(def, _) if def.is_enum() && (def.variants().is_empty() || is_c_void(cx, ty)) => {
|
||||
ReducedTy::TypeErasure
|
||||
},
|
||||
// TODO: Check if the conversion to or from at least one of a union's fields is valid.
|
||||
ty::Adt(def, _) if def.is_union() => ReducedTy::TypeErasure,
|
||||
ty::Foreign(_) => ReducedTy::TypeErasure,
|
||||
ty::Ref(_, ty, _) => ReducedTy::Ref(ty),
|
||||
ty::RawPtr(ty) => ReducedTy::Ref(ty.ty),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(clippy::unit_arg, clippy::transmute_ptr_to_ref)]
|
||||
|
||||
use core::ffi::c_void;
|
||||
use core::mem::{size_of, transmute};
|
||||
use core::mem::{size_of, transmute, MaybeUninit};
|
||||
|
||||
fn value<T>() -> T {
|
||||
unimplemented!()
|
||||
|
@ -103,5 +103,8 @@ fn main() {
|
|||
trait Trait {}
|
||||
let _: (isize, isize) = transmute(value::<&dyn Trait>()); // Ok
|
||||
let _: &dyn Trait = transmute(value::<(isize, isize)>()); // Ok
|
||||
|
||||
let _: MaybeUninit<Ty2<u32, u32>> = transmute(value::<Ty2<u32, u32>>()); // Ok
|
||||
let _: Ty2<u32, u32> = transmute(value::<MaybeUninit<Ty2<u32, u32>>>()); // Ok
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue