Skip to content

Commit bc6f0f6

Browse files
committed
Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obk
Uplift `clippy::fn_null_check` lint This PR aims at uplifting the `clippy::fn_null_check` lint into rustc. ## `incorrect_fn_null_checks` (warn-by-default) The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null. ### Example ```rust let fn_ptr: fn() = /* somehow obtained nullable function pointer */ if (fn_ptr as *const ()).is_null() { /* ... */ } ``` ### Explanation Function pointers are assumed to be non-null, checking for their nullity is incorrect. ----- Mostly followed the instructions for uplifting a clippy lint described here: rust-lang/rust#99696 (review) `@rustbot` label: +I-lang-nominated r? compiler
2 parents 23494a9 + f9afe0e commit bc6f0f6

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

core/src/ptr/const_ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl<T: ?Sized> *const T {
3030
/// ```
3131
#[stable(feature = "rust1", since = "1.0.0")]
3232
#[rustc_const_unstable(feature = "const_ptr_is_null", issue = "74939")]
33+
#[rustc_diagnostic_item = "ptr_const_is_null"]
3334
#[inline]
3435
pub const fn is_null(self) -> bool {
3536
#[inline]

core/src/ptr/mut_ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl<T: ?Sized> *mut T {
2929
/// ```
3030
#[stable(feature = "rust1", since = "1.0.0")]
3131
#[rustc_const_unstable(feature = "const_ptr_is_null", issue = "74939")]
32+
#[rustc_diagnostic_item = "ptr_is_null"]
3233
#[inline]
3334
pub const fn is_null(self) -> bool {
3435
#[inline]

0 commit comments

Comments
 (0)