@@ -3,7 +3,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind};
3
3
use rustc_session:: { declare_lint, declare_lint_pass} ;
4
4
use rustc_span:: sym;
5
5
6
- use crate :: lints:: PtrNullChecksDiag ;
6
+ use crate :: lints:: UselessPtrNullChecksDiag ;
7
7
use crate :: { LateContext , LateLintPass , LintContext } ;
8
8
9
9
declare_lint ! {
@@ -38,10 +38,10 @@ declare_lint_pass!(PtrNullChecks => [USELESS_PTR_NULL_CHECKS]);
38
38
/// a fn ptr, a reference, or a function call whose definition is
39
39
/// annotated with `#![rustc_never_returns_null_ptr]`.
40
40
/// If this situation is present, the function returns the appropriate diagnostic.
41
- fn incorrect_check < ' a , ' tcx : ' a > (
41
+ fn useless_check < ' a , ' tcx : ' a > (
42
42
cx : & ' a LateContext < ' tcx > ,
43
43
mut e : & ' a Expr < ' a > ,
44
- ) -> Option < PtrNullChecksDiag < ' tcx > > {
44
+ ) -> Option < UselessPtrNullChecksDiag < ' tcx > > {
45
45
let mut had_at_least_one_cast = false ;
46
46
loop {
47
47
e = e. peel_blocks ( ) ;
@@ -50,14 +50,14 @@ fn incorrect_check<'a, 'tcx: 'a>(
50
50
&& cx. tcx . has_attr ( def_id, sym:: rustc_never_returns_null_ptr)
51
51
&& let Some ( fn_name) = cx. tcx . opt_item_ident ( def_id)
52
52
{
53
- return Some ( PtrNullChecksDiag :: FnRet { fn_name } ) ;
53
+ return Some ( UselessPtrNullChecksDiag :: FnRet { fn_name } ) ;
54
54
} else if let ExprKind :: Call ( path, _args) = e. kind
55
55
&& let ExprKind :: Path ( ref qpath) = path. kind
56
56
&& let Some ( def_id) = cx. qpath_res ( qpath, path. hir_id ) . opt_def_id ( )
57
57
&& cx. tcx . has_attr ( def_id, sym:: rustc_never_returns_null_ptr)
58
58
&& let Some ( fn_name) = cx. tcx . opt_item_ident ( def_id)
59
59
{
60
- return Some ( PtrNullChecksDiag :: FnRet { fn_name } ) ;
60
+ return Some ( UselessPtrNullChecksDiag :: FnRet { fn_name } ) ;
61
61
}
62
62
e = if let ExprKind :: Cast ( expr, t) = e. kind
63
63
&& let TyKind :: Ptr ( _) = t. kind
@@ -73,9 +73,9 @@ fn incorrect_check<'a, 'tcx: 'a>(
73
73
} else if had_at_least_one_cast {
74
74
let orig_ty = cx. typeck_results ( ) . expr_ty ( e) ;
75
75
return if orig_ty. is_fn ( ) {
76
- Some ( PtrNullChecksDiag :: FnPtr { orig_ty, label : e. span } )
76
+ Some ( UselessPtrNullChecksDiag :: FnPtr { orig_ty, label : e. span } )
77
77
} else if orig_ty. is_ref ( ) {
78
- Some ( PtrNullChecksDiag :: Ref { orig_ty, label : e. span } )
78
+ Some ( UselessPtrNullChecksDiag :: Ref { orig_ty, label : e. span } )
79
79
} else {
80
80
None
81
81
} ;
@@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
97
97
cx. tcx. get_diagnostic_name( def_id) ,
98
98
Some ( sym:: ptr_const_is_null | sym:: ptr_is_null)
99
99
)
100
- && let Some ( diag) = incorrect_check ( cx, arg) =>
100
+ && let Some ( diag) = useless_check ( cx, arg) =>
101
101
{
102
102
cx. emit_span_lint ( USELESS_PTR_NULL_CHECKS , expr. span , diag)
103
103
}
@@ -110,18 +110,18 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
110
110
cx. tcx. get_diagnostic_name( def_id) ,
111
111
Some ( sym:: ptr_const_is_null | sym:: ptr_is_null)
112
112
)
113
- && let Some ( diag) = incorrect_check ( cx, receiver) =>
113
+ && let Some ( diag) = useless_check ( cx, receiver) =>
114
114
{
115
115
cx. emit_span_lint ( USELESS_PTR_NULL_CHECKS , expr. span , diag)
116
116
}
117
117
118
118
ExprKind :: Binary ( op, left, right) if matches ! ( op. node, BinOpKind :: Eq ) => {
119
119
let to_check: & Expr < ' _ > ;
120
- let diag: PtrNullChecksDiag < ' _ > ;
121
- if let Some ( ddiag) = incorrect_check ( cx, left) {
120
+ let diag: UselessPtrNullChecksDiag < ' _ > ;
121
+ if let Some ( ddiag) = useless_check ( cx, left) {
122
122
to_check = right;
123
123
diag = ddiag;
124
- } else if let Some ( ddiag) = incorrect_check ( cx, right) {
124
+ } else if let Some ( ddiag) = useless_check ( cx, right) {
125
125
to_check = left;
126
126
diag = ddiag;
127
127
} else {
0 commit comments