Skip to content

Commit

Permalink
Rollup merge of rust-lang#87488 - kornelski:track-remove, r=dtolnay
Browse files Browse the repository at this point in the history
Track caller of Vec::remove()

`vec.remove(invalid)` doesn't print a helpful source position:

> thread 'main' panicked at 'removal index (is 99) should be < len (is 1)', **library/alloc/src/vec/mod.rs:1379:13**
  • Loading branch information
GuillaumeGomez committed Jul 27, 2021
2 parents c5e23cf + 624df18 commit 1305f88
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,11 @@ impl<T, A: Allocator> Vec<T, A> {
/// assert_eq!(v, [1, 3]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
pub fn remove(&mut self, index: usize) -> T {
#[cold]
#[inline(never)]
#[track_caller]
fn assert_failed(index: usize, len: usize) -> ! {
panic!("removal index (is {}) should be < len (is {})", index, len);
}
Expand Down

0 comments on commit 1305f88

Please sign in to comment.