Skip to content

Commit d3766c6

Browse files
committed
Drop clippy::invalid_null_ptr_usage
1 parent 154fd61 commit d3766c6

13 files changed

+24
-648
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::PTR_EQ_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

+1-72
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,6 @@ 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-
151128
declare_clippy_lint! {
152129
/// ### What it does
153130
/// Use `std::ptr::eq` when applicable
@@ -177,7 +154,7 @@ declare_clippy_lint! {
177154
"use `std::ptr::eq` when comparing raw pointers"
178155
}
179156

180-
declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF, INVALID_NULL_PTR_USAGE, PTR_EQ]);
157+
declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF, PTR_EQ]);
181158

182159
impl<'tcx> LateLintPass<'tcx> for Ptr {
183160
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
@@ -301,54 +278,6 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
301278
format!("{non_null_path_snippet}.is_null()"),
302279
Applicability::MachineApplicable,
303280
);
304-
} else {
305-
check_invalid_ptr_usage(cx, expr);
306-
}
307-
}
308-
}
309-
310-
fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
311-
if let ExprKind::Call(fun, args) = expr.kind
312-
&& let ExprKind::Path(ref qpath) = fun.kind
313-
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()
314-
&& let Some(name) = cx.tcx.get_diagnostic_name(fun_def_id)
315-
{
316-
// TODO: `ptr_slice_from_raw_parts` and its mutable variant should probably still be linted
317-
// conditionally based on how the return value is used, but not universally like the other
318-
// functions since there are valid uses for null slice pointers.
319-
//
320-
// See: https://github.com/rust-lang/rust-clippy/pull/13452/files#r1773772034
321-
322-
// `arg` positions where null would cause U.B.
323-
let arg_indices: &[_] = match name {
324-
sym::ptr_read
325-
| sym::ptr_read_unaligned
326-
| sym::ptr_read_volatile
327-
| sym::ptr_replace
328-
| sym::ptr_write
329-
| sym::ptr_write_bytes
330-
| sym::ptr_write_unaligned
331-
| sym::ptr_write_volatile
332-
| sym::slice_from_raw_parts
333-
| sym::slice_from_raw_parts_mut => &[0],
334-
sym::ptr_copy | sym::ptr_copy_nonoverlapping | sym::ptr_swap | sym::ptr_swap_nonoverlapping => &[0, 1],
335-
_ => return,
336-
};
337-
338-
for &arg_idx in arg_indices {
339-
if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg))
340-
&& let Some(std_or_core) = std_or_core(cx)
341-
{
342-
span_lint_and_sugg(
343-
cx,
344-
INVALID_NULL_PTR_USAGE,
345-
arg.span,
346-
"pointer must be non-null",
347-
"change this to",
348-
format!("{std_or_core}::ptr::NonNull::dangling().as_ptr()"),
349-
Applicability::MachineApplicable,
350-
);
351-
}
352281
}
353282
}
354283
}

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)