about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorllogiq <bogusandre@gmail.com>2025-06-08 08:57:45 +0000
committerGitHub <noreply@github.com>2025-06-08 08:57:45 +0000
commita1a139317163a5db3fc45a86de42b19d860d129e (patch)
tree031cd9e7e73656903bf4415009e0135e59681acb /tests
parent0138c79f7695aea2fdc9abaa1ecea662217efce2 (diff)
parentf397a302a968344e8a9403206119d146bcdff7b2 (diff)
downloadrust-a1a139317163a5db3fc45a86de42b19d860d129e.tar.gz
rust-a1a139317163a5db3fc45a86de42b19d860d129e.zip
Invert suggestion if pointer is tested for non-nullness (#15015)
Fixes rust-lang/rust-clippy#15010

----

changelog: [`cmp_null`]: emit proper suggestion when pointer is checked
for non-nullness
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/cmp_null.fixed6
-rw-r--r--tests/ui/cmp_null.rs6
-rw-r--r--tests/ui/cmp_null.stderr8
3 files changed, 19 insertions, 1 deletions
diff --git a/tests/ui/cmp_null.fixed b/tests/ui/cmp_null.fixed
index 140ddb10aeb..04b8ec50160 100644
--- a/tests/ui/cmp_null.fixed
+++ b/tests/ui/cmp_null.fixed
@@ -33,3 +33,9 @@ fn main() {
     let _ = (x as *const ()).is_null();
     //~^ cmp_null
 }
+
+fn issue15010() {
+    let f: *mut i32 = std::ptr::null_mut();
+    debug_assert!(!f.is_null());
+    //~^ cmp_null
+}
diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs
index 16ed17765da..6f7762e6ae8 100644
--- a/tests/ui/cmp_null.rs
+++ b/tests/ui/cmp_null.rs
@@ -33,3 +33,9 @@ fn main() {
     let _ = x as *const () == ptr::null();
     //~^ cmp_null
 }
+
+fn issue15010() {
+    let f: *mut i32 = std::ptr::null_mut();
+    debug_assert!(f != std::ptr::null_mut());
+    //~^ cmp_null
+}
diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr
index 6821846d046..8a75b050111 100644
--- a/tests/ui/cmp_null.stderr
+++ b/tests/ui/cmp_null.stderr
@@ -31,5 +31,11 @@ error: comparing with null is better expressed by the `.is_null()` method
 LL |     let _ = x as *const () == ptr::null();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(x as *const ()).is_null()`
 
-error: aborting due to 5 previous errors
+error: comparing with null is better expressed by the `.is_null()` method
+  --> tests/ui/cmp_null.rs:39:19
+   |
+LL |     debug_assert!(f != std::ptr::null_mut());
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!f.is_null()`
+
+error: aborting due to 6 previous errors