From 46a077010240a5a8b92101f1404a616ad77585dc Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 24 Sep 2024 18:52:39 +0200 Subject: [PATCH] Use correct std/core prefix in lint output --- clippy_lints/src/ptr.rs | 8 +- tests/ui/invalid_null_ptr_usage.fixed | 44 +++--- tests/ui/invalid_null_ptr_usage.stderr | 44 +++--- tests/ui/invalid_null_ptr_usage_no_std.fixed | 57 ++++++++ tests/ui/invalid_null_ptr_usage_no_std.rs | 57 ++++++++ tests/ui/invalid_null_ptr_usage_no_std.stderr | 136 ++++++++++++++++++ 6 files changed, 299 insertions(+), 47 deletions(-) create mode 100644 tests/ui/invalid_null_ptr_usage_no_std.fixed create mode 100644 tests/ui/invalid_null_ptr_usage_no_std.rs create mode 100644 tests/ui/invalid_null_ptr_usage_no_std.stderr diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index bb8a9b6fca85b..f5fcf521b96cc 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::source::SpanRangeExt; use clippy_utils::visitors::contains_unsafe_block; -use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local}; +use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, std_or_core}; use hir::LifetimeName; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::hir_id::{HirId, HirIdMap}; @@ -294,14 +294,16 @@ fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { }; for &arg_idx in arg_indices { - if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) { + if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) + && let Some(std_or_core) = std_or_core(cx) + { span_lint_and_sugg( cx, INVALID_NULL_PTR_USAGE, arg.span, "pointer must be non-null", "change this to", - "core::ptr::NonNull::dangling().as_ptr()".to_string(), + format!("{std_or_core}::ptr::NonNull::dangling().as_ptr()"), Applicability::MachineApplicable, ); } diff --git a/tests/ui/invalid_null_ptr_usage.fixed b/tests/ui/invalid_null_ptr_usage.fixed index 092e875a2554a..ba225102c984b 100644 --- a/tests/ui/invalid_null_ptr_usage.fixed +++ b/tests/ui/invalid_null_ptr_usage.fixed @@ -1,44 +1,44 @@ fn main() { unsafe { - let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); - let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0); - let _slice: &[usize] = std::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); struct A; // zero sized struct assert_eq!(std::mem::size_of::(), 0); - let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read(std::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read(std::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_unaligned(std::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_unaligned(std::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_volatile(std::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_volatile(std::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A); + let _a: A = std::ptr::replace(std::ptr::NonNull::dangling().as_ptr(), A); let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); // shouldn't lint let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); - std::ptr::swap::(core::ptr::NonNull::dangling().as_ptr(), &mut A); - std::ptr::swap::(&mut A, core::ptr::NonNull::dangling().as_ptr()); + std::ptr::swap::(std::ptr::NonNull::dangling().as_ptr(), &mut A); + std::ptr::swap::(&mut A, std::ptr::NonNull::dangling().as_ptr()); - std::ptr::swap_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); - std::ptr::swap_nonoverlapping::(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::swap_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + std::ptr::swap_nonoverlapping::(&mut A, std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); + std::ptr::write(std::ptr::NonNull::dangling().as_ptr(), A); - std::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); + std::ptr::write_unaligned(std::ptr::NonNull::dangling().as_ptr(), A); - std::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); + std::ptr::write_volatile(std::ptr::NonNull::dangling().as_ptr(), A); - std::ptr::write_bytes::(core::ptr::NonNull::dangling().as_ptr(), 42, 0); + std::ptr::write_bytes::(std::ptr::NonNull::dangling().as_ptr(), 42, 0); } } diff --git a/tests/ui/invalid_null_ptr_usage.stderr b/tests/ui/invalid_null_ptr_usage.stderr index a0be2c0ad75c6..613a2cc36885c 100644 --- a/tests/ui/invalid_null_ptr_usage.stderr +++ b/tests/ui/invalid_null_ptr_usage.stderr @@ -2,7 +2,7 @@ error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:3:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` | = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default @@ -10,127 +10,127 @@ error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:4:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:6:63 | LL | let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:8:33 | LL | std::ptr::copy::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:9:73 | LL | std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:11:48 | LL | std::ptr::copy_nonoverlapping::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:12:88 | LL | std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:17:36 | LL | let _a: A = std::ptr::read(std::ptr::null()); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:18:36 | LL | let _a: A = std::ptr::read(std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:20:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null()); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:21:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:23:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null()); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:24:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:26:39 | LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:30:29 | LL | std::ptr::swap::(std::ptr::null_mut(), &mut A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:31:37 | LL | std::ptr::swap::(&mut A, std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:33:44 | LL | std::ptr::swap_nonoverlapping::(std::ptr::null_mut(), &mut A, 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:34:52 | LL | std::ptr::swap_nonoverlapping::(&mut A, std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:36:25 | LL | std::ptr::write(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:38:35 | LL | std::ptr::write_unaligned(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:40:34 | LL | std::ptr::write_volatile(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:42:40 | LL | std::ptr::write_bytes::(std::ptr::null_mut(), 42, 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: aborting due to 22 previous errors diff --git a/tests/ui/invalid_null_ptr_usage_no_std.fixed b/tests/ui/invalid_null_ptr_usage_no_std.fixed new file mode 100644 index 0000000000000..2bbfe72742426 --- /dev/null +++ b/tests/ui/invalid_null_ptr_usage_no_std.fixed @@ -0,0 +1,57 @@ +#![no_std] +#![feature(lang_items)] + +use core::panic::PanicInfo; + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + loop {} +} + +fn main() { + unsafe { + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + + let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + + core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + + core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + + struct A; // zero sized struct + assert_eq!(core::mem::size_of::(), 0); + + let _a: A = core::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = core::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + + let _a: A = core::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = core::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + + let _a: A = core::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = core::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + + let _a: A = core::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A); + let _slice: *const [usize] = core::ptr::slice_from_raw_parts(core::ptr::null_mut(), 0); // shouldn't lint + let _slice: *const [usize] = core::ptr::slice_from_raw_parts_mut(core::ptr::null_mut(), 0); + + core::ptr::swap::(core::ptr::NonNull::dangling().as_ptr(), &mut A); + core::ptr::swap::(&mut A, core::ptr::NonNull::dangling().as_ptr()); + + core::ptr::swap_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + core::ptr::swap_nonoverlapping::(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); + + core::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); + + core::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); + + core::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); + + core::ptr::write_bytes::(core::ptr::NonNull::dangling().as_ptr(), 42, 0); + } +} diff --git a/tests/ui/invalid_null_ptr_usage_no_std.rs b/tests/ui/invalid_null_ptr_usage_no_std.rs new file mode 100644 index 0000000000000..cbce44f7c0d9b --- /dev/null +++ b/tests/ui/invalid_null_ptr_usage_no_std.rs @@ -0,0 +1,57 @@ +#![no_std] +#![feature(lang_items)] + +use core::panic::PanicInfo; + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + loop {} +} + +fn main() { + unsafe { + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null(), 0); + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null_mut(), 0); + + let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::null_mut(), 0); + + core::ptr::copy::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + + core::ptr::copy_nonoverlapping::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + + struct A; // zero sized struct + assert_eq!(core::mem::size_of::(), 0); + + let _a: A = core::ptr::read(core::ptr::null()); + let _a: A = core::ptr::read(core::ptr::null_mut()); + + let _a: A = core::ptr::read_unaligned(core::ptr::null()); + let _a: A = core::ptr::read_unaligned(core::ptr::null_mut()); + + let _a: A = core::ptr::read_volatile(core::ptr::null()); + let _a: A = core::ptr::read_volatile(core::ptr::null_mut()); + + let _a: A = core::ptr::replace(core::ptr::null_mut(), A); + let _slice: *const [usize] = core::ptr::slice_from_raw_parts(core::ptr::null_mut(), 0); // shouldn't lint + let _slice: *const [usize] = core::ptr::slice_from_raw_parts_mut(core::ptr::null_mut(), 0); + + core::ptr::swap::(core::ptr::null_mut(), &mut A); + core::ptr::swap::(&mut A, core::ptr::null_mut()); + + core::ptr::swap_nonoverlapping::(core::ptr::null_mut(), &mut A, 0); + core::ptr::swap_nonoverlapping::(&mut A, core::ptr::null_mut(), 0); + + core::ptr::write(core::ptr::null_mut(), A); + + core::ptr::write_unaligned(core::ptr::null_mut(), A); + + core::ptr::write_volatile(core::ptr::null_mut(), A); + + core::ptr::write_bytes::(core::ptr::null_mut(), 42, 0); + } +} diff --git a/tests/ui/invalid_null_ptr_usage_no_std.stderr b/tests/ui/invalid_null_ptr_usage_no_std.stderr new file mode 100644 index 0000000000000..df0d40e9e072c --- /dev/null +++ b/tests/ui/invalid_null_ptr_usage_no_std.stderr @@ -0,0 +1,136 @@ +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:16:60 + | +LL | let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null(), 0); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | + = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:17:60 + | +LL | let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:19:64 + | +LL | let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:21:34 + | +LL | core::ptr::copy::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:22:75 + | +LL | core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:24:49 + | +LL | core::ptr::copy_nonoverlapping::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:25:90 + | +LL | core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:30:37 + | +LL | let _a: A = core::ptr::read(core::ptr::null()); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:31:37 + | +LL | let _a: A = core::ptr::read(core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:33:47 + | +LL | let _a: A = core::ptr::read_unaligned(core::ptr::null()); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:34:47 + | +LL | let _a: A = core::ptr::read_unaligned(core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:36:46 + | +LL | let _a: A = core::ptr::read_volatile(core::ptr::null()); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:37:46 + | +LL | let _a: A = core::ptr::read_volatile(core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:39:40 + | +LL | let _a: A = core::ptr::replace(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:43:30 + | +LL | core::ptr::swap::(core::ptr::null_mut(), &mut A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:44:38 + | +LL | core::ptr::swap::(&mut A, core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:46:45 + | +LL | core::ptr::swap_nonoverlapping::(core::ptr::null_mut(), &mut A, 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:47:53 + | +LL | core::ptr::swap_nonoverlapping::(&mut A, core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:49:26 + | +LL | core::ptr::write(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:51:36 + | +LL | core::ptr::write_unaligned(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:53:35 + | +LL | core::ptr::write_volatile(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:55:41 + | +LL | core::ptr::write_bytes::(core::ptr::null_mut(), 42, 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: aborting due to 22 previous errors +