Skip to content

Commit e9728b8

Browse files
committed
Auto merge of #7068 - boxdot:remove-std-ptr-null, r=camsteffen
Remove paths::STD_PTR_NULL Related to #5393 changelog: none
2 parents 2a96bc4 + d6beb18 commit e9728b8

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

clippy_lints/src/transmuting_null.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::consts::{constant_context, Constant};
22
use clippy_utils::diagnostics::span_lint;
3-
use clippy_utils::{match_qpath, paths};
3+
use clippy_utils::{match_def_path, paths};
44
use if_chain::if_chain;
55
use rustc_ast::LitKind;
66
use rustc_hir::{Expr, ExprKind};
@@ -38,10 +38,10 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
3838

3939
if_chain! {
4040
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);
4341
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);
4545
then {
4646

4747
// Catching transmute over constants that resolve to `null`.
@@ -69,10 +69,10 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
6969
// Catching:
7070
// `std::mem::transmute(std::ptr::null::<i32>())`
7171
if_chain! {
72-
if let ExprKind::Call(func1, args1) = args[0].kind;
72+
if let ExprKind::Call(func1, []) = args[0].kind;
7373
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);
7676
then {
7777
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
7878
}

clippy_utils/src/paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ pub const STDERR: [&str; 4] = ["std", "io", "stdio", "stderr"];
142142
pub const STDOUT: [&str; 4] = ["std", "io", "stdio", "stdout"];
143143
pub const STD_CONVERT_IDENTITY: [&str; 3] = ["std", "convert", "identity"];
144144
pub const STD_FS_CREATE_DIR: [&str; 3] = ["std", "fs", "create_dir"];
145-
pub const STD_MEM_TRANSMUTE: [&str; 3] = ["std", "mem", "transmute"];
146-
pub const STD_PTR_NULL: [&str; 3] = ["std", "ptr", "null"];
147145
pub const STRING_AS_MUT_STR: [&str; 4] = ["alloc", "string", "String", "as_mut_str"];
148146
pub const STRING_AS_STR: [&str; 4] = ["alloc", "string", "String", "as_str"];
149147
pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];

0 commit comments

Comments
 (0)