Skip to content

Commit 79b4828

Browse files
committed
Drop clippy::invalid_null_ptr_usage
1 parent 66451ce commit 79b4828

13 files changed

+25
-649
lines changed

src/tools/clippy/clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
638638
crate::precedence::PRECEDENCE_INFO,
639639
crate::precedence::PRECEDENCE_BITS_INFO,
640640
crate::ptr::CMP_NULL_INFO,
641-
crate::ptr::INVALID_NULL_PTR_USAGE_INFO,
642641
crate::ptr::MUT_FROM_REF_INFO,
643642
crate::ptr::PTR_ARG_INFO,
644643
crate::ptr_offset_with_cast::PTR_OFFSET_WITH_CAST_INFO,

src/tools/clippy/clippy_lints/src/deprecated_lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
131131
("clippy::clone_double_ref", "suspicious_double_ref_op"),
132132
#[clippy::version = ""]
133133
("clippy::cmp_nan", "invalid_nan_comparisons"),
134+
#[clippy::version = "CURRENT_RUSTC_VERSION"]
135+
("clippy::invalid_null_ptr_usage", "invalid_null_arguments"),
134136
#[clippy::version = "1.86.0"]
135137
("clippy::double_neg", "double_negations"),
136138
#[clippy::version = ""]

src/tools/clippy/clippy_lints/src/ptr.rs

+2-73
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, span_lin
22
use clippy_utils::source::SpanRangeExt;
33
use clippy_utils::sugg::Sugg;
44
use clippy_utils::visitors::contains_unsafe_block;
5-
use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, std_or_core};
5+
use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local};
66
use hir::LifetimeName;
77
use rustc_abi::ExternAbi;
88
use rustc_errors::{Applicability, MultiSpan};
@@ -125,30 +125,7 @@ declare_clippy_lint! {
125125
"fns that create mutable refs from immutable ref args"
126126
}
127127

128-
declare_clippy_lint! {
129-
/// ### What it does
130-
/// This lint checks for invalid usages of `ptr::null`.
131-
///
132-
/// ### Why is this bad?
133-
/// This causes undefined behavior.
134-
///
135-
/// ### Example
136-
/// ```ignore
137-
/// // Undefined behavior
138-
/// unsafe { std::slice::from_raw_parts(ptr::null(), 0); }
139-
/// ```
140-
///
141-
/// Use instead:
142-
/// ```ignore
143-
/// unsafe { std::slice::from_raw_parts(NonNull::dangling().as_ptr(), 0); }
144-
/// ```
145-
#[clippy::version = "1.53.0"]
146-
pub INVALID_NULL_PTR_USAGE,
147-
correctness,
148-
"invalid usage of a null pointer, suggesting `NonNull::dangling()` instead"
149-
}
150-
151-
declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF, INVALID_NULL_PTR_USAGE]);
128+
declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]);
152129

153130
impl<'tcx> LateLintPass<'tcx> for Ptr {
154131
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
@@ -268,54 +245,6 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
268245
format!("{non_null_path_snippet}.is_null()"),
269246
Applicability::MachineApplicable,
270247
);
271-
} else {
272-
check_invalid_ptr_usage(cx, expr);
273-
}
274-
}
275-
}
276-
277-
fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
278-
if let ExprKind::Call(fun, args) = expr.kind
279-
&& let ExprKind::Path(ref qpath) = fun.kind
280-
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()
281-
&& let Some(name) = cx.tcx.get_diagnostic_name(fun_def_id)
282-
{
283-
// TODO: `ptr_slice_from_raw_parts` and its mutable variant should probably still be linted
284-
// conditionally based on how the return value is used, but not universally like the other
285-
// functions since there are valid uses for null slice pointers.
286-
//
287-
// See: https://github.com/rust-lang/rust-clippy/pull/13452/files#r1773772034
288-
289-
// `arg` positions where null would cause U.B.
290-
let arg_indices: &[_] = match name {
291-
sym::ptr_read
292-
| sym::ptr_read_unaligned
293-
| sym::ptr_read_volatile
294-
| sym::ptr_replace
295-
| sym::ptr_write
296-
| sym::ptr_write_bytes
297-
| sym::ptr_write_unaligned
298-
| sym::ptr_write_volatile
299-
| sym::slice_from_raw_parts
300-
| sym::slice_from_raw_parts_mut => &[0],
301-
sym::ptr_copy | sym::ptr_copy_nonoverlapping | sym::ptr_swap | sym::ptr_swap_nonoverlapping => &[0, 1],
302-
_ => return,
303-
};
304-
305-
for &arg_idx in arg_indices {
306-
if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg))
307-
&& let Some(std_or_core) = std_or_core(cx)
308-
{
309-
span_lint_and_sugg(
310-
cx,
311-
INVALID_NULL_PTR_USAGE,
312-
arg.span,
313-
"pointer must be non-null",
314-
"change this to",
315-
format!("{std_or_core}::ptr::NonNull::dangling().as_ptr()"),
316-
Applicability::MachineApplicable,
317-
);
318-
}
319248
}
320249
}
321250
}

src/tools/clippy/tests/ui/crashes/ice-1782.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ check-pass
22

3-
#![allow(dead_code, unused_variables)]
3+
#![allow(dead_code, unused_variables, invalid_null_arguments)]
44
#![allow(clippy::unnecessary_cast, clippy::missing_transmute_annotations)]
55

66
/// Should not trigger an ICE in `SpanlessEq` / `consts::constant`

src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed

-66
This file was deleted.

src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs

-66
This file was deleted.

src/tools/clippy/tests/ui/invalid_null_ptr_usage.stderr

-136
This file was deleted.

0 commit comments

Comments
 (0)