@@ -4,7 +4,6 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4
4
use rustc:: { declare_lint_pass, declare_tool_lint} ;
5
5
6
6
use crate :: consts:: { constant, Constant } ;
7
- use crate :: syntax:: ast:: LitKind ;
8
7
use crate :: utils:: { in_macro, is_direct_expn_of, span_help_and_lint} ;
9
8
10
9
declare_clippy_lint ! {
@@ -43,51 +42,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
43
42
!in_macro( span)
44
43
} ) ;
45
44
if let ExprKind :: Unary ( _, ref lit) = e. node;
45
+ if let Some ( bool_const) = constant( cx, cx. tables, lit) ;
46
46
then {
47
- if let ExprKind :: Lit ( ref inner) = lit. node {
48
- match inner. node {
49
- LitKind :: Bool ( true ) => {
50
- span_help_and_lint(
51
- cx,
52
- ASSERTIONS_ON_CONSTANTS ,
53
- e. span,
54
- "`assert!(true)` will be optimized out by the compiler" ,
55
- "remove it"
56
- ) ;
57
- } ,
58
- LitKind :: Bool ( false ) if !is_debug_assert => {
59
- span_help_and_lint(
60
- cx,
61
- ASSERTIONS_ON_CONSTANTS ,
62
- e. span,
63
- "`assert!(false)` should probably be replaced" ,
64
- "use `panic!()` or `unreachable!()`"
65
- ) ;
66
- } ,
67
- _ => ( ) ,
68
- }
69
- } else if let Some ( bool_const) = constant( cx, cx. tables, lit) {
70
- match bool_const. 0 {
71
- Constant :: Bool ( true ) => {
72
- span_help_and_lint(
73
- cx,
74
- ASSERTIONS_ON_CONSTANTS ,
75
- e. span,
76
- "`assert!(const: true)` will be optimized out by the compiler" ,
77
- "remove it"
78
- ) ;
79
- } ,
80
- Constant :: Bool ( false ) if !is_debug_assert => {
81
- span_help_and_lint(
82
- cx,
83
- ASSERTIONS_ON_CONSTANTS ,
84
- e. span,
85
- "`assert!(const: false)` should probably be replaced" ,
86
- "use `panic!()` or `unreachable!()`"
87
- ) ;
88
- } ,
89
- _ => ( ) ,
90
- }
47
+ match bool_const. 0 {
48
+ Constant :: Bool ( true ) => {
49
+ span_help_and_lint(
50
+ cx,
51
+ ASSERTIONS_ON_CONSTANTS ,
52
+ e. span,
53
+ "`assert!(true)` will be optimized out by the compiler" ,
54
+ "remove it"
55
+ ) ;
56
+ } ,
57
+ Constant :: Bool ( false ) if !is_debug_assert => {
58
+ span_help_and_lint(
59
+ cx,
60
+ ASSERTIONS_ON_CONSTANTS ,
61
+ e. span,
62
+ "`assert!(false)` should probably be replaced" ,
63
+ "use `panic!()` or `unreachable!()`"
64
+ ) ;
65
+ } ,
66
+ _ => ( ) ,
91
67
}
92
68
}
93
69
}
0 commit comments