1- use crate :: { lints:: PtrNullChecksDiag , LateContext , LateLintPass , LintContext } ;
1+ use crate :: { lints:: UselessPtrNullChecksDiag , LateContext , LateLintPass , LintContext } ;
22use rustc_ast:: LitKind ;
33use rustc_hir:: { BinOpKind , Expr , ExprKind , TyKind } ;
44use rustc_session:: { declare_lint, declare_lint_pass} ;
@@ -36,10 +36,10 @@ declare_lint_pass!(PtrNullChecks => [USELESS_PTR_NULL_CHECKS]);
3636/// a fn ptr, a reference, or a function call whose definition is
3737/// annotated with `#![rustc_never_returns_null_ptr]`.
3838/// 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 > (
4040 cx : & ' a LateContext < ' tcx > ,
4141 mut e : & ' a Expr < ' a > ,
42- ) -> Option < PtrNullChecksDiag < ' tcx > > {
42+ ) -> Option < UselessPtrNullChecksDiag < ' tcx > > {
4343 let mut had_at_least_one_cast = false ;
4444 loop {
4545 e = e. peel_blocks ( ) ;
@@ -48,14 +48,14 @@ fn incorrect_check<'a, 'tcx: 'a>(
4848 && cx. tcx . has_attr ( def_id, sym:: rustc_never_returns_null_ptr)
4949 && let Some ( fn_name) = cx. tcx . opt_item_ident ( def_id)
5050 {
51- return Some ( PtrNullChecksDiag :: FnRet { fn_name } ) ;
51+ return Some ( UselessPtrNullChecksDiag :: FnRet { fn_name } ) ;
5252 } else if let ExprKind :: Call ( path, _args) = e. kind
5353 && let ExprKind :: Path ( ref qpath) = path. kind
5454 && let Some ( def_id) = cx. qpath_res ( qpath, path. hir_id ) . opt_def_id ( )
5555 && cx. tcx . has_attr ( def_id, sym:: rustc_never_returns_null_ptr)
5656 && let Some ( fn_name) = cx. tcx . opt_item_ident ( def_id)
5757 {
58- return Some ( PtrNullChecksDiag :: FnRet { fn_name } ) ;
58+ return Some ( UselessPtrNullChecksDiag :: FnRet { fn_name } ) ;
5959 }
6060 e = if let ExprKind :: Cast ( expr, t) = e. kind
6161 && let TyKind :: Ptr ( _) = t. kind
@@ -71,9 +71,9 @@ fn incorrect_check<'a, 'tcx: 'a>(
7171 } else if had_at_least_one_cast {
7272 let orig_ty = cx. typeck_results ( ) . expr_ty ( e) ;
7373 return if orig_ty. is_fn ( ) {
74- Some ( PtrNullChecksDiag :: FnPtr { orig_ty, label : e. span } )
74+ Some ( UselessPtrNullChecksDiag :: FnPtr { orig_ty, label : e. span } )
7575 } else if orig_ty. is_ref ( ) {
76- Some ( PtrNullChecksDiag :: Ref { orig_ty, label : e. span } )
76+ Some ( UselessPtrNullChecksDiag :: Ref { orig_ty, label : e. span } )
7777 } else {
7878 None
7979 } ;
@@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
9595 cx. tcx. get_diagnostic_name( def_id) ,
9696 Some ( sym:: ptr_const_is_null | sym:: ptr_is_null)
9797 )
98- && let Some ( diag) = incorrect_check ( cx, arg) =>
98+ && let Some ( diag) = useless_check ( cx, arg) =>
9999 {
100100 cx. emit_spanned_lint ( USELESS_PTR_NULL_CHECKS , expr. span , diag)
101101 }
@@ -108,18 +108,18 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
108108 cx. tcx. get_diagnostic_name( def_id) ,
109109 Some ( sym:: ptr_const_is_null | sym:: ptr_is_null)
110110 )
111- && let Some ( diag) = incorrect_check ( cx, receiver) =>
111+ && let Some ( diag) = useless_check ( cx, receiver) =>
112112 {
113113 cx. emit_spanned_lint ( USELESS_PTR_NULL_CHECKS , expr. span , diag)
114114 }
115115
116116 ExprKind :: Binary ( op, left, right) if matches ! ( op. node, BinOpKind :: Eq ) => {
117117 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) {
120120 to_check = right;
121121 diag = ddiag;
122- } else if let Some ( ddiag) = incorrect_check ( cx, right) {
122+ } else if let Some ( ddiag) = useless_check ( cx, right) {
123123 to_check = left;
124124 diag = ddiag;
125125 } else {
0 commit comments