|
1 | 1 | use crate::consts::{constant_context, Constant};
|
2 | 2 | use clippy_utils::diagnostics::span_lint;
|
3 |
| -use clippy_utils::{match_qpath, paths}; |
| 3 | +use clippy_utils::{match_def_path, paths}; |
4 | 4 | use if_chain::if_chain;
|
5 | 5 | use rustc_ast::LitKind;
|
6 | 6 | use rustc_hir::{Expr, ExprKind};
|
@@ -38,10 +38,10 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
|
38 | 38 |
|
39 | 39 | if_chain! {
|
40 | 40 | if let ExprKind::Call(func, args) = expr.kind;
|
41 |
| - if let ExprKind::Path(ref path) = func.kind; |
42 |
| - if match_qpath(path, &paths::STD_MEM_TRANSMUTE); |
43 | 41 | if args.len() == 1;
|
44 |
| - |
| 42 | + if let ExprKind::Path(ref path) = func.kind; |
| 43 | + if let Some(func_def_id) = cx.qpath_res(path, func.hir_id).opt_def_id(); |
| 44 | + if match_def_path(cx, func_def_id, &paths::TRANSMUTE); |
45 | 45 | then {
|
46 | 46 |
|
47 | 47 | // Catching transmute over constants that resolve to `null`.
|
@@ -69,10 +69,10 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
|
69 | 69 | // Catching:
|
70 | 70 | // `std::mem::transmute(std::ptr::null::<i32>())`
|
71 | 71 | if_chain! {
|
72 |
| - if let ExprKind::Call(func1, args1) = args[0].kind; |
| 72 | + if let ExprKind::Call(func1, []) = args[0].kind; |
73 | 73 | if let ExprKind::Path(ref path1) = func1.kind;
|
74 |
| - if match_qpath(path1, &paths::STD_PTR_NULL); |
75 |
| - if args1.is_empty(); |
| 74 | + if let Some(func1_def_id) = cx.qpath_res(path1, func1.hir_id).opt_def_id(); |
| 75 | + if match_def_path(cx, func1_def_id, &paths::PTR_NULL); |
76 | 76 | then {
|
77 | 77 | span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
|
78 | 78 | }
|
|
0 commit comments