mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Auto merge of #13454 - samueltardieu:push-ymnkzlqloptz, r=xFrednet
Use correct std/core prefix in lint output changelog: none I was waiting for #13452 to be merged before sending this one. `std` is used instead of `core` when appropriate in messages.
This commit is contained in:
commit
f444012c4c
@ -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::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then};
|
||||||
use clippy_utils::source::SpanRangeExt;
|
use clippy_utils::source::SpanRangeExt;
|
||||||
use clippy_utils::visitors::contains_unsafe_block;
|
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 hir::LifetimeName;
|
||||||
use rustc_errors::{Applicability, MultiSpan};
|
use rustc_errors::{Applicability, MultiSpan};
|
||||||
use rustc_hir::hir_id::{HirId, HirIdMap};
|
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 {
|
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(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
INVALID_NULL_PTR_USAGE,
|
INVALID_NULL_PTR_USAGE,
|
||||||
arg.span,
|
arg.span,
|
||||||
"pointer must be non-null",
|
"pointer must be non-null",
|
||||||
"change this to",
|
"change this to",
|
||||||
"core::ptr::NonNull::dangling().as_ptr()".to_string(),
|
format!("{std_or_core}::ptr::NonNull::dangling().as_ptr()"),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,44 +1,44 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
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(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_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::<usize>(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
|
||||||
std::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
|
||||||
struct A; // zero sized struct
|
struct A; // zero sized struct
|
||||||
assert_eq!(std::mem::size_of::<A>(), 0);
|
assert_eq!(std::mem::size_of::<A>(), 0);
|
||||||
|
|
||||||
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(core::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(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(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(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(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(std::ptr::null_mut(), 0); // shouldn't lint
|
||||||
let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);
|
let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);
|
||||||
|
|
||||||
std::ptr::swap::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A);
|
std::ptr::swap::<A>(std::ptr::NonNull::dangling().as_ptr(), &mut A);
|
||||||
std::ptr::swap::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr());
|
std::ptr::swap::<A>(&mut A, std::ptr::NonNull::dangling().as_ptr());
|
||||||
|
|
||||||
std::ptr::swap_nonoverlapping::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0);
|
std::ptr::swap_nonoverlapping::<A>(std::ptr::NonNull::dangling().as_ptr(), &mut A, 0);
|
||||||
std::ptr::swap_nonoverlapping::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0);
|
std::ptr::swap_nonoverlapping::<A>(&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::<usize>(core::ptr::NonNull::dangling().as_ptr(), 42, 0);
|
std::ptr::write_bytes::<usize>(std::ptr::NonNull::dangling().as_ptr(), 42, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ error: pointer must be non-null
|
|||||||
--> tests/ui/invalid_null_ptr_usage.rs:3:59
|
--> tests/ui/invalid_null_ptr_usage.rs:3:59
|
||||||
|
|
|
|
||||||
LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0);
|
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
|
= 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
|
--> tests/ui/invalid_null_ptr_usage.rs:4:59
|
||||||
|
|
|
|
||||||
LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0);
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:6:63
|
--> tests/ui/invalid_null_ptr_usage.rs:6:63
|
||||||
|
|
|
|
||||||
LL | let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0);
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:8:33
|
--> tests/ui/invalid_null_ptr_usage.rs:8:33
|
||||||
|
|
|
|
||||||
LL | std::ptr::copy::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
LL | std::ptr::copy::<usize>(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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:9:73
|
--> tests/ui/invalid_null_ptr_usage.rs:9:73
|
||||||
|
|
|
|
||||||
LL | std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0);
|
LL | std::ptr::copy::<usize>(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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:11:48
|
--> tests/ui/invalid_null_ptr_usage.rs:11:48
|
||||||
|
|
|
|
||||||
LL | std::ptr::copy_nonoverlapping::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0);
|
LL | std::ptr::copy_nonoverlapping::<usize>(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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:12:88
|
--> tests/ui/invalid_null_ptr_usage.rs:12:88
|
||||||
|
|
|
|
||||||
LL | std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0);
|
LL | std::ptr::copy_nonoverlapping::<usize>(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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:17:36
|
--> tests/ui/invalid_null_ptr_usage.rs:17:36
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::read(std::ptr::null());
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:18:36
|
--> tests/ui/invalid_null_ptr_usage.rs:18:36
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::read(std::ptr::null_mut());
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:20:46
|
--> tests/ui/invalid_null_ptr_usage.rs:20:46
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::read_unaligned(std::ptr::null());
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:21:46
|
--> tests/ui/invalid_null_ptr_usage.rs:21:46
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut());
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:23:45
|
--> tests/ui/invalid_null_ptr_usage.rs:23:45
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::read_volatile(std::ptr::null());
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:24:45
|
--> tests/ui/invalid_null_ptr_usage.rs:24:45
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut());
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:26:39
|
--> tests/ui/invalid_null_ptr_usage.rs:26:39
|
||||||
|
|
|
|
||||||
LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A);
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:30:29
|
--> tests/ui/invalid_null_ptr_usage.rs:30:29
|
||||||
|
|
|
|
||||||
LL | std::ptr::swap::<A>(std::ptr::null_mut(), &mut A);
|
LL | std::ptr::swap::<A>(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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:31:37
|
--> tests/ui/invalid_null_ptr_usage.rs:31:37
|
||||||
|
|
|
|
||||||
LL | std::ptr::swap::<A>(&mut A, std::ptr::null_mut());
|
LL | std::ptr::swap::<A>(&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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:33:44
|
--> tests/ui/invalid_null_ptr_usage.rs:33:44
|
||||||
|
|
|
|
||||||
LL | std::ptr::swap_nonoverlapping::<A>(std::ptr::null_mut(), &mut A, 0);
|
LL | std::ptr::swap_nonoverlapping::<A>(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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:34:52
|
--> tests/ui/invalid_null_ptr_usage.rs:34:52
|
||||||
|
|
|
|
||||||
LL | std::ptr::swap_nonoverlapping::<A>(&mut A, std::ptr::null_mut(), 0);
|
LL | std::ptr::swap_nonoverlapping::<A>(&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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:36:25
|
--> tests/ui/invalid_null_ptr_usage.rs:36:25
|
||||||
|
|
|
|
||||||
LL | std::ptr::write(std::ptr::null_mut(), A);
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:38:35
|
--> tests/ui/invalid_null_ptr_usage.rs:38:35
|
||||||
|
|
|
|
||||||
LL | std::ptr::write_unaligned(std::ptr::null_mut(), A);
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:40:34
|
--> tests/ui/invalid_null_ptr_usage.rs:40:34
|
||||||
|
|
|
|
||||||
LL | std::ptr::write_volatile(std::ptr::null_mut(), A);
|
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
|
error: pointer must be non-null
|
||||||
--> tests/ui/invalid_null_ptr_usage.rs:42:40
|
--> tests/ui/invalid_null_ptr_usage.rs:42:40
|
||||||
|
|
|
|
||||||
LL | std::ptr::write_bytes::<usize>(std::ptr::null_mut(), 42, 0);
|
LL | std::ptr::write_bytes::<usize>(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
|
error: aborting due to 22 previous errors
|
||||||
|
|
||||||
|
57
tests/ui/invalid_null_ptr_usage_no_std.fixed
Normal file
57
tests/ui/invalid_null_ptr_usage_no_std.fixed
Normal file
@ -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::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
core::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
|
||||||
|
core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
|
||||||
|
struct A; // zero sized struct
|
||||||
|
assert_eq!(core::mem::size_of::<A>(), 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::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A);
|
||||||
|
core::ptr::swap::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr());
|
||||||
|
|
||||||
|
core::ptr::swap_nonoverlapping::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0);
|
||||||
|
core::ptr::swap_nonoverlapping::<A>(&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::<usize>(core::ptr::NonNull::dangling().as_ptr(), 42, 0);
|
||||||
|
}
|
||||||
|
}
|
57
tests/ui/invalid_null_ptr_usage_no_std.rs
Normal file
57
tests/ui/invalid_null_ptr_usage_no_std.rs
Normal file
@ -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::<usize>(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
core::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0);
|
||||||
|
|
||||||
|
core::ptr::copy_nonoverlapping::<usize>(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0);
|
||||||
|
core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0);
|
||||||
|
|
||||||
|
struct A; // zero sized struct
|
||||||
|
assert_eq!(core::mem::size_of::<A>(), 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::<A>(core::ptr::null_mut(), &mut A);
|
||||||
|
core::ptr::swap::<A>(&mut A, core::ptr::null_mut());
|
||||||
|
|
||||||
|
core::ptr::swap_nonoverlapping::<A>(core::ptr::null_mut(), &mut A, 0);
|
||||||
|
core::ptr::swap_nonoverlapping::<A>(&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::<usize>(core::ptr::null_mut(), 42, 0);
|
||||||
|
}
|
||||||
|
}
|
136
tests/ui/invalid_null_ptr_usage_no_std.stderr
Normal file
136
tests/ui/invalid_null_ptr_usage_no_std.stderr
Normal file
@ -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::<usize>(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::<usize>(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::<usize>(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::<usize>(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::<A>(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::<A>(&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::<A>(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::<A>(&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::<usize>(core::ptr::null_mut(), 42, 0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
|
||||||
|
|
||||||
|
error: aborting due to 22 previous errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user