1 use super::utils
::is_layout_incompatible
;
2 use super::UNSOUND_COLLECTION_TRANSMUTE
;
3 use clippy_utils
::diagnostics
::span_lint
;
5 use rustc_lint
::LateContext
;
6 use rustc_middle
::ty
::{self, Ty}
;
7 use rustc_span
::symbol
::sym
;
9 /// Checks for `unsound_collection_transmute` lint.
10 /// Returns `true` if it's triggered, otherwise returns `false`.
11 pub(super) fn check
<'tcx
>(cx
: &LateContext
<'tcx
>, e
: &'tcx Expr
<'_
>, from_ty
: Ty
<'tcx
>, to_ty
: Ty
<'tcx
>) -> bool
{
12 match (&from_ty
.kind(), &to_ty
.kind()) {
13 (ty
::Adt(from_adt
, from_substs
), ty
::Adt(to_adt
, to_substs
)) => {
14 if from_adt
.did() != to_adt
.did() {
18 cx
.tcx
.get_diagnostic_name(to_adt
.did()),
33 .zip(to_substs
.types())
34 .any(|(from_ty
, to_ty
)| is_layout_incompatible(cx
, from_ty
, to_ty
))
38 UNSOUND_COLLECTION_TRANSMUTE
,
40 &format
!("transmute from `{from_ty}` to `{to_ty}` with mismatched layout is unsound"),