Skip to content

Commit d2b7c80

Browse files
committed
Rename incorrect_fn_null_checks to useless_ptr_null_checks
1 parent 743ae5a commit d2b7c80

File tree

6 files changed

+47
-47
lines changed

6 files changed

+47
-47
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ lint_expectation = this lint expectation is unfulfilled
213213
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
214214
.rationale = {$rationale}
215215
216-
lint_fn_null_check_fn_ptr = function pointers are not nullable, so checking them for null will always return false
217-
.help = wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
218-
219-
lint_fn_null_check_ref = references are not nullable, so checking them for null will always return false
220-
.label = expression has type `{$orig_ty}`
221-
222216
lint_for_loops_over_fallibles =
223217
for loop over {$article} `{$ty}`. This is more readably written as an `if let` statement
224218
.suggestion = consider using `if let` to clear intent
@@ -453,6 +447,12 @@ lint_path_statement_drop = path statement drops value
453447
454448
lint_path_statement_no_effect = path statement with no effect
455449
450+
lint_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false
451+
.help = wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
452+
453+
lint_ptr_null_checks_ref = references are not nullable, so checking them for null will always return false
454+
.label = expression has type `{$orig_ty}`
455+
456456
lint_query_instability = using `{$query}` can result in unstable query results
457457
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
458458

compiler/rustc_lint/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ mod early;
5757
mod enum_intrinsics_non_enums;
5858
mod errors;
5959
mod expect;
60-
mod fn_null_check;
6160
mod for_loops_over_fallibles;
6261
pub mod hidden_unicode_codepoints;
6362
mod internal;
@@ -76,6 +75,7 @@ mod noop_method_call;
7675
mod opaque_hidden_inferred_bound;
7776
mod pass_by_value;
7877
mod passes;
78+
mod ptr_nulls;
7979
mod redundant_semicolon;
8080
mod reference_casting;
8181
mod traits;
@@ -102,7 +102,6 @@ use builtin::*;
102102
use deref_into_dyn_supertrait::*;
103103
use drop_forget_useless::*;
104104
use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums;
105-
use fn_null_check::*;
106105
use for_loops_over_fallibles::*;
107106
use hidden_unicode_codepoints::*;
108107
use internal::*;
@@ -117,6 +116,7 @@ use nonstandard_style::*;
117116
use noop_method_call::*;
118117
use opaque_hidden_inferred_bound::*;
119118
use pass_by_value::*;
119+
use ptr_nulls::*;
120120
use redundant_semicolon::*;
121121
use reference_casting::*;
122122
use traits::*;
@@ -227,7 +227,7 @@ late_lint_methods!(
227227
// Depends on types used in type definitions
228228
MissingCopyImplementations: MissingCopyImplementations,
229229
// Depends on referenced function signatures in expressions
230-
IncorrectFnNullChecks: IncorrectFnNullChecks,
230+
PtrNullChecks: PtrNullChecks,
231231
MutableTransmutes: MutableTransmutes,
232232
TypeAliasBounds: TypeAliasBounds,
233233
TrivialConstraints: TrivialConstraints,

compiler/rustc_lint/src/lints.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,13 @@ pub struct ExpectationNote {
613613
pub rationale: Symbol,
614614
}
615615

616-
// fn_null_check.rs
616+
// ptr_nulls.rs
617617
#[derive(LintDiagnostic)]
618-
pub enum FnNullCheckDiag<'a> {
619-
#[diag(lint_fn_null_check_fn_ptr)]
618+
pub enum PtrNullChecksDiag<'a> {
619+
#[diag(lint_ptr_null_checks_fn_ptr)]
620620
#[help(lint_help)]
621621
FnPtr,
622-
#[diag(lint_fn_null_check_ref)]
622+
#[diag(lint_ptr_null_checks_ref)]
623623
Ref {
624624
orig_ty: Ty<'a>,
625625
#[label]

compiler/rustc_lint/src/fn_null_check.rs renamed to compiler/rustc_lint/src/ptr_nulls.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::{lints::FnNullCheckDiag, LateContext, LateLintPass, LintContext};
1+
use crate::{lints::PtrNullChecksDiag, LateContext, LateLintPass, LintContext};
22
use rustc_ast::LitKind;
33
use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind};
44
use rustc_session::{declare_lint, declare_lint_pass};
55
use rustc_span::sym;
66

77
declare_lint! {
8-
/// The `incorrect_fn_null_checks` lint checks for expression that checks if a
9-
/// function pointer is null.
8+
/// The `useless_ptr_null_checks` lint checks for useless null checks against pointers
9+
/// obtained from non-null types.
1010
///
1111
/// ### Example
1212
///
@@ -22,16 +22,16 @@ declare_lint! {
2222
///
2323
/// ### Explanation
2424
///
25-
/// Function pointers are assumed to be non-null, checking them for null will always
26-
/// return false.
27-
INCORRECT_FN_NULL_CHECKS,
25+
/// Function pointers and references are assumed to be non-null, checking them for null
26+
/// will always return false.
27+
USELESS_PTR_NULL_CHECKS,
2828
Warn,
29-
"incorrect checking of null function pointer"
29+
"useless checking of non-null-typed pointer"
3030
}
3131

32-
declare_lint_pass!(IncorrectFnNullChecks => [INCORRECT_FN_NULL_CHECKS]);
32+
declare_lint_pass!(PtrNullChecks => [USELESS_PTR_NULL_CHECKS]);
3333

34-
fn incorrect_check<'a>(cx: &LateContext<'a>, expr: &Expr<'_>) -> Option<FnNullCheckDiag<'a>> {
34+
fn incorrect_check<'a>(cx: &LateContext<'a>, expr: &Expr<'_>) -> Option<PtrNullChecksDiag<'a>> {
3535
let mut expr = expr.peel_blocks();
3636
let mut had_at_least_one_cast = false;
3737
while let ExprKind::Cast(cast_expr, cast_ty) = expr.kind
@@ -44,16 +44,16 @@ fn incorrect_check<'a>(cx: &LateContext<'a>, expr: &Expr<'_>) -> Option<FnNullCh
4444
} else {
4545
let orig_ty = cx.typeck_results().expr_ty(expr);
4646
if orig_ty.is_fn() {
47-
Some(FnNullCheckDiag::FnPtr)
47+
Some(PtrNullChecksDiag::FnPtr)
4848
} else if orig_ty.is_ref() {
49-
Some(FnNullCheckDiag::Ref { orig_ty, label: expr.span })
49+
Some(PtrNullChecksDiag::Ref { orig_ty, label: expr.span })
5050
} else {
5151
None
5252
}
5353
}
5454
}
5555

56-
impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
56+
impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
5757
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5858
match expr.kind {
5959
// Catching:
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
6767
)
6868
&& let Some(diag) = incorrect_check(cx, arg) =>
6969
{
70-
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
70+
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
7171
}
7272

7373
// Catching:
@@ -80,12 +80,12 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
8080
)
8181
&& let Some(diag) = incorrect_check(cx, receiver) =>
8282
{
83-
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
83+
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
8484
}
8585

8686
ExprKind::Binary(op, left, right) if matches!(op.node, BinOpKind::Eq) => {
8787
let to_check: &Expr<'_>;
88-
let diag: FnNullCheckDiag<'_>;
88+
let diag: PtrNullChecksDiag<'_>;
8989
if let Some(ddiag) = incorrect_check(cx, left) {
9090
to_check = right;
9191
diag = ddiag;
@@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
103103
if let ExprKind::Lit(spanned) = cast_expr.kind
104104
&& let LitKind::Int(v, _) = spanned.node && v == 0 =>
105105
{
106-
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
106+
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
107107
},
108108

109109
// Catching:
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
114114
&& let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id)
115115
&& (diag_item == sym::ptr_null || diag_item == sym::ptr_null_mut) =>
116116
{
117-
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
117+
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
118118
},
119119

120120
_ => {},
File renamed without changes.

tests/ui/lint/fn_null_check.stderr renamed to tests/ui/lint/ptr_null_checks.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,126 @@
11
warning: function pointers are not nullable, so checking them for null will always return false
2-
--> $DIR/fn_null_check.rs:7:8
2+
--> $DIR/ptr_null_checks.rs:7:8
33
|
44
LL | if (fn_ptr as *mut ()).is_null() {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
8-
= note: `#[warn(incorrect_fn_null_checks)]` on by default
8+
= note: `#[warn(useless_ptr_null_checks)]` on by default
99

1010
warning: function pointers are not nullable, so checking them for null will always return false
11-
--> $DIR/fn_null_check.rs:9:8
11+
--> $DIR/ptr_null_checks.rs:9:8
1212
|
1313
LL | if (fn_ptr as *const u8).is_null() {}
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
1717

1818
warning: function pointers are not nullable, so checking them for null will always return false
19-
--> $DIR/fn_null_check.rs:11:8
19+
--> $DIR/ptr_null_checks.rs:11:8
2020
|
2121
LL | if (fn_ptr as *const ()) == std::ptr::null() {}
2222
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
2424
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
2525

2626
warning: function pointers are not nullable, so checking them for null will always return false
27-
--> $DIR/fn_null_check.rs:13:8
27+
--> $DIR/ptr_null_checks.rs:13:8
2828
|
2929
LL | if (fn_ptr as *mut ()) == std::ptr::null_mut() {}
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
|
3232
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
3333

3434
warning: function pointers are not nullable, so checking them for null will always return false
35-
--> $DIR/fn_null_check.rs:15:8
35+
--> $DIR/ptr_null_checks.rs:15:8
3636
|
3737
LL | if (fn_ptr as *const ()) == (0 as *const ()) {}
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
|
4040
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
4141

4242
warning: function pointers are not nullable, so checking them for null will always return false
43-
--> $DIR/fn_null_check.rs:17:8
43+
--> $DIR/ptr_null_checks.rs:17:8
4444
|
4545
LL | if <*const _>::is_null(fn_ptr as *const ()) {}
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4747
|
4848
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
4949

5050
warning: function pointers are not nullable, so checking them for null will always return false
51-
--> $DIR/fn_null_check.rs:19:8
51+
--> $DIR/ptr_null_checks.rs:19:8
5252
|
5353
LL | if (fn_ptr as *mut fn() as *const fn() as *const ()).is_null() {}
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5555
|
5656
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
5757

5858
warning: function pointers are not nullable, so checking them for null will always return false
59-
--> $DIR/fn_null_check.rs:21:8
59+
--> $DIR/ptr_null_checks.rs:21:8
6060
|
6161
LL | if (fn_ptr as fn() as *const ()).is_null() {}
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363
|
6464
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
6565

6666
warning: references are not nullable, so checking them for null will always return false
67-
--> $DIR/fn_null_check.rs:25:8
67+
--> $DIR/ptr_null_checks.rs:25:8
6868
|
6969
LL | if (&mut 8 as *mut i32).is_null() {}
7070
| ^------^^^^^^^^^^^^^^^^^^^^^^^
7171
| |
7272
| expression has type `&mut i32`
7373

7474
warning: references are not nullable, so checking them for null will always return false
75-
--> $DIR/fn_null_check.rs:27:8
75+
--> $DIR/ptr_null_checks.rs:27:8
7676
|
7777
LL | if (&8 as *const i32).is_null() {}
7878
| ^--^^^^^^^^^^^^^^^^^^^^^^^^^
7979
| |
8080
| expression has type `&i32`
8181

8282
warning: references are not nullable, so checking them for null will always return false
83-
--> $DIR/fn_null_check.rs:29:8
83+
--> $DIR/ptr_null_checks.rs:29:8
8484
|
8585
LL | if (&8 as *const i32) == std::ptr::null() {}
8686
| ^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787
| |
8888
| expression has type `&i32`
8989

9090
warning: references are not nullable, so checking them for null will always return false
91-
--> $DIR/fn_null_check.rs:32:8
91+
--> $DIR/ptr_null_checks.rs:32:8
9292
|
9393
LL | if (ref_num as *const i32) == std::ptr::null() {}
9494
| ^-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9595
| |
9696
| expression has type `&i32`
9797

9898
warning: references are not nullable, so checking them for null will always return false
99-
--> $DIR/fn_null_check.rs:34:8
99+
--> $DIR/ptr_null_checks.rs:34:8
100100
|
101101
LL | if (b"\0" as *const u8).is_null() {}
102102
| ^-----^^^^^^^^^^^^^^^^^^^^^^^^
103103
| |
104104
| expression has type `&[u8; 1]`
105105

106106
warning: references are not nullable, so checking them for null will always return false
107-
--> $DIR/fn_null_check.rs:36:8
107+
--> $DIR/ptr_null_checks.rs:36:8
108108
|
109109
LL | if ("aa" as *const str).is_null() {}
110110
| ^----^^^^^^^^^^^^^^^^^^^^^^^^^
111111
| |
112112
| expression has type `&str`
113113

114114
warning: references are not nullable, so checking them for null will always return false
115-
--> $DIR/fn_null_check.rs:38:8
115+
--> $DIR/ptr_null_checks.rs:38:8
116116
|
117117
LL | if (&[1, 2] as *const i32).is_null() {}
118118
| ^-------^^^^^^^^^^^^^^^^^^^^^^^^^
119119
| |
120120
| expression has type `&[i32; 2]`
121121

122122
warning: references are not nullable, so checking them for null will always return false
123-
--> $DIR/fn_null_check.rs:40:8
123+
--> $DIR/ptr_null_checks.rs:40:8
124124
|
125125
LL | if (&mut [1, 2] as *mut i32) == std::ptr::null_mut() {}
126126
| ^-----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)