Skip to content

Commit

Permalink
Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obk
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 11, 2023
2 parents b485e4f + 103949b commit a8939e5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 223 deletions.
1 change: 0 additions & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::float_literal::LOSSY_FLOAT_LITERAL_INFO,
crate::floating_point_arithmetic::IMPRECISE_FLOPS_INFO,
crate::floating_point_arithmetic::SUBOPTIMAL_FLOPS_INFO,
crate::fn_null_check::FN_NULL_CHECK_INFO,
crate::format::USELESS_FORMAT_INFO,
crate::format_args::FORMAT_IN_FORMAT_ARGS_INFO,
crate::format_args::TO_STRING_IN_FORMAT_ARGS_INFO,
Expand Down
102 changes: 0 additions & 102 deletions clippy_lints/src/fn_null_check.rs

This file was deleted.

2 changes: 0 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ mod extra_unused_type_parameters;
mod fallible_impl_from;
mod float_literal;
mod floating_point_arithmetic;
mod fn_null_check;
mod format;
mod format_args;
mod format_impl;
Expand Down Expand Up @@ -1003,7 +1002,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
semicolon_outside_block_ignore_multiline,
))
});
store.register_late_pass(|_| Box::new(fn_null_check::FnNullCheck));
store.register_late_pass(|_| Box::new(permissions_set_readonly_false::PermissionsSetReadonlyFalse));
store.register_late_pass(|_| Box::new(size_of_ref::SizeOfRef));
store.register_late_pass(|_| Box::new(multiple_unsafe_ops_per_block::MultipleUnsafeOpsPerBlock));
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/renamed_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
("clippy::forget_copy", "forgetting_copy_types"),
("clippy::forget_ref", "forgetting_references"),
("clippy::fn_null_check", "incorrect_fn_null_checks"),
("clippy::into_iter_on_array", "array_into_iter"),
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
("clippy::invalid_ref", "invalid_value"),
Expand Down
22 changes: 0 additions & 22 deletions tests/ui/fn_null_check.rs

This file was deleted.

43 changes: 0 additions & 43 deletions tests/ui/fn_null_check.stderr

This file was deleted.

2 changes: 2 additions & 0 deletions tests/ui/rename.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#![allow(for_loops_over_fallibles)]
#![allow(forgetting_copy_types)]
#![allow(forgetting_references)]
#![allow(incorrect_fn_null_checks)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
Expand Down Expand Up @@ -89,6 +90,7 @@
#![warn(for_loops_over_fallibles)]
#![warn(forgetting_copy_types)]
#![warn(forgetting_references)]
#![warn(incorrect_fn_null_checks)]
#![warn(array_into_iter)]
#![warn(invalid_atomic_ordering)]
#![warn(invalid_value)]
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#![allow(for_loops_over_fallibles)]
#![allow(forgetting_copy_types)]
#![allow(forgetting_references)]
#![allow(incorrect_fn_null_checks)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
Expand Down Expand Up @@ -89,6 +90,7 @@
#![warn(clippy::for_loops_over_fallibles)]
#![warn(clippy::forget_copy)]
#![warn(clippy::forget_ref)]
#![warn(clippy::fn_null_check)]
#![warn(clippy::into_iter_on_array)]
#![warn(clippy::invalid_atomic_ordering)]
#![warn(clippy::invalid_ref)]
Expand Down
Loading

0 comments on commit a8939e5

Please sign in to comment.