]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/transmute/wrong_transmute.rs
Rollup merge of #102412 - joboet:dont_panic, r=m-ou-se
[rust.git] / src / tools / clippy / clippy_lints / src / transmute / wrong_transmute.rs
1 use super::WRONG_TRANSMUTE;
2 use clippy_utils::diagnostics::span_lint;
3 use rustc_hir::Expr;
4 use rustc_lint::LateContext;
5 use rustc_middle::ty::{self, Ty};
6
7 /// Checks for `wrong_transmute` lint.
8 /// Returns `true` if it's triggered, otherwise returns `false`.
9 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool {
10     match (&from_ty.kind(), &to_ty.kind()) {
11         (ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_)) => {
12             span_lint(
13                 cx,
14                 WRONG_TRANSMUTE,
15                 e.span,
16                 &format!("transmute from a `{from_ty}` to a pointer"),
17             );
18             true
19         },
20         _ => false,
21     }
22 }