Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
//
// Library features:
// tidy-alphabetical-start
#![feature(abort_immediate)]
Comment thread
nia-e marked this conversation as resolved.
Outdated
#![feature(allocator_api)]
#![feature(array_into_iter_constructors)]
#![feature(ascii_char)]
Expand Down
9 changes: 8 additions & 1 deletion library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,14 @@ impl String {
"end of range should be a character boundary"
);

// ignore-tidy-undocumented-unsafe
if replace_with.len() > checked_range.len() {
self.reserve(replace_with.len() - checked_range.len());
}
// SAFETY: We ensure that we're not replacing across a char boundary and
// that the new contents are valid UTF-8. The only potentially-unsound
// unwind from `splice` that would leave the string in an invalid state
// would be from an error growing the allocation, which we protect against
// by reserving it preemptively.
unsafe { self.as_mut_vec() }.splice(checked_range, replace_with.bytes());
}

Expand Down
Loading