@@ -33,10 +33,15 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
33
33
34
34
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for AssertionsOnConstants {
35
35
fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , e : & ' tcx Expr ) {
36
+ let mut is_debug_assert = false ;
36
37
if_chain ! {
37
38
if let Some ( assert_span) = is_direct_expn_of( e. span, "assert" ) ;
38
39
if !in_macro( assert_span)
39
- || is_direct_expn_of( assert_span, "debug_assert" ) . map_or( false , |span| !in_macro( span) ) ;
40
+ || is_direct_expn_of( assert_span, "debug_assert" ) . map_or( false , |span| {
41
+ is_debug_assert = true ;
42
+ // Check that `debug_assert!` itself is not inside a macro
43
+ !in_macro( span)
44
+ } ) ;
40
45
if let ExprKind :: Unary ( _, ref lit) = e. node;
41
46
then {
42
47
if let ExprKind :: Lit ( ref inner) = lit. node {
@@ -46,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
46
51
"assert!(true) will be optimized out by the compiler" ,
47
52
"remove it" ) ;
48
53
} ,
49
- LitKind :: Bool ( false ) => {
54
+ LitKind :: Bool ( false ) if !is_debug_assert => {
50
55
span_help_and_lint(
51
56
cx, ASSERTIONS_ON_CONSTANTS , e. span,
52
57
"assert!(false) should probably be replaced" ,
@@ -61,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
61
66
"assert!(const: true) will be optimized out by the compiler" ,
62
67
"remove it" ) ;
63
68
} ,
64
- Constant :: Bool ( false ) => {
69
+ Constant :: Bool ( false ) if !is_debug_assert => {
65
70
span_help_and_lint( cx, ASSERTIONS_ON_CONSTANTS , e. span,
66
71
"assert!(const: false) should probably be replaced" ,
67
72
"use panic!() or unreachable!()" ) ;
0 commit comments