about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2024-03-23 17:24:13 -0700
committerJosh Stone <jistone@redhat.com>2024-03-23 17:24:13 -0700
commit66f1e14cc3fa48aa29ecd19274207bfd3fb08fa8 (patch)
treef9ae7ecf62c713a39876b83b41493ec56e746c67
parente50ab294714ae706f85948efb17fac3c599ba2d3 (diff)
downloadrust-66f1e14cc3fa48aa29ecd19274207bfd3fb08fa8.tar.gz
rust-66f1e14cc3fa48aa29ecd19274207bfd3fb08fa8.zip
Simplify an iterator search in borrowck diag
Rather than `.into_iter().rev().find_position(...)`, this case can
simply call `.iter().rposition(...)`.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mod.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs
index 11561539f6d..0106e285604 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mod.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs
@@ -4,7 +4,6 @@ use crate::session_diagnostics::{
     CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
     CaptureVarKind, CaptureVarPathUseCause, OnClosureNote,
 };
-use itertools::Itertools;
 use rustc_errors::{Applicability, Diag};
 use rustc_hir as hir;
 use rustc_hir::def::{CtorKind, Namespace};
@@ -226,16 +225,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                         }
                     } else {
                         if autoderef_index.is_none() {
-                            autoderef_index =
-                                match place.projection.into_iter().rev().find_position(|elem| {
-                                    !matches!(
-                                        elem,
-                                        ProjectionElem::Deref | ProjectionElem::Downcast(..)
-                                    )
-                                }) {
-                                    Some((index, _)) => Some(place.projection.len() - index),
-                                    None => Some(0),
-                                };
+                            autoderef_index = match place.projection.iter().rposition(|elem| {
+                                !matches!(
+                                    elem,
+                                    ProjectionElem::Deref | ProjectionElem::Downcast(..)
+                                )
+                            }) {
+                                Some(index) => Some(index + 1),
+                                None => Some(0),
+                            };
                         }
                         if index >= autoderef_index.unwrap() {
                             buf.insert(0, '*');