diff options
| author | dswij <dharmasw@outlook.com> | 2025-06-28 08:46:57 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-28 08:46:57 +0000 |
| commit | 8633bcbc3c7f71e463c7c9f81b03f0aa11728eb8 (patch) | |
| tree | b3bea3c17f03b182f8a16805841b39634354cafb /tests | |
| parent | c5dbd1de07e0407b9687619a868384d6de06253f (diff) | |
| parent | 9117cb0223eaf72ab9015cee10549b2b774d8f74 (diff) | |
| download | rust-8633bcbc3c7f71e463c7c9f81b03f0aa11728eb8.tar.gz rust-8633bcbc3c7f71e463c7c9f81b03f0aa11728eb8.zip | |
`zero_ptr`: lint in `const` context as well (#15152)
The lint was extra restrictive, and didn't suggest using `core::ptr::null` and `core::ptr::null_mut` in `const` contexts although they have been const-stabilized since Rust 1.24. changelog: [`zero_ptr`]: lint in `const` context as well @rustbot label +I-false-negative +C-bug
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/zero_ptr.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/zero_ptr.rs | 8 | ||||
| -rw-r--r-- | tests/ui/zero_ptr.stderr | 8 |
3 files changed, 23 insertions, 1 deletions
diff --git a/tests/ui/zero_ptr.fixed b/tests/ui/zero_ptr.fixed index f2375d57f3a..f9d9d2db176 100644 --- a/tests/ui/zero_ptr.fixed +++ b/tests/ui/zero_ptr.fixed @@ -16,3 +16,11 @@ fn main() { let z = 0; let _ = z as *const usize; // this is currently not caught } + +const fn in_const_context() { + #[clippy::msrv = "1.23"] + let _: *const usize = 0 as *const _; + #[clippy::msrv = "1.24"] + let _: *const usize = std::ptr::null(); + //~^ zero_ptr +} diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs index ee01e426a43..41455fee5b5 100644 --- a/tests/ui/zero_ptr.rs +++ b/tests/ui/zero_ptr.rs @@ -16,3 +16,11 @@ fn main() { let z = 0; let _ = z as *const usize; // this is currently not caught } + +const fn in_const_context() { + #[clippy::msrv = "1.23"] + let _: *const usize = 0 as *const _; + #[clippy::msrv = "1.24"] + let _: *const usize = 0 as *const _; + //~^ zero_ptr +} diff --git a/tests/ui/zero_ptr.stderr b/tests/ui/zero_ptr.stderr index 8dc781f3625..81269de6c60 100644 --- a/tests/ui/zero_ptr.stderr +++ b/tests/ui/zero_ptr.stderr @@ -31,5 +31,11 @@ error: `0 as *mut _` detected LL | foo(0 as *const _, 0 as *mut _); | ^^^^^^^^^^^ help: try: `std::ptr::null_mut()` -error: aborting due to 5 previous errors +error: `0 as *const _` detected + --> tests/ui/zero_ptr.rs:24:27 + | +LL | let _: *const usize = 0 as *const _; + | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` + +error: aborting due to 6 previous errors |
