]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/match_on_vec_items.rs
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
[rust.git] / clippy_lints / src / match_on_vec_items.rs
index 4a025e0621f9643f9903c2c32ae9ab277588b86e..086dae9422f9b57184af6e39f796377ec285e54d 100644 (file)
@@ -1,10 +1,11 @@
-use crate::utils::{self, is_type_diagnostic_item, match_type, snippet, span_lint_and_sugg, walk_ptrs_ty};
+use crate::utils::{is_type_diagnostic_item, is_type_lang_item, snippet, span_lint_and_sugg};
 use if_chain::if_chain;
 use rustc_errors::Applicability;
-use rustc_hir::{Expr, ExprKind, MatchSource};
+use rustc_hir::{Expr, ExprKind, LangItem, MatchSource};
 use rustc_lint::{LateContext, LateLintPass, LintContext};
 use rustc_middle::lint::in_external_macro;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
 
 declare_clippy_lint! {
     /// **What it does:** Checks for `match vec[idx]` or `match vec[n..m]`.
@@ -44,8 +45,8 @@
 
 declare_lint_pass!(MatchOnVecItems => [MATCH_ON_VEC_ITEMS]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchOnVecItems {
-    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) {
+impl<'tcx> LateLintPass<'tcx> for MatchOnVecItems {
+    fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
         if_chain! {
             if !in_external_macro(cx.sess(), expr.span);
             if let ExprKind::Match(ref match_expr, _, MatchSource::Normal) = expr.kind;
@@ -73,7 +74,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) {
     }
 }
 
-fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
+fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
     if_chain! {
         if let ExprKind::Index(ref array, ref index) = expr.kind;
         if is_vector(cx, array);
@@ -87,14 +88,14 @@ fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>)
     None
 }
 
-fn is_vector(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
-    let ty = cx.tables().expr_ty(expr);
-    let ty = walk_ptrs_ty(ty);
-    is_type_diagnostic_item(cx, ty, sym!(vec_type))
+fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
+    let ty = cx.typeck_results().expr_ty(expr);
+    let ty = ty.peel_refs();
+    is_type_diagnostic_item(cx, ty, sym::vec_type)
 }
 
-fn is_full_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
-    let ty = cx.tables().expr_ty(expr);
-    let ty = walk_ptrs_ty(ty);
-    match_type(cx, ty, &utils::paths::RANGE_FULL)
+fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
+    let ty = cx.typeck_results().expr_ty(expr);
+    let ty = ty.peel_refs();
+    is_type_lang_item(cx, ty, LangItem::RangeFull)
 }