about summary refs log tree commit diff
path: root/clippy_lints/src/methods
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-08-03 21:43:17 +0200
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-08-04 13:17:39 +0200
commited0dfed24f988cb2b52c819cd57c8eb65da400be (patch)
tree6ef1c4ae20455b74511aa0fb1f25f27c78c25dd9 /clippy_lints/src/methods
parentff27f9095f5edebdd03e885cb4df74ad32df30dc (diff)
downloadrust-ed0dfed24f988cb2b52c819cd57c8eb65da400be.tar.gz
rust-ed0dfed24f988cb2b52c819cd57c8eb65da400be.zip
Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
Diffstat (limited to 'clippy_lints/src/methods')
-rw-r--r--clippy_lints/src/methods/filter_next.rs2
-rw-r--r--clippy_lints/src/methods/iter_next_slice.rs2
2 files changed, 2 insertions, 2 deletions
diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs
index ce7f9997b5a..ac7bc9bcca4 100644
--- a/clippy_lints/src/methods/filter_next.rs
+++ b/clippy_lints/src/methods/filter_next.rs
@@ -12,7 +12,7 @@ use super::FILTER_NEXT;
 fn path_to_local(expr: &hir::Expr<'_>) -> Option<hir::HirId> {
     match expr.kind {
         hir::ExprKind::Field(f, _) => path_to_local(f),
-        hir::ExprKind::Index(recv, _) => path_to_local(recv),
+        hir::ExprKind::Index(recv, _, _) => path_to_local(recv),
         hir::ExprKind::Path(hir::QPath::Resolved(
             _,
             hir::Path {
diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs
index e2029da8081..8f885e9f729 100644
--- a/clippy_lints/src/methods/iter_next_slice.rs
+++ b/clippy_lints/src/methods/iter_next_slice.rs
@@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal
     if derefs_to_slice(cx, caller_expr, cx.typeck_results().expr_ty(caller_expr)).is_some() {
         // caller is a Slice
         if_chain! {
-            if let hir::ExprKind::Index(caller_var, index_expr) = &caller_expr.kind;
+            if let hir::ExprKind::Index(caller_var, index_expr, _) = &caller_expr.kind;
             if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen })
                 = higher::Range::hir(index_expr);
             if let hir::ExprKind::Lit(start_lit) = &start_expr.kind;