diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-24 21:32:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-24 21:32:28 +0100 |
| commit | 50d2f302cbf512271eac3e6242f08e7d77e1a2f3 (patch) | |
| tree | 6e085ee24af62a4c6b50887205137270d6d19f3e /src/libcore | |
| parent | 89feaf6d960c42fb56cbbd215005f6ec7249cad9 (diff) | |
| parent | a7ab7b136ee347e7b80523994a060e6784b3b219 (diff) | |
| download | rust-50d2f302cbf512271eac3e6242f08e7d77e1a2f3.tar.gz rust-50d2f302cbf512271eac3e6242f08e7d77e1a2f3.zip | |
Rollup merge of #70234 - anp:tracked-std-traits, r=Amanieu
#[track_caller] on core::ops::{Index, IndexMut}.
Applies the attribute to `core::ops::Index(Mut)` and enough std internals to cover the [functions listed in "tier 1" in the original RFC](https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md#survey-of-panicking-standard-functions).
Split out from #69251 to allow separate assessment of perf impact.
To my knowledge, this is the last piece of implementing RFC 2091.
Tracking issue: https://github.com/rust-lang/rust/issues/47809
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops/index.rs | 2 | ||||
| -rw-r--r-- | src/libcore/slice/mod.rs | 6 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 2 |
3 files changed, 10 insertions, 0 deletions
diff --git a/src/libcore/ops/index.rs b/src/libcore/ops/index.rs index aae06911224..64dd633f75d 100644 --- a/src/libcore/ops/index.rs +++ b/src/libcore/ops/index.rs @@ -65,6 +65,7 @@ pub trait Index<Idx: ?Sized> { /// Performs the indexing (`container[index]`) operation. #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), track_caller)] fn index(&self, index: Idx) -> &Self::Output; } @@ -166,5 +167,6 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind pub trait IndexMut<Idx: ?Sized>: Index<Idx> { /// Performs the mutable indexing (`container[index]`) operation. #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), track_caller)] fn index_mut(&mut self, index: Idx) -> &mut Self::Output; } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 0e12e6360da..2140a7be9ef 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -2306,6 +2306,7 @@ impl<T> [T] { /// assert_eq!(&bytes, b"Hello, Wello!"); /// ``` #[stable(feature = "copy_within", since = "1.37.0")] + #[track_caller] pub fn copy_within<R: ops::RangeBounds<usize>>(&mut self, src: R, dest: usize) where T: Copy, @@ -2721,18 +2722,21 @@ where #[inline(never)] #[cold] +#[track_caller] fn slice_index_len_fail(index: usize, len: usize) -> ! { panic!("index {} out of range for slice of length {}", index, len); } #[inline(never)] #[cold] +#[track_caller] fn slice_index_order_fail(index: usize, end: usize) -> ! { panic!("slice index starts at {} but ends at {}", index, end); } #[inline(never)] #[cold] +#[track_caller] fn slice_index_overflow_fail() -> ! { panic!("attempted to index slice up to maximum usize"); } @@ -2804,11 +2808,13 @@ pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed { /// Returns a shared reference to the output at this location, panicking /// if out of bounds. #[unstable(feature = "slice_index_methods", issue = "none")] + #[cfg_attr(not(bootstrap), track_caller)] fn index(self, slice: &T) -> &Self::Output; /// Returns a mutable reference to the output at this location, panicking /// if out of bounds. #[unstable(feature = "slice_index_methods", issue = "none")] + #[cfg_attr(not(bootstrap), track_caller)] fn index_mut(self, slice: &mut T) -> &mut Self::Output; } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 6ad0e68a88f..013ca182c13 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1794,6 +1794,7 @@ mod traits { #[inline(never)] #[cold] + #[track_caller] fn str_index_overflow_fail() -> ! { panic!("attempted to index str up to maximum usize"); } @@ -2185,6 +2186,7 @@ fn truncate_to_char_boundary(s: &str, mut max: usize) -> (bool, &str) { #[inline(never)] #[cold] +#[track_caller] fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! { const MAX_DISPLAY_LENGTH: usize = 256; let (truncated, s_trunc) = truncate_to_char_boundary(s, MAX_DISPLAY_LENGTH); |
