@@ -3,7 +3,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind};
33use rustc_session:: { declare_lint, declare_lint_pass} ;
44use rustc_span:: sym;
55
6- use crate :: lints:: PtrNullChecksDiag ;
6+ use crate :: lints:: UselessPtrNullChecksDiag ;
77use crate :: { LateContext , LateLintPass , LintContext } ;
88
99declare_lint ! {
@@ -38,10 +38,10 @@ declare_lint_pass!(PtrNullChecks => [USELESS_PTR_NULL_CHECKS]);
3838/// a fn ptr, a reference, or a function call whose definition is
3939/// annotated with `#![rustc_never_returns_null_ptr]`.
4040/// 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 > (
4242 cx : & ' a LateContext < ' tcx > ,
4343 mut e : & ' a Expr < ' a > ,
44- ) -> Option < PtrNullChecksDiag < ' tcx > > {
44+ ) -> Option < UselessPtrNullChecksDiag < ' tcx > > {
4545 let mut had_at_least_one_cast = false ;
4646 loop {
4747 e = e. peel_blocks ( ) ;
@@ -50,14 +50,14 @@ fn incorrect_check<'a, 'tcx: 'a>(
5050 && cx. tcx . has_attr ( def_id, sym:: rustc_never_returns_null_ptr)
5151 && let Some ( fn_name) = cx. tcx . opt_item_ident ( def_id)
5252 {
53- return Some ( PtrNullChecksDiag :: FnRet { fn_name } ) ;
53+ return Some ( UselessPtrNullChecksDiag :: FnRet { fn_name } ) ;
5454 } else if let ExprKind :: Call ( path, _args) = e. kind
5555 && let ExprKind :: Path ( ref qpath) = path. kind
5656 && let Some ( def_id) = cx. qpath_res ( qpath, path. hir_id ) . opt_def_id ( )
5757 && cx. tcx . has_attr ( def_id, sym:: rustc_never_returns_null_ptr)
5858 && let Some ( fn_name) = cx. tcx . opt_item_ident ( def_id)
5959 {
60- return Some ( PtrNullChecksDiag :: FnRet { fn_name } ) ;
60+ return Some ( UselessPtrNullChecksDiag :: FnRet { fn_name } ) ;
6161 }
6262 e = if let ExprKind :: Cast ( expr, t) = e. kind
6363 && let TyKind :: Ptr ( _) = t. kind
@@ -73,9 +73,9 @@ fn incorrect_check<'a, 'tcx: 'a>(
7373 } else if had_at_least_one_cast {
7474 let orig_ty = cx. typeck_results ( ) . expr_ty ( e) ;
7575 return if orig_ty. is_fn ( ) {
76- Some ( PtrNullChecksDiag :: FnPtr { orig_ty, label : e. span } )
76+ Some ( UselessPtrNullChecksDiag :: FnPtr { orig_ty, label : e. span } )
7777 } else if orig_ty. is_ref ( ) {
78- Some ( PtrNullChecksDiag :: Ref { orig_ty, label : e. span } )
78+ Some ( UselessPtrNullChecksDiag :: Ref { orig_ty, label : e. span } )
7979 } else {
8080 None
8181 } ;
@@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
9797 cx. tcx. get_diagnostic_name( def_id) ,
9898 Some ( sym:: ptr_const_is_null | sym:: ptr_is_null)
9999 )
100- && let Some ( diag) = incorrect_check ( cx, arg) =>
100+ && let Some ( diag) = useless_check ( cx, arg) =>
101101 {
102102 cx. emit_span_lint ( USELESS_PTR_NULL_CHECKS , expr. span , diag)
103103 }
@@ -110,18 +110,18 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
110110 cx. tcx. get_diagnostic_name( def_id) ,
111111 Some ( sym:: ptr_const_is_null | sym:: ptr_is_null)
112112 )
113- && let Some ( diag) = incorrect_check ( cx, receiver) =>
113+ && let Some ( diag) = useless_check ( cx, receiver) =>
114114 {
115115 cx. emit_span_lint ( USELESS_PTR_NULL_CHECKS , expr. span , diag)
116116 }
117117
118118 ExprKind :: Binary ( op, left, right) if matches ! ( op. node, BinOpKind :: Eq ) => {
119119 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) {
122122 to_check = right;
123123 diag = ddiag;
124- } else if let Some ( ddiag) = incorrect_check ( cx, right) {
124+ } else if let Some ( ddiag) = useless_check ( cx, right) {
125125 to_check = left;
126126 diag = ddiag;
127127 } else {
0 commit comments