Skip to content

Commit 29ab7d8

Browse files
authored
Rollup merge of rust-lang#49577 - tmccombs:string-splice-stabilize, r=TimNN
Stabilize String::replace_range Fixes rust-lang#44643
2 parents 7dad49f + e75c6a7 commit 29ab7d8

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

src/doc/unstable-book/src/library-features/splice.md

-22
This file was deleted.

src/liballoc/string.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ impl String {
15171517
}
15181518
}
15191519

1520-
/// Creates a splicing iterator that removes the specified range in the string,
1520+
/// Removes the specified range in the string,
15211521
/// and replaces it with the given string.
15221522
/// The given string doesn't need to be the same length as the range.
15231523
///
@@ -1537,21 +1537,20 @@ impl String {
15371537
/// Basic usage:
15381538
///
15391539
/// ```
1540-
/// #![feature(splice)]
15411540
/// let mut s = String::from("α is alpha, β is beta");
15421541
/// let beta_offset = s.find('β').unwrap_or(s.len());
15431542
///
15441543
/// // Replace the range up until the β from the string
1545-
/// s.splice(..beta_offset, "Α is capital alpha; ");
1544+
/// s.replace_range(..beta_offset, "Α is capital alpha; ");
15461545
/// assert_eq!(s, "Α is capital alpha; β is beta");
15471546
/// ```
1548-
#[unstable(feature = "splice", reason = "recently added", issue = "44643")]
1549-
pub fn splice<R>(&mut self, range: R, replace_with: &str)
1547+
#[stable(feature = "splice", since = "1.27.0")]
1548+
pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
15501549
where R: RangeBounds<usize>
15511550
{
15521551
// Memory safety
15531552
//
1554-
// The String version of Splice does not have the memory safety issues
1553+
// Replace_range does not have the memory safety issues of a vector Splice.
15551554
// of the vector version. The data is just plain bytes.
15561555

15571556
match range.start() {

src/liballoc/tests/string.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -443,53 +443,53 @@ fn test_drain() {
443443
}
444444

445445
#[test]
446-
fn test_splice() {
446+
fn test_replace_range() {
447447
let mut s = "Hello, world!".to_owned();
448-
s.splice(7..12, "世界");
448+
s.replace_range(7..12, "世界");
449449
assert_eq!(s, "Hello, 世界!");
450450
}
451451

452452
#[test]
453453
#[should_panic]
454-
fn test_splice_char_boundary() {
454+
fn test_replace_range_char_boundary() {
455455
let mut s = "Hello, 世界!".to_owned();
456-
s.splice(..8, "");
456+
s.replace_range(..8, "");
457457
}
458458

459459
#[test]
460-
fn test_splice_inclusive_range() {
460+
fn test_replace_range_inclusive_range() {
461461
let mut v = String::from("12345");
462-
v.splice(2..=3, "789");
462+
v.replace_range(2..=3, "789");
463463
assert_eq!(v, "127895");
464-
v.splice(1..=2, "A");
464+
v.replace_range(1..=2, "A");
465465
assert_eq!(v, "1A895");
466466
}
467467

468468
#[test]
469469
#[should_panic]
470-
fn test_splice_out_of_bounds() {
470+
fn test_replace_range_out_of_bounds() {
471471
let mut s = String::from("12345");
472-
s.splice(5..6, "789");
472+
s.replace_range(5..6, "789");
473473
}
474474

475475
#[test]
476476
#[should_panic]
477-
fn test_splice_inclusive_out_of_bounds() {
477+
fn test_replace_range_inclusive_out_of_bounds() {
478478
let mut s = String::from("12345");
479-
s.splice(5..=5, "789");
479+
s.replace_range(5..=5, "789");
480480
}
481481

482482
#[test]
483-
fn test_splice_empty() {
483+
fn test_replace_range_empty() {
484484
let mut s = String::from("12345");
485-
s.splice(1..2, "");
485+
s.replace_range(1..2, "");
486486
assert_eq!(s, "1345");
487487
}
488488

489489
#[test]
490-
fn test_splice_unbounded() {
490+
fn test_replace_range_unbounded() {
491491
let mut s = String::from("12345");
492-
s.splice(.., "");
492+
s.replace_range(.., "");
493493
assert_eq!(s, "");
494494
}
495495

0 commit comments

Comments
 (0)