Skip to content

Let String pass #[track_caller] to its Vec calls #142728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_confusables("append", "push")]
#[rustc_diagnostic_item = "string_push_str"]
Expand Down Expand Up @@ -1135,6 +1136,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "string_extend_from_within", since = "1.87.0")]
#[track_caller]
pub fn extend_from_within<R>(&mut self, src: R)
where
R: RangeBounds<usize>,
Expand Down Expand Up @@ -1206,6 +1208,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: usize) {
self.vec.reserve(additional)
Expand Down Expand Up @@ -1257,6 +1260,7 @@ impl String {
#[cfg(not(no_global_oom_handling))]
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
pub fn reserve_exact(&mut self, additional: usize) {
self.vec.reserve_exact(additional)
}
Expand Down Expand Up @@ -1352,6 +1356,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
self.vec.shrink_to_fit()
Expand Down Expand Up @@ -1379,6 +1384,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "shrink_to", since = "1.56.0")]
pub fn shrink_to(&mut self, min_capacity: usize) {
self.vec.shrink_to(min_capacity)
Expand All @@ -1400,6 +1406,7 @@ impl String {
#[cfg(not(no_global_oom_handling))]
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
pub fn push(&mut self, ch: char) {
let len = self.len();
let ch_len = ch.len_utf8();
Expand Down Expand Up @@ -1456,6 +1463,7 @@ impl String {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
pub fn truncate(&mut self, new_len: usize) {
if new_len <= self.len() {
assert!(self.is_char_boundary(new_len));
Expand Down Expand Up @@ -1511,6 +1519,7 @@ impl String {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
#[rustc_confusables("delete", "take")]
pub fn remove(&mut self, idx: usize) -> char {
let ch = match self[idx..].chars().next() {
Expand Down Expand Up @@ -1705,6 +1714,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_confusables("set")]
pub fn insert(&mut self, idx: usize, ch: char) {
Expand Down Expand Up @@ -1761,6 +1771,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "insert_str", since = "1.16.0")]
#[rustc_diagnostic_item = "string_insert_str"]
pub fn insert_str(&mut self, idx: usize, string: &str) {
Expand Down Expand Up @@ -1889,6 +1900,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
#[track_caller]
#[stable(feature = "string_split_off", since = "1.16.0")]
#[must_use = "use `.truncate()` if you don't need the other half"]
pub fn split_off(&mut self, at: usize) -> String {
Expand Down Expand Up @@ -1953,6 +1965,7 @@ impl String {
/// assert_eq!(s, "");
/// ```
#[stable(feature = "drain", since = "1.6.0")]
#[track_caller]
pub fn drain<R>(&mut self, range: R) -> Drain<'_>
where
R: RangeBounds<usize>,
Expand Down Expand Up @@ -2052,6 +2065,7 @@ impl String {
/// ```
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "splice", since = "1.27.0")]
#[track_caller]
pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
where
R: RangeBounds<usize>,
Expand Down Expand Up @@ -2101,6 +2115,7 @@ impl String {
#[stable(feature = "box_str", since = "1.4.0")]
#[must_use = "`self` will be dropped if the result is not used"]
#[inline]
#[track_caller]
pub fn into_boxed_str(self) -> Box<str> {
let slice = self.vec.into_boxed_slice();
unsafe { from_boxed_utf8_unchecked(slice) }
Expand Down Expand Up @@ -2288,6 +2303,7 @@ impl Error for FromUtf16Error {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl Clone for String {
#[track_caller]
fn clone(&self) -> Self {
String { vec: self.vec.clone() }
}
Expand All @@ -2296,6 +2312,7 @@ impl Clone for String {
///
/// This method is preferred over simply assigning `source.clone()` to `self`,
/// as it avoids reallocation if possible.
#[track_caller]
fn clone_from(&mut self, source: &Self) {
self.vec.clone_from(&source.vec);
}
Expand Down Expand Up @@ -2469,11 +2486,14 @@ impl<'a> Extend<Cow<'a, str>> for String {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl Extend<core::ascii::Char> for String {
#[inline]
#[track_caller]
fn extend<I: IntoIterator<Item = core::ascii::Char>>(&mut self, iter: I) {
self.vec.extend(iter.into_iter().map(|c| c.to_u8()));
}

#[inline]
#[track_caller]
fn extend_one(&mut self, c: core::ascii::Char) {
self.vec.push(c.to_u8());
}
Expand All @@ -2482,11 +2502,14 @@ impl Extend<core::ascii::Char> for String {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl<'a> Extend<&'a core::ascii::Char> for String {
#[inline]
#[track_caller]
fn extend<I: IntoIterator<Item = &'a core::ascii::Char>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
#[track_caller]
fn extend_one(&mut self, c: &'a core::ascii::Char) {
self.vec.push(c.to_u8());
}
Expand Down
Loading