]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/entry.rs
add `tcx` to `fn walk`
[rust.git] / clippy_lints / src / entry.rs
index 2eb8b1422ed8a4292091f41d526a5f7a21f2f963..627f746ec99716fd6510ba61cbd7b0912c327e53 100644 (file)
@@ -1,3 +1,4 @@
+use clippy_utils::higher;
 use clippy_utils::{
     can_move_expr_to_closure_no_visit,
     diagnostics::span_lint_and_sugg,
@@ -5,6 +6,7 @@
     source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context},
     SpanlessEq,
 };
+use core::fmt::Write;
 use rustc_errors::Applicability;
 use rustc_hir::{
     intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor},
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::{Span, SyntaxContext, DUMMY_SP};
-use std::fmt::Write;
 
 declare_clippy_lint! {
-    /// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap`
+    /// ### What it does
+    /// Checks for uses of `contains_key` + `insert` on `HashMap`
     /// or `BTreeMap`.
     ///
-    /// **Why is this bad?** Using `entry` is more efficient.
+    /// ### Why is this bad?
+    /// Using `entry` is more efficient.
     ///
-    /// **Known problems:** The suggestion may have type inference errors in some cases. e.g.
+    /// ### Known problems
+    /// The suggestion may have type inference errors in some cases. e.g.
     /// ```rust
     /// let mut map = std::collections::HashMap::new();
     /// let _ = if !map.contains_key(&0) {
@@ -31,7 +35,7 @@
     /// };
     /// ```
     ///
-    /// **Example:**
+    /// ### Example
     /// ```rust
     /// # use std::collections::HashMap;
     /// # let mut map = HashMap::new();
 impl<'tcx> LateLintPass<'tcx> for HashMapPass {
     #[allow(clippy::too_many_lines)]
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
-        let (cond_expr, then_expr, else_expr) = match expr.kind {
-            ExprKind::If(c, t, e) => (c, t, e),
+        let (cond_expr, then_expr, else_expr) = match higher::If::hir(expr) {
+            Some(higher::If { cond, then, r#else }) => (cond, then, r#else),
             _ => return,
         };
+
         let (map_ty, contains_expr) = match try_parse_contains(cx, cond_expr) {
             Some(x) => x,
             None => return,