-use if_chain::if_chain;
-use rustc::declare_lint_pass;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc_session::declare_tool_lint;
-
use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
-use rustc::hir::intravisit::*;
-use rustc_hir::*;
+use if_chain::if_chain;
+use rustc::hir::map::Map;
+use rustc::lint::in_external_macro;
+use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
+use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Path, QPath, UnOp};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
declare_clippy_lint! {
}
impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
+ type Map = Map<'tcx>;
+
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
+ // Shouldn't lint when `expr` is in macro.
+ if in_external_macro(self.cx.tcx.sess, expr.span) {
+ return;
+ }
if let Some((cond, then, els)) = if_block(&expr) {
walk_expr(self, cond);
self.visit_branch(cond, then, false);
}
}
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir())
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
+ NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
}
}