diff options
| author | flip1995 <hello@philkrones.com> | 2019-02-05 19:05:42 +0100 |
|---|---|---|
| committer | flip1995 <hello@philkrones.com> | 2019-02-05 19:37:50 +0100 |
| commit | 446e2ecfb72cf91c8389a42357a168de77dd414b (patch) | |
| tree | 7e7ecda1fee610a84b42daab17434d1536deecd6 | |
| parent | 4259377ea61e4c830a49deda5be60c05a76a0a90 (diff) | |
| download | rust-446e2ecfb72cf91c8389a42357a168de77dd414b.tar.gz rust-446e2ecfb72cf91c8389a42357a168de77dd414b.zip | |
Don't warn about const assertions when assert is in a macro itself
| -rw-r--r-- | clippy_lints/src/assertions_on_constants.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index d420de3a4db..92ee9d1bc66 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -3,7 +3,7 @@ use crate::rustc::hir::{Expr, ExprKind}; use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; use crate::syntax::ast::LitKind; -use crate::utils::{is_direct_expn_of, span_help_and_lint}; +use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint}; use if_chain::if_chain; /// **What it does:** Check to call assert!(true/false) @@ -43,7 +43,9 @@ impl LintPass for AssertionsOnConstants { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { if_chain! { - if is_direct_expn_of(e.span, "assert").is_some(); + if let Some(assert_span) = is_direct_expn_of(e.span, "assert"); + if !in_macro(assert_span) + || is_direct_expn_of(assert_span, "debug_assert").map_or(false, |span| !in_macro(span)); if let ExprKind::Unary(_, ref lit) = e.node; then { if let ExprKind::Lit(ref inner) = lit.node { |
