Skip to content

Commit 8387d61

Browse files
committed
Auto merge of #142728 - kornelski:string-track, r=tgross35
Let String pass #[track_caller] to its Vec calls I've added `#[track_caller]` to `String` methods that delegate to `Vec` methods that already have `#[track_caller]`. I've also added `#[track_caller]` to methods that have `assert!` or `panic!` due to invalid inputs.
2 parents be19eda + c109b28 commit 8387d61

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

library/alloc/src/string.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ impl String {
11051105
/// ```
11061106
#[cfg(not(no_global_oom_handling))]
11071107
#[inline]
1108+
#[track_caller]
11081109
#[stable(feature = "rust1", since = "1.0.0")]
11091110
#[rustc_confusables("append", "push")]
11101111
#[rustc_diagnostic_item = "string_push_str"]
@@ -1135,6 +1136,7 @@ impl String {
11351136
/// ```
11361137
#[cfg(not(no_global_oom_handling))]
11371138
#[stable(feature = "string_extend_from_within", since = "1.87.0")]
1139+
#[track_caller]
11381140
pub fn extend_from_within<R>(&mut self, src: R)
11391141
where
11401142
R: RangeBounds<usize>,
@@ -1206,6 +1208,7 @@ impl String {
12061208
/// ```
12071209
#[cfg(not(no_global_oom_handling))]
12081210
#[inline]
1211+
#[track_caller]
12091212
#[stable(feature = "rust1", since = "1.0.0")]
12101213
pub fn reserve(&mut self, additional: usize) {
12111214
self.vec.reserve(additional)
@@ -1257,6 +1260,7 @@ impl String {
12571260
#[cfg(not(no_global_oom_handling))]
12581261
#[inline]
12591262
#[stable(feature = "rust1", since = "1.0.0")]
1263+
#[track_caller]
12601264
pub fn reserve_exact(&mut self, additional: usize) {
12611265
self.vec.reserve_exact(additional)
12621266
}
@@ -1352,6 +1356,7 @@ impl String {
13521356
/// ```
13531357
#[cfg(not(no_global_oom_handling))]
13541358
#[inline]
1359+
#[track_caller]
13551360
#[stable(feature = "rust1", since = "1.0.0")]
13561361
pub fn shrink_to_fit(&mut self) {
13571362
self.vec.shrink_to_fit()
@@ -1379,6 +1384,7 @@ impl String {
13791384
/// ```
13801385
#[cfg(not(no_global_oom_handling))]
13811386
#[inline]
1387+
#[track_caller]
13821388
#[stable(feature = "shrink_to", since = "1.56.0")]
13831389
pub fn shrink_to(&mut self, min_capacity: usize) {
13841390
self.vec.shrink_to(min_capacity)
@@ -1400,6 +1406,7 @@ impl String {
14001406
#[cfg(not(no_global_oom_handling))]
14011407
#[inline]
14021408
#[stable(feature = "rust1", since = "1.0.0")]
1409+
#[track_caller]
14031410
pub fn push(&mut self, ch: char) {
14041411
let len = self.len();
14051412
let ch_len = ch.len_utf8();
@@ -1456,6 +1463,7 @@ impl String {
14561463
/// ```
14571464
#[inline]
14581465
#[stable(feature = "rust1", since = "1.0.0")]
1466+
#[track_caller]
14591467
pub fn truncate(&mut self, new_len: usize) {
14601468
if new_len <= self.len() {
14611469
assert!(self.is_char_boundary(new_len));
@@ -1511,6 +1519,7 @@ impl String {
15111519
/// ```
15121520
#[inline]
15131521
#[stable(feature = "rust1", since = "1.0.0")]
1522+
#[track_caller]
15141523
#[rustc_confusables("delete", "take")]
15151524
pub fn remove(&mut self, idx: usize) -> char {
15161525
let ch = match self[idx..].chars().next() {
@@ -1705,6 +1714,7 @@ impl String {
17051714
/// ```
17061715
#[cfg(not(no_global_oom_handling))]
17071716
#[inline]
1717+
#[track_caller]
17081718
#[stable(feature = "rust1", since = "1.0.0")]
17091719
#[rustc_confusables("set")]
17101720
pub fn insert(&mut self, idx: usize, ch: char) {
@@ -1761,6 +1771,7 @@ impl String {
17611771
/// ```
17621772
#[cfg(not(no_global_oom_handling))]
17631773
#[inline]
1774+
#[track_caller]
17641775
#[stable(feature = "insert_str", since = "1.16.0")]
17651776
#[rustc_diagnostic_item = "string_insert_str"]
17661777
pub fn insert_str(&mut self, idx: usize, string: &str) {
@@ -1889,6 +1900,7 @@ impl String {
18891900
/// ```
18901901
#[cfg(not(no_global_oom_handling))]
18911902
#[inline]
1903+
#[track_caller]
18921904
#[stable(feature = "string_split_off", since = "1.16.0")]
18931905
#[must_use = "use `.truncate()` if you don't need the other half"]
18941906
pub fn split_off(&mut self, at: usize) -> String {
@@ -1953,6 +1965,7 @@ impl String {
19531965
/// assert_eq!(s, "");
19541966
/// ```
19551967
#[stable(feature = "drain", since = "1.6.0")]
1968+
#[track_caller]
19561969
pub fn drain<R>(&mut self, range: R) -> Drain<'_>
19571970
where
19581971
R: RangeBounds<usize>,
@@ -2052,6 +2065,7 @@ impl String {
20522065
/// ```
20532066
#[cfg(not(no_global_oom_handling))]
20542067
#[stable(feature = "splice", since = "1.27.0")]
2068+
#[track_caller]
20552069
pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
20562070
where
20572071
R: RangeBounds<usize>,
@@ -2101,6 +2115,7 @@ impl String {
21012115
#[stable(feature = "box_str", since = "1.4.0")]
21022116
#[must_use = "`self` will be dropped if the result is not used"]
21032117
#[inline]
2118+
#[track_caller]
21042119
pub fn into_boxed_str(self) -> Box<str> {
21052120
let slice = self.vec.into_boxed_slice();
21062121
unsafe { from_boxed_utf8_unchecked(slice) }
@@ -2288,6 +2303,7 @@ impl Error for FromUtf16Error {
22882303
#[cfg(not(no_global_oom_handling))]
22892304
#[stable(feature = "rust1", since = "1.0.0")]
22902305
impl Clone for String {
2306+
#[track_caller]
22912307
fn clone(&self) -> Self {
22922308
String { vec: self.vec.clone() }
22932309
}
@@ -2296,6 +2312,7 @@ impl Clone for String {
22962312
///
22972313
/// This method is preferred over simply assigning `source.clone()` to `self`,
22982314
/// as it avoids reallocation if possible.
2315+
#[track_caller]
22992316
fn clone_from(&mut self, source: &Self) {
23002317
self.vec.clone_from(&source.vec);
23012318
}
@@ -2469,11 +2486,14 @@ impl<'a> Extend<Cow<'a, str>> for String {
24692486
#[cfg(not(no_global_oom_handling))]
24702487
#[unstable(feature = "ascii_char", issue = "110998")]
24712488
impl Extend<core::ascii::Char> for String {
2489+
#[inline]
2490+
#[track_caller]
24722491
fn extend<I: IntoIterator<Item = core::ascii::Char>>(&mut self, iter: I) {
24732492
self.vec.extend(iter.into_iter().map(|c| c.to_u8()));
24742493
}
24752494

24762495
#[inline]
2496+
#[track_caller]
24772497
fn extend_one(&mut self, c: core::ascii::Char) {
24782498
self.vec.push(c.to_u8());
24792499
}
@@ -2482,11 +2502,14 @@ impl Extend<core::ascii::Char> for String {
24822502
#[cfg(not(no_global_oom_handling))]
24832503
#[unstable(feature = "ascii_char", issue = "110998")]
24842504
impl<'a> Extend<&'a core::ascii::Char> for String {
2505+
#[inline]
2506+
#[track_caller]
24852507
fn extend<I: IntoIterator<Item = &'a core::ascii::Char>>(&mut self, iter: I) {
24862508
self.extend(iter.into_iter().cloned());
24872509
}
24882510

24892511
#[inline]
2512+
#[track_caller]
24902513
fn extend_one(&mut self, c: &'a core::ascii::Char) {
24912514
self.vec.push(c.to_u8());
24922515
}

0 commit comments

Comments
 (0)