Skip to content

Commit c109b28

Browse files
committed
Add #[track_caller] to String methods that assert inputs
1 parent b26dfa1 commit c109b28

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/alloc/src/string.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ impl String {
14631463
/// ```
14641464
#[inline]
14651465
#[stable(feature = "rust1", since = "1.0.0")]
1466+
#[track_caller]
14661467
pub fn truncate(&mut self, new_len: usize) {
14671468
if new_len <= self.len() {
14681469
assert!(self.is_char_boundary(new_len));
@@ -1518,6 +1519,7 @@ impl String {
15181519
/// ```
15191520
#[inline]
15201521
#[stable(feature = "rust1", since = "1.0.0")]
1522+
#[track_caller]
15211523
#[rustc_confusables("delete", "take")]
15221524
pub fn remove(&mut self, idx: usize) -> char {
15231525
let ch = match self[idx..].chars().next() {
@@ -1712,6 +1714,7 @@ impl String {
17121714
/// ```
17131715
#[cfg(not(no_global_oom_handling))]
17141716
#[inline]
1717+
#[track_caller]
17151718
#[stable(feature = "rust1", since = "1.0.0")]
17161719
#[rustc_confusables("set")]
17171720
pub fn insert(&mut self, idx: usize, ch: char) {
@@ -1768,6 +1771,7 @@ impl String {
17681771
/// ```
17691772
#[cfg(not(no_global_oom_handling))]
17701773
#[inline]
1774+
#[track_caller]
17711775
#[stable(feature = "insert_str", since = "1.16.0")]
17721776
#[rustc_diagnostic_item = "string_insert_str"]
17731777
pub fn insert_str(&mut self, idx: usize, string: &str) {
@@ -1961,6 +1965,7 @@ impl String {
19611965
/// assert_eq!(s, "");
19621966
/// ```
19631967
#[stable(feature = "drain", since = "1.6.0")]
1968+
#[track_caller]
19641969
pub fn drain<R>(&mut self, range: R) -> Drain<'_>
19651970
where
19661971
R: RangeBounds<usize>,
@@ -2060,6 +2065,7 @@ impl String {
20602065
/// ```
20612066
#[cfg(not(no_global_oom_handling))]
20622067
#[stable(feature = "splice", since = "1.27.0")]
2068+
#[track_caller]
20632069
pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
20642070
where
20652071
R: RangeBounds<usize>,

0 commit comments

Comments
 (0)