11use clippy_utils:: consts:: { constant_context, Constant } ;
22use clippy_utils:: diagnostics:: span_lint;
3- use clippy_utils:: is_path_diagnostic_item;
4- use if_chain:: if_chain;
5- use rustc_ast:: LitKind ;
3+ use clippy_utils:: { is_integer_literal, is_path_diagnostic_item} ;
64use rustc_hir:: { Expr , ExprKind } ;
75use rustc_lint:: LateContext ;
86use rustc_middle:: ty:: Ty ;
@@ -19,37 +17,28 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
1917
2018 // Catching transmute over constants that resolve to `null`.
2119 let mut const_eval_context = constant_context ( cx, cx. typeck_results ( ) ) ;
22- if_chain ! {
23- if let ExprKind :: Path ( ref _qpath) = arg. kind;
24- if let Some ( Constant :: RawPtr ( x) ) = const_eval_context. expr( arg) ;
25- if x == 0 ;
26- then {
27- span_lint( cx, TRANSMUTING_NULL , expr. span, LINT_MSG ) ;
28- return true ;
29- }
20+ if let ExprKind :: Path ( ref _qpath) = arg. kind &&
21+ let Some ( Constant :: RawPtr ( x) ) = const_eval_context. expr ( arg) &&
22+ x == 0
23+ {
24+ span_lint ( cx, TRANSMUTING_NULL , expr. span , LINT_MSG ) ;
25+ return true ;
3026 }
3127
3228 // Catching:
3329 // `std::mem::transmute(0 as *const i32)`
34- if_chain ! {
35- if let ExprKind :: Cast ( inner_expr, _cast_ty) = arg. kind;
36- if let ExprKind :: Lit ( ref lit) = inner_expr. kind;
37- if let LitKind :: Int ( 0 , _) = lit. node;
38- then {
39- span_lint( cx, TRANSMUTING_NULL , expr. span, LINT_MSG ) ;
40- return true ;
41- }
30+ if let ExprKind :: Cast ( inner_expr, _cast_ty) = arg. kind && is_integer_literal ( inner_expr, 0 ) {
31+ span_lint ( cx, TRANSMUTING_NULL , expr. span , LINT_MSG ) ;
32+ return true ;
4233 }
4334
4435 // Catching:
4536 // `std::mem::transmute(std::ptr::null::<i32>())`
46- if_chain ! {
47- if let ExprKind :: Call ( func1, [ ] ) = arg. kind;
48- if is_path_diagnostic_item( cx, func1, sym:: ptr_null) ;
49- then {
50- span_lint( cx, TRANSMUTING_NULL , expr. span, LINT_MSG ) ;
51- return true ;
52- }
37+ if let ExprKind :: Call ( func1, [ ] ) = arg. kind &&
38+ is_path_diagnostic_item ( cx, func1, sym:: ptr_null)
39+ {
40+ span_lint ( cx, TRANSMUTING_NULL , expr. span , LINT_MSG ) ;
41+ return true ;
5342 }
5443
5544 // FIXME:
0 commit comments