Skip to content

Commit 0779516

Browse files
committed
Drop uplifted clippy::invalid_null_ptr_usage
1 parent aaed11e commit 0779516

10 files changed

+76
-376
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
569569
crate::permissions_set_readonly_false::PERMISSIONS_SET_READONLY_FALSE_INFO,
570570
crate::precedence::PRECEDENCE_INFO,
571571
crate::ptr::CMP_NULL_INFO,
572-
crate::ptr::INVALID_NULL_PTR_USAGE_INFO,
573572
crate::ptr::MUT_FROM_REF_INFO,
574573
crate::ptr::PTR_ARG_INFO,
575574
crate::ptr_offset_with_cast::PTR_OFFSET_WITH_CAST_INFO,

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

+2-67
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Checks for usage of `&Vec[_]` and `&String`.
22
3-
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then};
3+
use clippy_utils::diagnostics::{span_lint, span_lint_and_then, span_lint_hir_and_then};
44
use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::expr_sig;
66
use clippy_utils::visitors::contains_unsafe_block;
@@ -129,30 +129,7 @@ declare_clippy_lint! {
129129
"fns that create mutable refs from immutable ref args"
130130
}
131131

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

157134
impl<'tcx> LateLintPass<'tcx> for Ptr {
158135
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
@@ -264,48 +241,6 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
264241
"comparing with null is better expressed by the `.is_null()` method",
265242
);
266243
}
267-
} else {
268-
check_invalid_ptr_usage(cx, expr);
269-
}
270-
}
271-
}
272-
273-
fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
274-
if let ExprKind::Call(fun, args) = expr.kind
275-
&& let ExprKind::Path(ref qpath) = fun.kind
276-
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()
277-
&& let Some(name) = cx.tcx.get_diagnostic_name(fun_def_id)
278-
{
279-
// `arg` positions where null would cause U.B.
280-
let arg_indices: &[_] = match name {
281-
sym::ptr_read
282-
| sym::ptr_read_unaligned
283-
| sym::ptr_read_volatile
284-
| sym::ptr_replace
285-
| sym::ptr_slice_from_raw_parts
286-
| sym::ptr_slice_from_raw_parts_mut
287-
| sym::ptr_write
288-
| sym::ptr_write_bytes
289-
| sym::ptr_write_unaligned
290-
| sym::ptr_write_volatile
291-
| sym::slice_from_raw_parts
292-
| sym::slice_from_raw_parts_mut => &[0],
293-
sym::ptr_copy | sym::ptr_copy_nonoverlapping | sym::ptr_swap | sym::ptr_swap_nonoverlapping => &[0, 1],
294-
_ => return,
295-
};
296-
297-
for &arg_idx in arg_indices {
298-
if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) {
299-
span_lint_and_sugg(
300-
cx,
301-
INVALID_NULL_PTR_USAGE,
302-
arg.span,
303-
"pointer must be non-null",
304-
"change this to",
305-
"core::ptr::NonNull::dangling().as_ptr()".to_string(),
306-
Applicability::MachineApplicable,
307-
);
308-
}
309244
}
310245
}
311246
}

src/tools/clippy/clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
5151
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
5252
("clippy::invalid_ref", "invalid_value"),
5353
("clippy::invalid_utf8_in_unchecked", "invalid_from_utf8_unchecked"),
54+
("clippy::invalid_null_ptr_usage", "invalid_null_ptr_usages"),
5455
("clippy::let_underscore_drop", "let_underscore_drop"),
5556
("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"),
5657
("clippy::panic_params", "non_fmt_panics"),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(dead_code, unused_variables)]
1+
#![allow(dead_code, unused_variables, invalid_null_ptr_usages)]
22
#![allow(clippy::unnecessary_cast)]
33

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

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

-47
This file was deleted.

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

-47
This file was deleted.

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

-154
This file was deleted.

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

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#![allow(unknown_lints)]
5353
#![allow(unused_labels)]
5454
#![allow(ambiguous_wide_pointer_comparisons)]
55+
#![allow(invalid_null_ptr_usages)]
5556
#![warn(clippy::almost_complete_range)]
5657
#![warn(clippy::disallowed_names)]
5758
#![warn(clippy::blocks_in_conditions)]
@@ -110,5 +111,6 @@
110111
#![warn(unknown_lints)]
111112
#![warn(unused_labels)]
112113
#![warn(ambiguous_wide_pointer_comparisons)]
114+
#![warn(invalid_null_ptr_usages)]
113115

114116
fn main() {}

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

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#![allow(unknown_lints)]
5353
#![allow(unused_labels)]
5454
#![allow(ambiguous_wide_pointer_comparisons)]
55+
#![allow(invalid_null_ptr_usages)]
5556
#![warn(clippy::almost_complete_letter_range)]
5657
#![warn(clippy::blacklisted_name)]
5758
#![warn(clippy::block_in_if_condition_expr)]
@@ -110,5 +111,6 @@
110111
#![warn(clippy::unknown_clippy_lints)]
111112
#![warn(clippy::unused_label)]
112113
#![warn(clippy::vtable_address_comparisons)]
114+
#![warn(clippy::invalid_null_ptr_usages)]
113115

114116
fn main() {}

0 commit comments

Comments
 (0)