Skip to content

Commit 4465f22

Browse files
committed
Auto merge of rust-lang#40889 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests - Successful merges: rust-lang#40682, rust-lang#40731, rust-lang#40783, rust-lang#40838, rust-lang#40864 - Failed merges:
2 parents 10b1739 + 1214b16 commit 4465f22

File tree

13 files changed

+544
-148
lines changed

13 files changed

+544
-148
lines changed

src/doc/nomicon

src/doc/reference

src/libcollections/str.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,28 @@
1010

1111
//! Unicode string slices.
1212
//!
13+
//! The `&str` type is one of the two main string types, the other being `String`.
14+
//! Unlike its `String` counterpart, its contents are borrowed.
15+
//!
16+
//! # Basic Usage
17+
//!
18+
//! A basic string declaration of `&str` type:
19+
//!
20+
//! ```
21+
//! let hello_world = "Hello, World!";
22+
//! ```
23+
//!
24+
//! Here we have declared a string literal, also known as a string slice.
25+
//! String literals have a static lifetime, which means the string `hello_world`
26+
//! is guaranteed to be valid for the duration of the entire program.
27+
//! We can explicitly specify `hello_world`'s lifetime as well:
28+
//!
29+
//! ```
30+
//! let hello_world: &'static str = "Hello, world!";
31+
//! ```
32+
//!
1333
//! *[See also the `str` primitive type](../../std/primitive.str.html).*
1434
15-
1635
#![stable(feature = "rust1", since = "1.0.0")]
1736

1837
// Many of the usings in this module are only used in the test configuration.

src/libcollections/vec.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ impl<T> ops::DerefMut for Vec<T> {
15631563
impl<T> FromIterator<T> for Vec<T> {
15641564
#[inline]
15651565
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T> {
1566-
<Self as SpecExtend<_, _>>::from_iter(iter.into_iter())
1566+
<Self as SpecExtend<T, I::IntoIter>>::from_iter(iter.into_iter())
15671567
}
15681568
}
15691569

@@ -1631,7 +1631,7 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
16311631
impl<T> Extend<T> for Vec<T> {
16321632
#[inline]
16331633
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
1634-
self.spec_extend(iter.into_iter())
1634+
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
16351635
}
16361636
}
16371637

@@ -1662,7 +1662,7 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
16621662
vector
16631663
}
16641664
};
1665-
vector.spec_extend(iterator);
1665+
<Vec<T> as SpecExtend<T, I>>::spec_extend(&mut vector, iterator);
16661666
vector
16671667
}
16681668

@@ -1674,7 +1674,7 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
16741674
impl<T, I> SpecExtend<T, I> for Vec<T>
16751675
where I: TrustedLen<Item=T>,
16761676
{
1677-
fn from_iter(iterator: I) -> Self {
1677+
default fn from_iter(iterator: I) -> Self {
16781678
let mut vector = Vec::new();
16791679
vector.spec_extend(iterator);
16801680
vector
@@ -1706,6 +1706,27 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
17061706
}
17071707
}
17081708

1709+
impl<T> SpecExtend<T, IntoIter<T>> for Vec<T> {
1710+
fn from_iter(iterator: IntoIter<T>) -> Self {
1711+
// A common case is passing a vector into a function which immediately
1712+
// re-collects into a vector. We can short circuit this if the IntoIter
1713+
// has not been advanced at all.
1714+
if *iterator.buf == iterator.ptr as *mut T {
1715+
unsafe {
1716+
let vec = Vec::from_raw_parts(*iterator.buf as *mut T,
1717+
iterator.len(),
1718+
iterator.cap);
1719+
mem::forget(iterator);
1720+
vec
1721+
}
1722+
} else {
1723+
let mut vector = Vec::new();
1724+
vector.spec_extend(iterator);
1725+
vector
1726+
}
1727+
}
1728+
}
1729+
17091730
impl<'a, T: 'a, I> SpecExtend<&'a T, I> for Vec<T>
17101731
where I: Iterator<Item=&'a T>,
17111732
T: Clone,

src/libcollectionstest/vec.rs

+16
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,19 @@ fn test_placement_panic() {
680680
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| { vec.place_back() <- mkpanic(); }));
681681
assert_eq!(vec.len(), 3);
682682
}
683+
684+
#[test]
685+
fn from_into_inner() {
686+
let vec = vec![1, 2, 3];
687+
let ptr = vec.as_ptr();
688+
let vec = vec.into_iter().collect::<Vec<_>>();
689+
assert_eq!(vec, [1, 2, 3]);
690+
assert_eq!(vec.as_ptr(), ptr);
691+
692+
let ptr = &vec[1] as *const _;
693+
let mut it = vec.into_iter();
694+
it.next().unwrap();
695+
let vec = it.collect::<Vec<_>>();
696+
assert_eq!(vec, [2, 3]);
697+
assert!(ptr != vec.as_ptr());
698+
}

src/libstd/io/cursor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pub struct Cursor<T> {
8989
impl<T> Cursor<T> {
9090
/// Creates a new cursor wrapping the provided underlying I/O object.
9191
///
92+
/// Cursor initial position is `0` even if underlying object (e.
93+
/// g. `Vec`) is not empty. So writing to cursor starts with
94+
/// overwriting `Vec` content, not with appending to it.
95+
///
9296
/// # Examples
9397
///
9498
/// ```

0 commit comments

Comments
 (0)