Skip to content

Commit 10cd289

Browse files
committed
Fix dogfood error
1 parent 88359a1 commit 10cd289

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

clippy_lints/src/assertions_on_constants.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use if_chain::if_chain;
22
use rustc::hir::{Expr, ExprKind};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
5+
use syntax_pos::Span;
56

67
use crate::consts::{constant, Constant};
78
use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
@@ -33,14 +34,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3334
impl<'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

Comments
 (0)