Skip to content

Commit c73aceb

Browse files
committed
indexing_slicing: Check HIR tree first.
1 parent 06f83b4 commit c73aceb

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

clippy_lints/src/indexing_slicing.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,16 @@ impl IndexingSlicing {
102102

103103
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
104104
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
105-
if (self.suppress_restriction_lint_in_const && cx.tcx.hir().is_inside_const_context(expr.hir_id))
106-
|| is_from_proc_macro(cx, expr)
107-
{
108-
return;
109-
}
110-
111105
if let ExprKind::Index(array, index, _) = &expr.kind
106+
&& (!self.suppress_restriction_lint_in_const || !cx.tcx.hir().is_inside_const_context(expr.hir_id))
112107
&& let expr_ty = cx.typeck_results().expr_ty(array)
113108
&& let mut deref = deref_chain(cx, expr_ty)
114109
&& deref.any(|l| {
115110
l.peel_refs().is_slice()
116111
|| l.peel_refs().is_array()
117112
|| ty_has_applicable_get_function(cx, l.peel_refs(), expr_ty, expr)
118113
})
114+
&& !is_from_proc_macro(cx, expr)
119115
{
120116
let note = "the suggestion might not be applicable in constant blocks";
121117
let ty = cx.typeck_results().expr_ty(array).peel_refs();

0 commit comments

Comments
 (0)