diff options
| author | bors <bors@rust-lang.org> | 2022-01-02 09:35:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-01-02 09:35:24 +0000 |
| commit | 82418f93ac70c2de31843dbe7c0e7d2174636688 (patch) | |
| tree | de1a9b4b47c050ea9123ff6b9fb04ae7b39d564b | |
| parent | f7934f693bceb4820751394be72b781e264da6d6 (diff) | |
| parent | 084ea21f171dacef758817a9ee1c8e058af4effe (diff) | |
| download | rust-82418f93ac70c2de31843dbe7c0e7d2174636688.tar.gz rust-82418f93ac70c2de31843dbe7c0e7d2174636688.zip | |
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.
| -rw-r--r-- | library/core/src/slice/mod.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 49dce89a494..0599f274013 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -585,6 +585,7 @@ impl<T> [T] { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_swap", issue = "83163")] #[inline] + #[track_caller] pub const fn swap(&mut self, a: usize, b: usize) { let _ = &self[a]; let _ = &self[b]; @@ -1501,6 +1502,7 @@ impl<T> [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] + #[track_caller] pub fn split_at(&self, mid: usize) -> (&[T], &[T]) { assert!(mid <= self.len()); // SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which @@ -1531,6 +1533,7 @@ impl<T> [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] + #[track_caller] pub fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) { assert!(mid <= self.len()); // SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which @@ -1670,6 +1673,7 @@ impl<T> [T] { /// ``` #[unstable(feature = "split_array", reason = "new API", issue = "90091")] #[inline] + #[track_caller] pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]) { let (a, b) = self.split_at(N); // SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at) @@ -1701,6 +1705,7 @@ impl<T> [T] { /// ``` #[unstable(feature = "split_array", reason = "new API", issue = "90091")] #[inline] + #[track_caller] pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]) { let (a, b) = self.split_at_mut(N); // SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at_mut) |
