Don't warn about const assertions when assert is in a macro itself

This commit is contained in:
flip1995 2019-02-05 19:05:42 +01:00
parent 4259377ea6
commit 446e2ecfb7
No known key found for this signature in database
GPG Key ID: 693086869D506637

View File

@ -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 {