@@ -2,6 +2,7 @@ use if_chain::if_chain;
2
2
use rustc:: hir:: { Expr , ExprKind } ;
3
3
use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
4
4
use rustc:: { declare_lint_pass, declare_tool_lint} ;
5
+ use syntax_pos:: Span ;
5
6
6
7
use crate :: consts:: { constant, Constant } ;
7
8
use crate :: utils:: { in_macro, is_direct_expn_of, span_help_and_lint} ;
@@ -33,14 +34,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
33
34
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for AssertionsOnConstants {
34
35
fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , e : & ' tcx Expr ) {
35
36
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
+ } ;
36
42
if_chain ! {
37
43
if let Some ( assert_span) = is_direct_expn_of( e. span, "assert" ) ;
38
44
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) ;
44
47
if let ExprKind :: Unary ( _, ref lit) = e. node;
45
48
if let Some ( bool_const) = constant( cx, cx. tables, lit) ;
46
49
then {
0 commit comments