Skip to content

Commit 82418f9

Browse files
committed
Auto merge of #91961 - kornelski:track_split_caller, r=joshtriplett
Track caller of slice split and swap Improves error location for `slice.split_at*()` and `slice.swap()`. These are generic inline functions, so the `#[track_caller]` on them is free — only changes a value of an argument already passed to panicking code.
2 parents f7934f6 + 084ea21 commit 82418f9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: library/core/src/slice/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ impl<T> [T] {
585585
#[stable(feature = "rust1", since = "1.0.0")]
586586
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
587587
#[inline]
588+
#[track_caller]
588589
pub const fn swap(&mut self, a: usize, b: usize) {
589590
let _ = &self[a];
590591
let _ = &self[b];
@@ -1501,6 +1502,7 @@ impl<T> [T] {
15011502
/// ```
15021503
#[stable(feature = "rust1", since = "1.0.0")]
15031504
#[inline]
1505+
#[track_caller]
15041506
pub fn split_at(&self, mid: usize) -> (&[T], &[T]) {
15051507
assert!(mid <= self.len());
15061508
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
@@ -1531,6 +1533,7 @@ impl<T> [T] {
15311533
/// ```
15321534
#[stable(feature = "rust1", since = "1.0.0")]
15331535
#[inline]
1536+
#[track_caller]
15341537
pub fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
15351538
assert!(mid <= self.len());
15361539
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
@@ -1670,6 +1673,7 @@ impl<T> [T] {
16701673
/// ```
16711674
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
16721675
#[inline]
1676+
#[track_caller]
16731677
pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]) {
16741678
let (a, b) = self.split_at(N);
16751679
// SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at)
@@ -1701,6 +1705,7 @@ impl<T> [T] {
17011705
/// ```
17021706
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
17031707
#[inline]
1708+
#[track_caller]
17041709
pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]) {
17051710
let (a, b) = self.split_at_mut(N);
17061711
// SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)

0 commit comments

Comments
 (0)