1 use super::utils::can_be_expressed_as_pointer_cast;
2 use super::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS;
3 use clippy_utils::diagnostics::span_lint_and_then;
4 use clippy_utils::sugg;
5 use rustc_errors::Applicability;
7 use rustc_lint::LateContext;
8 use rustc_middle::ty::Ty;
10 /// Checks for `transmutes_expressible_as_ptr_casts` lint.
11 /// Returns `true` if it's triggered, otherwise returns `false`.
12 pub(super) fn check<'tcx>(
13 cx: &LateContext<'tcx>,
17 args: &'tcx [Expr<'_>],
19 if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
22 TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
25 "transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
29 if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
30 let sugg = arg.as_ty(&to_ty.to_string()).to_string();
31 diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable);