Skip to content

Commit 834ad76

Browse files
committed
Remove code duplication
1 parent 40218ba commit 834ad76

File tree

1 file changed

+21
-45
lines changed

1 file changed

+21
-45
lines changed

clippy_lints/src/assertions_on_constants.rs

+21-45
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
55

66
use crate::consts::{constant, Constant};
7-
use crate::syntax::ast::LitKind;
87
use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
98

109
declare_clippy_lint! {
@@ -43,51 +42,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4342
!in_macro(span)
4443
});
4544
if let ExprKind::Unary(_, ref lit) = e.node;
45+
if let Some(bool_const) = constant(cx, cx.tables, lit);
4646
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+
_ => (),
9167
}
9268
}
9369
}

0 commit comments

Comments
 (0)