Skip to content

Commit 1415756

Browse files
authored
Rollup merge of rust-lang#109718 - scottmcm:indexvec-last, r=Nilstrieb
Rename `IndexVec::last` → `last_index` As I've been trying to replace a `Vec` with an `IndexVec`, having `last` exist on both but returning very different types makes the transition a bit awkward -- the errors are later, where you get things like "there's no `ty` method on `mir::Field`" rather than a more localized error like "hey, there's no `last` on `IndexVec`". So I propose renaming `last` to `last_index` to help distinguish `Vec::last`, which returns an element, and `IndexVec::last_index`, which returns an index. (Similarly, `Iterator::last` also returns an element, not an index.)
2 parents 2a4455d + 843c5e3 commit 1415756

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

Diff for: compiler/rustc_const_eval/src/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
707707
}
708708

709709
fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) {
710-
let last = self.promoted.basic_blocks.last().unwrap();
710+
let last = self.promoted.basic_blocks.last_index().unwrap();
711711
let data = &mut self.promoted[last];
712712
data.statements.push(Statement {
713713
source_info: SourceInfo::outermost(span),
@@ -800,7 +800,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
800800
self.visit_operand(arg, loc);
801801
}
802802

803-
let last = self.promoted.basic_blocks.last().unwrap();
803+
let last = self.promoted.basic_blocks.last_index().unwrap();
804804
let new_target = self.new_block();
805805

806806
*self.promoted[last].terminator_mut() = Terminator {

Diff for: compiler/rustc_index/src/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<I: Idx, T> IndexVec<I, T> {
216216
}
217217

218218
#[inline]
219-
pub fn last(&self) -> Option<I> {
219+
pub fn last_index(&self) -> Option<I> {
220220
self.len().checked_sub(1).map(I::new)
221221
}
222222

Diff for: compiler/rustc_mir_transform/src/coverage/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> MockBlocks<'tcx> {
6565
}
6666

6767
fn push(&mut self, kind: TerminatorKind<'tcx>) -> BasicBlock {
68-
let next_lo = if let Some(last) = self.blocks.last() {
68+
let next_lo = if let Some(last) = self.blocks.last_index() {
6969
self.blocks[last].terminator().source_info.span.hi()
7070
} else {
7171
BytePos(1)

Diff for: compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'tcx> SearchGraph<'tcx> {
7070
/// Whether we're currently in a cycle. This should only be used
7171
/// for debug assertions.
7272
pub(super) fn in_cycle(&self) -> bool {
73-
if let Some(stack_depth) = self.stack.last() {
73+
if let Some(stack_depth) = self.stack.last_index() {
7474
// Either the current goal on the stack is the root of a cycle...
7575
if self.stack[stack_depth].has_been_used {
7676
return true;

0 commit comments

Comments
 (0)