@@ -2,6 +2,7 @@ use if_chain::if_chain;
22use rustc:: hir:: { Expr , ExprKind } ;
33use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
44use rustc:: { declare_lint_pass, declare_tool_lint} ;
5+ use syntax_pos:: Span ;
56
67use crate :: consts:: { constant, Constant } ;
78use crate :: utils:: { in_macro, is_direct_expn_of, span_help_and_lint} ;
@@ -33,14 +34,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3334impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for AssertionsOnConstants {
3435 fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , e : & ' tcx Expr ) {
3536 let mut is_debug_assert = false ;
37+ let debug_assert_not_in_macro = |span : Span | {
38+ is_debug_assert = true ;
39+ // Check that `debug_assert!` itself is not inside a macro
40+ !in_macro ( span)
41+ } ;
3642 if_chain ! {
3743 if let Some ( assert_span) = is_direct_expn_of( e. span, "assert" ) ;
3844 if !in_macro( assert_span)
39- || is_direct_expn_of( assert_span, "debug_assert" ) . map_or( false , |span| {
40- is_debug_assert = true ;
41- // Check that `debug_assert!` itself is not inside a macro
42- !in_macro( span)
43- } ) ;
45+ || is_direct_expn_of( assert_span, "debug_assert" )
46+ . map_or( false , debug_assert_not_in_macro) ;
4447 if let ExprKind :: Unary ( _, ref lit) = e. node;
4548 if let Some ( bool_const) = constant( cx, cx. tables, lit) ;
4649 then {
0 commit comments