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