Skip to content

Commit 843c5e3

Browse files
committed
Rename IndexVec::lastlast_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.)
1 parent acd27bb commit 843c5e3

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

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 {

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

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)

compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

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

0 commit comments

Comments
 (0)