Skip to content

Commit 890c87b

Browse files
committed
Auto merge of #44186 - alexcrichton:rollup, r=alexcrichton
Rollup of 8 pull requests - Successful merges: #44044, #44089, #44116, #44125, #44154, #44157, #44160, #44172 - Failed merges: #44162
2 parents 7eeac1b + b9fea42 commit 890c87b

File tree

37 files changed

+691
-206
lines changed

37 files changed

+691
-206
lines changed

Diff for: src/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/doc/unstable-book/src/language-features/generators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The tracking issue for this feature is: [#43122]
44

5-
[#34511]: https://github.com/rust-lang/rust/issues/43122
5+
[#43122]: https://github.com/rust-lang/rust/issues/43122
66

77
------------------------
88

Diff for: src/doc/unstable-book/src/library-features/splice.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ let mut s = String::from("α is alpha, β is beta");
1818
let beta_offset = s.find('β').unwrap_or(s.len());
1919

2020
// Replace the range up until the β from the string
21-
let t: String = s.splice(..beta_offset, "Α is capital alpha; ").collect();
22-
assert_eq!(t, "α is alpha, ");
21+
s.splice(..beta_offset, "Α is capital alpha; ");
2322
assert_eq!(s, "Α is capital alpha; β is beta");
2423
```

Diff for: src/liballoc/macros.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/// Creates a `Vec` containing the arguments.
11+
/// Creates a [`Vec`] containing the arguments.
1212
///
1313
/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions.
1414
/// There are two forms of this macro:
1515
///
16-
/// - Create a `Vec` containing a given list of elements:
16+
/// - Create a [`Vec`] containing a given list of elements:
1717
///
1818
/// ```
1919
/// let v = vec![1, 2, 3];
@@ -22,22 +22,25 @@
2222
/// assert_eq!(v[2], 3);
2323
/// ```
2424
///
25-
/// - Create a `Vec` from a given element and size:
25+
/// - Create a [`Vec`] from a given element and size:
2626
///
2727
/// ```
2828
/// let v = vec![1; 3];
2929
/// assert_eq!(v, [1, 1, 1]);
3030
/// ```
3131
///
3232
/// Note that unlike array expressions this syntax supports all elements
33-
/// which implement `Clone` and the number of elements doesn't have to be
33+
/// which implement [`Clone`] and the number of elements doesn't have to be
3434
/// a constant.
3535
///
36-
/// This will use `clone()` to duplicate an expression, so one should be careful
36+
/// This will use `clone` to duplicate an expression, so one should be careful
3737
/// using this with types having a nonstandard `Clone` implementation. For
3838
/// example, `vec![Rc::new(1); 5]` will create a vector of five references
3939
/// to the same boxed integer value, not five references pointing to independently
4040
/// boxed integers.
41+
///
42+
/// [`Vec`]: ../std/vec/struct.Vec.html
43+
/// [`Clone`]: ../std/clone/trait.Clone.html
4144
#[cfg(not(test))]
4245
#[macro_export]
4346
#[stable(feature = "rust1", since = "1.0.0")]
@@ -67,10 +70,22 @@ macro_rules! vec {
6770
($($x:expr,)*) => (vec![$($x),*])
6871
}
6972

70-
/// Use the syntax described in `std::fmt` to create a value of type `String`.
71-
/// See [`std::fmt`][fmt] for more information.
73+
/// Creates a `String` using interpolation of runtime expressions.
74+
///
75+
/// The first argument `format!` recieves is a format string. This must be a string
76+
/// literal. The power of the formatting string is in the `{}`s contained.
77+
///
78+
/// Additional parameters passed to `format!` replace the `{}`s within the
79+
/// formatting string in the order given unless named or positional parameters
80+
/// are used, see [`std::fmt`][fmt] for more information.
81+
///
82+
/// A common use for `format!` is concatenation and interpolation of strings.
83+
/// The same convention is used with [`print!`] and [`write!`] macros,
84+
/// depending on the intended destination of the string.
7285
///
7386
/// [fmt]: ../std/fmt/index.html
87+
/// [`print!`]: ../std/macro.print.html
88+
/// [`write!`]: ../std/macro.write.html
7489
///
7590
/// # Panics
7691
///

Diff for: src/liballoc/string.rs

+19-90
Original file line numberDiff line numberDiff line change
@@ -1392,19 +1392,19 @@ impl String {
13921392
}
13931393

13941394
/// Creates a splicing iterator that removes the specified range in the string,
1395-
/// replaces with the given string, and yields the removed chars.
1396-
/// The given string doesnt need to be the same length as the range.
1395+
/// and replaces it with the given string.
1396+
/// The given string doesn't need to be the same length as the range.
13971397
///
1398-
/// Note: The element range is removed when the [`Splice`] is dropped,
1399-
/// even if the iterator is not consumed until the end.
1398+
/// Note: Unlike [`Vec::splice`], the replacement happens eagerly, and this
1399+
/// method does not return the removed chars.
14001400
///
14011401
/// # Panics
14021402
///
14031403
/// Panics if the starting point or end point do not lie on a [`char`]
14041404
/// boundary, or if they're out of bounds.
14051405
///
14061406
/// [`char`]: ../../std/primitive.char.html
1407-
/// [`Splice`]: ../../std/string/struct.Splice.html
1407+
/// [`Vec::splice`]: ../../std/vec/struct.Vec.html#method.splice
14081408
///
14091409
/// # Examples
14101410
///
@@ -1416,45 +1416,32 @@ impl String {
14161416
/// let beta_offset = s.find('β').unwrap_or(s.len());
14171417
///
14181418
/// // Replace the range up until the β from the string
1419-
/// let t: String = s.splice(..beta_offset, "Α is capital alpha; ").collect();
1420-
/// assert_eq!(t, "α is alpha, ");
1419+
/// s.splice(..beta_offset, "Α is capital alpha; ");
14211420
/// assert_eq!(s, "Α is capital alpha; β is beta");
14221421
/// ```
14231422
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
1424-
pub fn splice<'a, 'b, R>(&'a mut self, range: R, replace_with: &'b str) -> Splice<'a, 'b>
1423+
pub fn splice<R>(&mut self, range: R, replace_with: &str)
14251424
where R: RangeArgument<usize>
14261425
{
14271426
// Memory safety
14281427
//
14291428
// The String version of Splice does not have the memory safety issues
14301429
// of the vector version. The data is just plain bytes.
1431-
// Because the range removal happens in Drop, if the Splice iterator is leaked,
1432-
// the removal will not happen.
1433-
let len = self.len();
1434-
let start = match range.start() {
1435-
Included(&n) => n,
1436-
Excluded(&n) => n + 1,
1437-
Unbounded => 0,
1430+
1431+
match range.start() {
1432+
Included(&n) => assert!(self.is_char_boundary(n)),
1433+
Excluded(&n) => assert!(self.is_char_boundary(n + 1)),
1434+
Unbounded => {},
14381435
};
1439-
let end = match range.end() {
1440-
Included(&n) => n + 1,
1441-
Excluded(&n) => n,
1442-
Unbounded => len,
1436+
match range.end() {
1437+
Included(&n) => assert!(self.is_char_boundary(n + 1)),
1438+
Excluded(&n) => assert!(self.is_char_boundary(n)),
1439+
Unbounded => {},
14431440
};
14441441

1445-
// Take out two simultaneous borrows. The &mut String won't be accessed
1446-
// until iteration is over, in Drop.
1447-
let self_ptr = self as *mut _;
1448-
// slicing does the appropriate bounds checks
1449-
let chars_iter = self[start..end].chars();
1450-
1451-
Splice {
1452-
start,
1453-
end,
1454-
iter: chars_iter,
1455-
string: self_ptr,
1456-
replace_with,
1457-
}
1442+
unsafe {
1443+
self.as_mut_vec()
1444+
}.splice(range, replace_with.bytes());
14581445
}
14591446

14601447
/// Converts this `String` into a [`Box`]`<`[`str`]`>`.
@@ -2241,61 +2228,3 @@ impl<'a> DoubleEndedIterator for Drain<'a> {
22412228

22422229
#[unstable(feature = "fused", issue = "35602")]
22432230
impl<'a> FusedIterator for Drain<'a> {}
2244-
2245-
/// A splicing iterator for `String`.
2246-
///
2247-
/// This struct is created by the [`splice()`] method on [`String`]. See its
2248-
/// documentation for more.
2249-
///
2250-
/// [`splice()`]: struct.String.html#method.splice
2251-
/// [`String`]: struct.String.html
2252-
#[derive(Debug)]
2253-
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
2254-
pub struct Splice<'a, 'b> {
2255-
/// Will be used as &'a mut String in the destructor
2256-
string: *mut String,
2257-
/// Start of part to remove
2258-
start: usize,
2259-
/// End of part to remove
2260-
end: usize,
2261-
/// Current remaining range to remove
2262-
iter: Chars<'a>,
2263-
replace_with: &'b str,
2264-
}
2265-
2266-
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
2267-
unsafe impl<'a, 'b> Sync for Splice<'a, 'b> {}
2268-
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
2269-
unsafe impl<'a, 'b> Send for Splice<'a, 'b> {}
2270-
2271-
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
2272-
impl<'a, 'b> Drop for Splice<'a, 'b> {
2273-
fn drop(&mut self) {
2274-
unsafe {
2275-
let vec = (*self.string).as_mut_vec();
2276-
vec.splice(self.start..self.end, self.replace_with.bytes());
2277-
}
2278-
}
2279-
}
2280-
2281-
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
2282-
impl<'a, 'b> Iterator for Splice<'a, 'b> {
2283-
type Item = char;
2284-
2285-
#[inline]
2286-
fn next(&mut self) -> Option<char> {
2287-
self.iter.next()
2288-
}
2289-
2290-
fn size_hint(&self) -> (usize, Option<usize>) {
2291-
self.iter.size_hint()
2292-
}
2293-
}
2294-
2295-
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
2296-
impl<'a, 'b> DoubleEndedIterator for Splice<'a, 'b> {
2297-
#[inline]
2298-
fn next_back(&mut self) -> Option<char> {
2299-
self.iter.next_back()
2300-
}
2301-
}

Diff for: src/liballoc/tests/string.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@ fn test_drain() {
442442
#[test]
443443
fn test_splice() {
444444
let mut s = "Hello, world!".to_owned();
445-
let t: String = s.splice(7..12, "世界").collect();
445+
s.splice(7..12, "世界");
446446
assert_eq!(s, "Hello, 世界!");
447-
assert_eq!(t, "world");
448447
}
449448

450449
#[test]
@@ -457,12 +456,10 @@ fn test_splice_char_boundary() {
457456
#[test]
458457
fn test_splice_inclusive_range() {
459458
let mut v = String::from("12345");
460-
let t: String = v.splice(2...3, "789").collect();
459+
v.splice(2...3, "789");
461460
assert_eq!(v, "127895");
462-
assert_eq!(t, "34");
463-
let t2: String = v.splice(1...2, "A").collect();
461+
v.splice(1...2, "A");
464462
assert_eq!(v, "1A895");
465-
assert_eq!(t2, "27");
466463
}
467464

468465
#[test]
@@ -482,24 +479,15 @@ fn test_splice_inclusive_out_of_bounds() {
482479
#[test]
483480
fn test_splice_empty() {
484481
let mut s = String::from("12345");
485-
let t: String = s.splice(1..2, "").collect();
482+
s.splice(1..2, "");
486483
assert_eq!(s, "1345");
487-
assert_eq!(t, "2");
488484
}
489485

490486
#[test]
491487
fn test_splice_unbounded() {
492488
let mut s = String::from("12345");
493-
let t: String = s.splice(.., "").collect();
489+
s.splice(.., "");
494490
assert_eq!(s, "");
495-
assert_eq!(t, "12345");
496-
}
497-
498-
#[test]
499-
fn test_splice_forget() {
500-
let mut s = String::from("12345");
501-
::std::mem::forget(s.splice(2..4, "789"));
502-
assert_eq!(s, "12345");
503491
}
504492

505493
#[test]

0 commit comments

Comments
 (0)