Skip to content

Remove paths::STD_PTR_NULL #7068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions clippy_lints/src/transmuting_null.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::consts::{constant_context, Constant};
use clippy_utils::diagnostics::span_lint;
use clippy_utils::{match_qpath, paths};
use clippy_utils::{match_def_path, paths};
use if_chain::if_chain;
use rustc_ast::LitKind;
use rustc_hir::{Expr, ExprKind};
Expand Down Expand Up @@ -38,10 +38,10 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {

if_chain! {
if let ExprKind::Call(func, args) = expr.kind;
if let ExprKind::Path(ref path) = func.kind;
if match_qpath(path, &paths::STD_MEM_TRANSMUTE);
if args.len() == 1;

if let ExprKind::Path(ref path) = func.kind;
if let Some(func_def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
if match_def_path(cx, func_def_id, &paths::TRANSMUTE);
then {

// Catching transmute over constants that resolve to `null`.
Expand Down Expand Up @@ -69,10 +69,10 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
// Catching:
// `std::mem::transmute(std::ptr::null::<i32>())`
if_chain! {
if let ExprKind::Call(func1, args1) = args[0].kind;
if let ExprKind::Call(func1, []) = args[0].kind;
if let ExprKind::Path(ref path1) = func1.kind;
if match_qpath(path1, &paths::STD_PTR_NULL);
if args1.is_empty();
if let Some(func1_def_id) = cx.qpath_res(path1, func1.hir_id).opt_def_id();
if match_def_path(cx, func1_def_id, &paths::PTR_NULL);
then {
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
}
Expand Down
2 changes: 0 additions & 2 deletions clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ pub const STDERR: [&str; 4] = ["std", "io", "stdio", "stderr"];
pub const STDOUT: [&str; 4] = ["std", "io", "stdio", "stdout"];
pub const STD_CONVERT_IDENTITY: [&str; 3] = ["std", "convert", "identity"];
pub const STD_FS_CREATE_DIR: [&str; 3] = ["std", "fs", "create_dir"];
pub const STD_MEM_TRANSMUTE: [&str; 3] = ["std", "mem", "transmute"];
pub const STD_PTR_NULL: [&str; 3] = ["std", "ptr", "null"];
pub const STRING_AS_MUT_STR: [&str; 4] = ["alloc", "string", "String", "as_mut_str"];
pub const STRING_AS_STR: [&str; 4] = ["alloc", "string", "String", "as_str"];
pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];
Expand Down