@@ -13,8 +13,8 @@ use crate::consts::{constant, Constant};
13
13
use crate :: utils:: sugg:: Sugg ;
14
14
use crate :: utils:: {
15
15
get_item_name, get_parent_expr, implements_trait, in_constant, is_integer_const, iter_input_pats,
16
- last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then ,
17
- span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq ,
16
+ last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_sugg ,
17
+ span_lint_and_then , span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq ,
18
18
} ;
19
19
20
20
declare_clippy_lint ! {
@@ -623,15 +623,14 @@ fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
623
623
if_chain ! {
624
624
if let TyKind :: Ptr ( MutTy { mutbl, .. } ) = ty. kind;
625
625
if let ExprKind :: Lit ( ref lit) = e. kind;
626
- if let LitKind :: Int ( value, ..) = lit. node;
627
- if value == 0 ;
626
+ if let LitKind :: Int ( 0 , _) = lit. node;
628
627
if !in_constant( cx, e. hir_id) ;
629
628
then {
630
- let msg = match mutbl {
631
- Mutability :: MutMutable => "`0 as *mut _` detected. Consider using `ptr::null_mut()`" ,
632
- Mutability :: MutImmutable => "`0 as *const _` detected. Consider using `ptr::null()`" ,
629
+ let ( msg, sugg ) = match mutbl {
630
+ Mutability :: MutMutable => ( "`0 as *mut _` detected. Consider using `ptr::null_mut()`" , "std::ptr::null_mut()" ) ,
631
+ Mutability :: MutImmutable => ( "`0 as *const _` detected. Consider using `ptr::null()`" , "std::ptr::null()" ) ,
633
632
} ;
634
- span_lint ( cx, ZERO_PTR , span, msg) ;
633
+ span_lint_and_sugg ( cx, ZERO_PTR , span, msg, "try" , sugg . to_string ( ) , Applicability :: MaybeIncorrect ) ;
635
634
}
636
635
}
637
636
}
0 commit comments