Skip to content

Commit 94bf2c1

Browse files
committed
Auto merge of #57087 - Centril:rollup, r=Centril
Rollup of 14 pull requests Successful merges: - #56188 (enum type instead of variant suggestion unification ) - #56342 (Improve docs for collecting into `Option`s) - #56916 (Fix mutable references in `static mut`) - #56917 (Simplify MIR generation for logical operations) - #56939 (Pin stabilization) - #56953 (Mark tuple structs as live if their constructors are used) - #56964 (Remove `TokenStream::JointTree`.) - #56966 (Correct strings for raw pointer deref and array access suggestions) - #57020 (Point to cause of `fn` expected return type) - #57032 (fix deprecation warnings in liballoc benches) - #57053 (Fix alignment for array indexing) - #57062 (Fix a comment) - #57067 (Stabilize min_const_unsafe_fn in 1.33) - #57078 (Ignore two tests on s390x) Failed merges: r? @ghost
2 parents e169280 + dff3e41 commit 94bf2c1

File tree

79 files changed

+721
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+721
-489
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies = [
1818
"compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
1919
"core 0.0.0",
2020
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
21+
"rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
2122
]
2223

2324
[[package]]

src/liballoc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ compiler_builtins = { version = "0.1.0", features = ['rustc-dep-of-std'] }
1515

1616
[dev-dependencies]
1717
rand = "0.6"
18+
rand_xorshift = "0.1"
1819

1920
[[test]]
2021
name = "collectionstests"

src/liballoc/benches/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::iter::Iterator;
1313
use std::vec::Vec;
1414
use std::collections::BTreeMap;
15-
use rand::{Rng, thread_rng};
15+
use rand::{Rng, seq::SliceRandom, thread_rng};
1616
use test::{Bencher, black_box};
1717

1818
macro_rules! map_insert_rand_bench {
@@ -78,7 +78,7 @@ macro_rules! map_find_rand_bench {
7878
map.insert(k, k);
7979
}
8080

81-
rng.shuffle(&mut keys);
81+
keys.shuffle(&mut rng);
8282

8383
// measure
8484
let mut i = 0;

src/liballoc/benches/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(test)]
1414

1515
extern crate rand;
16+
extern crate rand_xorshift;
1617
extern crate test;
1718

1819
mod btree;

src/liballoc/benches/slice.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use rand::{thread_rng};
1212
use std::mem;
1313
use std::ptr;
1414

15-
use rand::{Rng, SeedableRng, XorShiftRng};
15+
use rand::{Rng, SeedableRng};
1616
use rand::distributions::{Standard, Alphanumeric};
17+
use rand_xorshift::XorShiftRng;
1718
use test::{Bencher, black_box};
1819

1920
#[bench]

src/liballoc/benches/str.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ make_test!(split_a_str, s, s.split("a").count());
274274
make_test!(trim_ascii_char, s, {
275275
s.trim_matches(|c: char| c.is_ascii())
276276
});
277-
make_test!(trim_left_ascii_char, s, {
278-
s.trim_left_matches(|c: char| c.is_ascii())
277+
make_test!(trim_start_ascii_char, s, {
278+
s.trim_start_matches(|c: char| c.is_ascii())
279279
});
280-
make_test!(trim_right_ascii_char, s, {
281-
s.trim_right_matches(|c: char| c.is_ascii())
280+
make_test!(trim_end_ascii_char, s, {
281+
s.trim_end_matches(|c: char| c.is_ascii())
282282
});
283283

284284
make_test!(find_underscore_char, s, s.find('_'));

src/liballoc/boxed.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ impl<T> Box<T> {
111111
box x
112112
}
113113

114-
#[unstable(feature = "pin", issue = "49150")]
114+
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
115+
/// `x` will be pinned in memory and unable to be moved.
116+
#[stable(feature = "pin", since = "1.33.0")]
115117
#[inline(always)]
116-
pub fn pinned(x: T) -> Pin<Box<T>> {
118+
pub fn pin(x: T) -> Pin<Box<T>> {
117119
(box x).into()
118120
}
119121
}
@@ -446,7 +448,7 @@ impl<T> From<T> for Box<T> {
446448
}
447449
}
448450

449-
#[unstable(feature = "pin", issue = "49150")]
451+
#[stable(feature = "pin", since = "1.33.0")]
450452
impl<T> From<Box<T>> for Pin<Box<T>> {
451453
fn from(boxed: Box<T>) -> Self {
452454
// It's not possible to move or replace the insides of a `Pin<Box<T>>`
@@ -813,7 +815,7 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
813815
* implementation of `Unpin` (where `T: Unpin`) would be valid/safe, and
814816
* could have a method to project a Pin<T> from it.
815817
*/
816-
#[unstable(feature = "pin", issue = "49150")]
818+
#[stable(feature = "pin", since = "1.33.0")]
817819
impl<T: ?Sized> Unpin for Box<T> { }
818820

819821
#[unstable(feature = "generator_trait", issue = "43122")]

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
#![feature(nll)]
103103
#![feature(optin_builtin_traits)]
104104
#![feature(pattern)]
105-
#![feature(pin)]
106105
#![feature(ptr_internals)]
107106
#![feature(ptr_offset_from)]
108107
#![feature(rustc_attrs)]

src/liballoc/rc.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ impl<T> Rc<T> {
325325
}
326326
}
327327

328-
#[unstable(feature = "pin", issue = "49150")]
329-
pub fn pinned(value: T) -> Pin<Rc<T>> {
328+
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
329+
/// `value` will be pinned in memory and unable to be moved.
330+
#[stable(feature = "pin", since = "1.33.0")]
331+
pub fn pin(value: T) -> Pin<Rc<T>> {
330332
unsafe { Pin::new_unchecked(Rc::new(value)) }
331333
}
332334

@@ -1934,5 +1936,5 @@ impl<T: ?Sized> AsRef<T> for Rc<T> {
19341936
}
19351937
}
19361938

1937-
#[unstable(feature = "pin", issue = "49150")]
1939+
#[stable(feature = "pin", since = "1.33.0")]
19381940
impl<T: ?Sized> Unpin for Rc<T> { }

src/liballoc/sync.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,10 @@ impl<T> Arc<T> {
303303
Arc { ptr: Box::into_raw_non_null(x), phantom: PhantomData }
304304
}
305305

306-
#[unstable(feature = "pin", issue = "49150")]
307-
pub fn pinned(data: T) -> Pin<Arc<T>> {
306+
/// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
307+
/// `data` will be pinned in memory and unable to be moved.
308+
#[stable(feature = "pin", since = "1.33.0")]
309+
pub fn pin(data: T) -> Pin<Arc<T>> {
308310
unsafe { Pin::new_unchecked(Arc::new(data)) }
309311
}
310312

@@ -2050,5 +2052,5 @@ impl<T: ?Sized> AsRef<T> for Arc<T> {
20502052
}
20512053
}
20522054

2053-
#[unstable(feature = "pin", issue = "49150")]
2055+
#[stable(feature = "pin", since = "1.33.0")]
20542056
impl<T: ?Sized> Unpin for Arc<T> { }

src/libcore/future/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
120120

121121
impl<P> Future for Pin<P>
122122
where
123-
P: ops::DerefMut,
123+
P: Unpin + ops::DerefMut,
124124
P::Target: Future,
125125
{
126126
type Output = <<P as ops::Deref>::Target as Future>::Output;

src/libcore/marker.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
621621
/// So this, for example, can only be done on types implementing `Unpin`:
622622
///
623623
/// ```rust
624-
/// #![feature(pin)]
625624
/// use std::mem::replace;
626625
/// use std::pin::Pin;
627626
///
@@ -637,23 +636,23 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
637636
/// [`replace`]: ../../std/mem/fn.replace.html
638637
/// [`Pin`]: ../pin/struct.Pin.html
639638
/// [`pin module`]: ../../std/pin/index.html
640-
#[unstable(feature = "pin", issue = "49150")]
639+
#[stable(feature = "pin", since = "1.33.0")]
641640
pub auto trait Unpin {}
642641

643642
/// A marker type which does not implement `Unpin`.
644643
///
645644
/// If a type contains a `PhantomPinned`, it will not implement `Unpin` by default.
646-
#[unstable(feature = "pin", issue = "49150")]
645+
#[stable(feature = "pin", since = "1.33.0")]
647646
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
648647
pub struct PhantomPinned;
649648

650-
#[unstable(feature = "pin", issue = "49150")]
649+
#[stable(feature = "pin", since = "1.33.0")]
651650
impl !Unpin for PhantomPinned {}
652651

653-
#[unstable(feature = "pin", issue = "49150")]
652+
#[stable(feature = "pin", since = "1.33.0")]
654653
impl<'a, T: ?Sized + 'a> Unpin for &'a T {}
655654

656-
#[unstable(feature = "pin", issue = "49150")]
655+
#[stable(feature = "pin", since = "1.33.0")]
657656
impl<'a, T: ?Sized + 'a> Unpin for &'a mut T {}
658657

659658
/// Implementations of `Copy` for primitive types.

src/libcore/option.rs

+34-12
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<T> Option<T> {
273273

274274
/// Converts from `Pin<&Option<T>>` to `Option<Pin<&T>>`
275275
#[inline]
276-
#[unstable(feature = "pin", issue = "49150")]
276+
#[stable(feature = "pin", since = "1.33.0")]
277277
pub fn as_pin_ref<'a>(self: Pin<&'a Option<T>>) -> Option<Pin<&'a T>> {
278278
unsafe {
279279
Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x))
@@ -282,10 +282,10 @@ impl<T> Option<T> {
282282

283283
/// Converts from `Pin<&mut Option<T>>` to `Option<Pin<&mut T>>`
284284
#[inline]
285-
#[unstable(feature = "pin", issue = "49150")]
285+
#[stable(feature = "pin", since = "1.33.0")]
286286
pub fn as_pin_mut<'a>(self: Pin<&'a mut Option<T>>) -> Option<Pin<&'a mut T>> {
287287
unsafe {
288-
Pin::get_mut_unchecked(self).as_mut().map(|x| Pin::new_unchecked(x))
288+
Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x))
289289
}
290290
}
291291

@@ -1253,20 +1253,42 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
12531253
/// returned. Should no [`None`][Option::None] occur, a container with the
12541254
/// values of each [`Option`] is returned.
12551255
///
1256-
/// Here is an example which increments every integer in a vector,
1257-
/// checking for overflow:
1256+
/// # Examples
1257+
///
1258+
/// Here is an example which increments every integer in a vector.
1259+
/// `We use the checked variant of `add` that returns `None` when the
1260+
/// calculation would result in an overflow.
12581261
///
12591262
/// ```
1260-
/// use std::u16;
1263+
/// let items = vec![0_u16, 1, 2];
1264+
///
1265+
/// let res: Option<Vec<u16>> = items
1266+
/// .iter()
1267+
/// .map(|x| x.checked_add(1))
1268+
/// .collect();
12611269
///
1262-
/// let v = vec![1, 2];
1263-
/// let res: Option<Vec<u16>> = v.iter().map(|&x: &u16|
1264-
/// if x == u16::MAX { None }
1265-
/// else { Some(x + 1) }
1266-
/// ).collect();
1267-
/// assert!(res == Some(vec![2, 3]));
1270+
/// assert_eq!(res, Some(vec![1, 2, 3]));
12681271
/// ```
12691272
///
1273+
/// As you can see, this will return the expected, valid items.
1274+
///
1275+
/// Here is another example that tries to subtract one from another list
1276+
/// of integers, this time checking for underflow:
1277+
///
1278+
/// ```
1279+
/// let items = vec![2_u16, 1, 0];
1280+
///
1281+
/// let res: Option<Vec<u16>> = items
1282+
/// .iter()
1283+
/// .map(|x| x.checked_sub(1))
1284+
/// .collect();
1285+
///
1286+
/// assert_eq!(res, None);
1287+
/// ```
1288+
///
1289+
/// Since the last element is zero, it would underflow. Thus, the resulting
1290+
/// value is `None`.
1291+
///
12701292
/// [`Iterator`]: ../iter/trait.Iterator.html
12711293
#[inline]
12721294
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {

0 commit comments

Comments
 (0)