about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2024-06-11 15:11:20 -0400
committerJason Newcomb <jsnewcomb@pm.me>2024-07-07 16:26:57 -0400
commitc73aceb0435ca35e47d0d8361ce49a74ff3ec70b (patch)
treebaf7211534d9910fc7e552ed134705ead8e0d070
parent06f83b4e2603b9bb702383199e57480b88f2382a (diff)
downloadrust-c73aceb0435ca35e47d0d8361ce49a74ff3ec70b.tar.gz
rust-c73aceb0435ca35e47d0d8361ce49a74ff3ec70b.zip
`indexing_slicing`: Check HIR tree first.
-rw-r--r--clippy_lints/src/indexing_slicing.rs8
1 files changed, 2 insertions, 6 deletions
diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs
index d54f2af65cd..52073d2ee4c 100644
--- a/clippy_lints/src/indexing_slicing.rs
+++ b/clippy_lints/src/indexing_slicing.rs
@@ -102,13 +102,8 @@ impl IndexingSlicing {
 
 impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
-        if (self.suppress_restriction_lint_in_const && cx.tcx.hir().is_inside_const_context(expr.hir_id))
-            || is_from_proc_macro(cx, expr)
-        {
-            return;
-        }
-
         if let ExprKind::Index(array, index, _) = &expr.kind
+            && (!self.suppress_restriction_lint_in_const || !cx.tcx.hir().is_inside_const_context(expr.hir_id))
             && let expr_ty = cx.typeck_results().expr_ty(array)
             && let mut deref = deref_chain(cx, expr_ty)
             && deref.any(|l| {
@@ -116,6 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
                     || l.peel_refs().is_array()
                     || ty_has_applicable_get_function(cx, l.peel_refs(), expr_ty, expr)
             })
+            && !is_from_proc_macro(cx, expr)
         {
             let note = "the suggestion might not be applicable in constant blocks";
             let ty = cx.typeck_results().expr_ty(array).peel_refs();