@@ -173,6 +173,9 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
173173 }
174174
175175 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
176+ const INVALID_NULL_PTR_USAGE_FNS : [ & [ & ' static str ] ; 2 ] =
177+ [ & paths:: SLICE_FROM_RAW_PARTS , & paths:: SLICE_FROM_RAW_PARTS_MUT ] ;
178+
176179 if let ExprKind :: Binary ( ref op, ref l, ref r) = expr. kind {
177180 if ( op. node == BinOpKind :: Eq || op. node == BinOpKind :: Ne ) && ( is_null_path ( l) || is_null_path ( r) ) {
178181 span_lint (
@@ -182,19 +185,22 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
182185 "comparing with null is better expressed by the `.is_null()` method" ,
183186 ) ;
184187 }
185- } else if let Some ( args) = match_function_call ( cx, expr, & paths:: SLICE_FROM_RAW_PARTS ) {
186- if let Some ( arg) = args. first ( ) {
187- if is_null_path ( arg) {
188- span_lint_and_sugg (
189- cx,
190- INVALID_NULL_PTR_USAGE ,
191- arg. span ,
192- "pointer must be non-null" ,
193- "change this to" ,
194- "core::ptr::NonNull::dangling().as_ptr()" . to_string ( ) ,
195- Applicability :: MachineApplicable ,
196- ) ;
197- }
188+ } else if let Some ( arg) = INVALID_NULL_PTR_USAGE_FNS
189+ . iter ( )
190+ . filter_map ( |fn_name| match_function_call ( cx, expr, fn_name) )
191+ . next ( )
192+ . and_then ( |args| args. first ( ) )
193+ {
194+ if is_null_path ( arg) {
195+ span_lint_and_sugg (
196+ cx,
197+ INVALID_NULL_PTR_USAGE ,
198+ arg. span ,
199+ "pointer must be non-null" ,
200+ "change this to" ,
201+ "core::ptr::NonNull::dangling().as_ptr()" . to_string ( ) ,
202+ Applicability :: MachineApplicable ,
203+ ) ;
198204 }
199205 }
200206 }
0 commit comments