Skip to content

Commit

Permalink
Rollup merge of rust-lang#122969 - cuviper:borrowck-rposition, r=matt…
Browse files Browse the repository at this point in the history
…hewjasper

Simplify an iterator search in borrowck diag

Rather than `.into_iter().rev().find_position(...)`, this case can
simply call `.iter().rposition(...)`.
  • Loading branch information
workingjubilee committed Mar 24, 2024
2 parents 992aa1e + 66f1e14 commit c94d229
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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, '*');
Expand Down

0 comments on commit c94d229

Please sign in to comment.