Allow block_in_if_{stmt,expr} in external macro

This commit is contained in:
flip1995 2019-08-27 09:43:03 +02:00
parent 949b347f65
commit d36c785344
No known key found for this signature in database
GPG key ID: 693086869D506637

View file

@ -2,7 +2,7 @@ use crate::utils::*;
use matches::matches; use matches::matches;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
@ -72,6 +72,9 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_external_macro(cx.sess(), expr.span) {
return;
}
if let Some((check, then, _)) = higher::if_block(&expr) { if let Some((check, then, _)) = higher::if_block(&expr) {
if let ExprKind::Block(block, _) = &check.node { if let ExprKind::Block(block, _) = &check.node {
if block.rules == DefaultBlock { if block.rules == DefaultBlock {