Skip to content

Commit

Permalink
Auto merge of #57087 - Centril:rollup, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 24, 2018
2 parents e169280 + dff3e41 commit 94bf2c1
Show file tree
Hide file tree
Showing 79 changed files with 721 additions and 489 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies = [
"compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ compiler_builtins = { version = "0.1.0", features = ['rustc-dep-of-std'] }

[dev-dependencies]
rand = "0.6"
rand_xorshift = "0.1"

[[test]]
name = "collectionstests"
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/benches/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use std::iter::Iterator;
use std::vec::Vec;
use std::collections::BTreeMap;
use rand::{Rng, thread_rng};
use rand::{Rng, seq::SliceRandom, thread_rng};
use test::{Bencher, black_box};

macro_rules! map_insert_rand_bench {
Expand Down Expand Up @@ -78,7 +78,7 @@ macro_rules! map_find_rand_bench {
map.insert(k, k);
}

rng.shuffle(&mut keys);
keys.shuffle(&mut rng);

// measure
let mut i = 0;
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![feature(test)]

extern crate rand;
extern crate rand_xorshift;
extern crate test;

mod btree;
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/benches/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use rand::{thread_rng};
use std::mem;
use std::ptr;

use rand::{Rng, SeedableRng, XorShiftRng};
use rand::{Rng, SeedableRng};
use rand::distributions::{Standard, Alphanumeric};
use rand_xorshift::XorShiftRng;
use test::{Bencher, black_box};

#[bench]
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/benches/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ make_test!(split_a_str, s, s.split("a").count());
make_test!(trim_ascii_char, s, {
s.trim_matches(|c: char| c.is_ascii())
});
make_test!(trim_left_ascii_char, s, {
s.trim_left_matches(|c: char| c.is_ascii())
make_test!(trim_start_ascii_char, s, {
s.trim_start_matches(|c: char| c.is_ascii())
});
make_test!(trim_right_ascii_char, s, {
s.trim_right_matches(|c: char| c.is_ascii())
make_test!(trim_end_ascii_char, s, {
s.trim_end_matches(|c: char| c.is_ascii())
});

make_test!(find_underscore_char, s, s.find('_'));
Expand Down
10 changes: 6 additions & 4 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ impl<T> Box<T> {
box x
}

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

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

#[unstable(feature = "generator_trait", issue = "43122")]
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
#![feature(nll)]
#![feature(optin_builtin_traits)]
#![feature(pattern)]
#![feature(pin)]
#![feature(ptr_internals)]
#![feature(ptr_offset_from)]
#![feature(rustc_attrs)]
Expand Down
8 changes: 5 additions & 3 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ impl<T> Rc<T> {
}
}

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

Expand Down Expand Up @@ -1934,5 +1936,5 @@ impl<T: ?Sized> AsRef<T> for Rc<T> {
}
}

#[unstable(feature = "pin", issue = "49150")]
#[stable(feature = "pin", since = "1.33.0")]
impl<T: ?Sized> Unpin for Rc<T> { }
8 changes: 5 additions & 3 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,10 @@ impl<T> Arc<T> {
Arc { ptr: Box::into_raw_non_null(x), phantom: PhantomData }
}

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

Expand Down Expand Up @@ -2050,5 +2052,5 @@ impl<T: ?Sized> AsRef<T> for Arc<T> {
}
}

#[unstable(feature = "pin", issue = "49150")]
#[stable(feature = "pin", since = "1.33.0")]
impl<T: ?Sized> Unpin for Arc<T> { }
2 changes: 1 addition & 1 deletion src/libcore/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {

impl<P> Future for Pin<P>
where
P: ops::DerefMut,
P: Unpin + ops::DerefMut,
P::Target: Future,
{
type Output = <<P as ops::Deref>::Target as Future>::Output;
Expand Down
11 changes: 5 additions & 6 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
/// So this, for example, can only be done on types implementing `Unpin`:
///
/// ```rust
/// #![feature(pin)]
/// use std::mem::replace;
/// use std::pin::Pin;
///
Expand All @@ -637,23 +636,23 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
/// [`replace`]: ../../std/mem/fn.replace.html
/// [`Pin`]: ../pin/struct.Pin.html
/// [`pin module`]: ../../std/pin/index.html
#[unstable(feature = "pin", issue = "49150")]
#[stable(feature = "pin", since = "1.33.0")]
pub auto trait Unpin {}

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

#[unstable(feature = "pin", issue = "49150")]
#[stable(feature = "pin", since = "1.33.0")]
impl !Unpin for PhantomPinned {}

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

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

/// Implementations of `Copy` for primitive types.
Expand Down
46 changes: 34 additions & 12 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<T> Option<T> {

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

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

Expand Down Expand Up @@ -1253,20 +1253,42 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// returned. Should no [`None`][Option::None] occur, a container with the
/// values of each [`Option`] is returned.
///
/// Here is an example which increments every integer in a vector,
/// checking for overflow:
/// # Examples
///
/// Here is an example which increments every integer in a vector.
/// `We use the checked variant of `add` that returns `None` when the
/// calculation would result in an overflow.
///
/// ```
/// use std::u16;
/// let items = vec![0_u16, 1, 2];
///
/// let res: Option<Vec<u16>> = items
/// .iter()
/// .map(|x| x.checked_add(1))
/// .collect();
///
/// let v = vec![1, 2];
/// let res: Option<Vec<u16>> = v.iter().map(|&x: &u16|
/// if x == u16::MAX { None }
/// else { Some(x + 1) }
/// ).collect();
/// assert!(res == Some(vec![2, 3]));
/// assert_eq!(res, Some(vec![1, 2, 3]));
/// ```
///
/// As you can see, this will return the expected, valid items.
///
/// Here is another example that tries to subtract one from another list
/// of integers, this time checking for underflow:
///
/// ```
/// let items = vec![2_u16, 1, 0];
///
/// let res: Option<Vec<u16>> = items
/// .iter()
/// .map(|x| x.checked_sub(1))
/// .collect();
///
/// assert_eq!(res, None);
/// ```
///
/// Since the last element is zero, it would underflow. Thus, the resulting
/// value is `None`.
///
/// [`Iterator`]: ../iter/trait.Iterator.html
#[inline]
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
Expand Down

0 comments on commit 94bf2c1

Please sign in to comment.