Skip to content

Commit 1670a53

Browse files
committed
Auto merge of #48203 - kennytm:rollup, r=kennytm
Rollup of 23 pull requests - Successful merges: #47784, #47806, #47846, #48005, #48033, #48065, #48087, #48114, #48126, #48130, #48133, #48151, #48154, #48156, #48162, #48163, #48165, #48167, #48181, #48186, #48195, #48035, #48210 - Failed merges:
2 parents c83fa5d + 03b089d commit 1670a53

File tree

50 files changed

+805
-211
lines changed

Some content is hidden

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

50 files changed

+805
-211
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ matrix:
5656
NO_LLVM_ASSERTIONS=1
5757
NO_DEBUG_ASSERTIONS=1
5858
os: osx
59-
osx_image: xcode8.3
59+
osx_image: xcode9.2
6060
if: branch = auto
6161
6262
- env: >
@@ -70,7 +70,7 @@ matrix:
7070
NO_LLVM_ASSERTIONS=1
7171
NO_DEBUG_ASSERTIONS=1
7272
os: osx
73-
osx_image: xcode8.3
73+
osx_image: xcode9.2
7474
if: branch = auto
7575
7676
# OSX builders producing releases. These do not run the full test suite and

RELEASES.md

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Compatibility Notes
7878
- [`column!()` macro is one-based instead of zero-based][46977]
7979
- [`fmt::Arguments` can no longer be shared across threads][45198]
8080
- [Access to `#[repr(packed)]` struct fields is now unsafe][44884]
81+
- [Cargo sets a different working directory for the compiler][cargo/4788]
8182

8283
[44884]: https://github.com/rust-lang/rust/pull/44884
8384
[45198]: https://github.com/rust-lang/rust/pull/45198
@@ -106,6 +107,7 @@ Compatibility Notes
106107
[47080]: https://github.com/rust-lang/rust/pull/47080
107108
[47084]: https://github.com/rust-lang/rust/pull/47084
108109
[cargo/4743]: https://github.com/rust-lang/cargo/pull/4743
110+
[cargo/4788]: https://github.com/rust-lang/cargo/pull/4788
109111
[cargo/4817]: https://github.com/rust-lang/cargo/pull/4817
110112
[`RefCell::replace`]: https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.replace
111113
[`RefCell::swap`]: https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.swap

src/bootstrap/native.rs

+8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ impl Step for Llvm {
157157
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
158158
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
159159

160+
// By default, LLVM will automatically find OCaml and, if it finds it,
161+
// install the LLVM bindings in LLVM_OCAML_INSTALL_PATH, which defaults
162+
// to /usr/bin/ocaml.
163+
// This causes problem for non-root builds of Rust. Side-step the issue
164+
// by setting LLVM_OCAML_INSTALL_PATH to a relative path, so it installs
165+
// in the prefix.
166+
cfg.define("LLVM_OCAML_INSTALL_PATH",
167+
env::var_os("LLVM_OCAML_INSTALL_PATH").unwrap_or_else(|| "usr/lib/ocaml".into()));
160168

161169
// This setting makes the LLVM tools link to the dynamic LLVM library,
162170
// which saves both memory during parallel links and overall disk space

src/liballoc/vec.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -805,22 +805,7 @@ impl<T> Vec<T> {
805805
pub fn retain<F>(&mut self, mut f: F)
806806
where F: FnMut(&T) -> bool
807807
{
808-
let len = self.len();
809-
let mut del = 0;
810-
{
811-
let v = &mut **self;
812-
813-
for i in 0..len {
814-
if !f(&v[i]) {
815-
del += 1;
816-
} else if del > 0 {
817-
v.swap(i - del, i);
818-
}
819-
}
820-
}
821-
if del > 0 {
822-
self.truncate(len - del);
823-
}
808+
self.drain_filter(|x| !f(x));
824809
}
825810

826811
/// Removes all but the first of consecutive elements in the vector that resolve to the same

src/libcore/iter/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ pub use self::range::Step;
333333

334334
#[stable(feature = "rust1", since = "1.0.0")]
335335
pub use self::sources::{Repeat, repeat};
336+
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
337+
pub use self::sources::{RepeatWith, repeat_with};
336338
#[stable(feature = "iter_empty", since = "1.2.0")]
337339
pub use self::sources::{Empty, empty};
338340
#[stable(feature = "iter_once", since = "1.2.0")]

src/libcore/iter/sources.rs

+115
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ unsafe impl<A: Clone> TrustedLen for Repeat<A> {}
5757
///
5858
/// [`take`]: trait.Iterator.html#method.take
5959
///
60+
/// If the element type of the iterator you need does not implement `Clone`,
61+
/// or if you do not want to keep the repeated element in memory, you can
62+
/// instead use the [`repeat_with`] function.
63+
///
64+
/// [`repeat_with`]: fn.repeat_with.html
65+
///
6066
/// # Examples
6167
///
6268
/// Basic usage:
@@ -99,6 +105,115 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
99105
Repeat{element: elt}
100106
}
101107

108+
/// An iterator that repeats elements of type `A` endlessly by
109+
/// applying the provided closure `F: FnMut() -> A`.
110+
///
111+
/// This `struct` is created by the [`repeat_with`] function.
112+
/// See its documentation for more.
113+
///
114+
/// [`repeat_with`]: fn.repeat_with.html
115+
#[derive(Copy, Clone, Debug)]
116+
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
117+
pub struct RepeatWith<F> {
118+
repeater: F
119+
}
120+
121+
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
122+
impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
123+
type Item = A;
124+
125+
#[inline]
126+
fn next(&mut self) -> Option<A> { Some((self.repeater)()) }
127+
128+
#[inline]
129+
fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
130+
}
131+
132+
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
133+
impl<A, F: FnMut() -> A> DoubleEndedIterator for RepeatWith<F> {
134+
#[inline]
135+
fn next_back(&mut self) -> Option<A> { self.next() }
136+
}
137+
138+
#[unstable(feature = "fused", issue = "35602")]
139+
impl<A, F: FnMut() -> A> FusedIterator for RepeatWith<F> {}
140+
141+
#[unstable(feature = "trusted_len", issue = "37572")]
142+
unsafe impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F> {}
143+
144+
/// Creates a new iterator that repeats elements of type `A` endlessly by
145+
/// applying the provided closure, the repeater, `F: FnMut() -> A`.
146+
///
147+
/// The `repeat_with()` function calls the repeater over and over and over and
148+
/// over and over and 🔁.
149+
///
150+
/// Infinite iterators like `repeat_with()` are often used with adapters like
151+
/// [`take`], in order to make them finite.
152+
///
153+
/// [`take`]: trait.Iterator.html#method.take
154+
///
155+
/// If the element type of the iterator you need implements `Clone`, and
156+
/// it is OK to keep the source element in memory, you should instead use
157+
/// the [`repeat`] function.
158+
///
159+
/// [`repeat`]: fn.repeat.html
160+
///
161+
/// An iterator produced by `repeat_with()` is a `DoubleEndedIterator`.
162+
/// It is important to not that reversing `repeat_with(f)` will produce
163+
/// the exact same sequence as the non-reversed iterator. In other words,
164+
/// `repeat_with(f).rev().collect::<Vec<_>>()` is equivalent to
165+
/// `repeat_with(f).collect::<Vec<_>>()`.
166+
///
167+
/// # Examples
168+
///
169+
/// Basic usage:
170+
///
171+
/// ```
172+
/// #![feature(iterator_repeat_with)]
173+
///
174+
/// use std::iter;
175+
///
176+
/// // let's assume we have some value of a type that is not `Clone`
177+
/// // or which don't want to have in memory just yet because it is expensive:
178+
/// #[derive(PartialEq, Debug)]
179+
/// struct Expensive;
180+
///
181+
/// // a particular value forever:
182+
/// let mut things = iter::repeat_with(|| Expensive);
183+
///
184+
/// assert_eq!(Some(Expensive), things.next());
185+
/// assert_eq!(Some(Expensive), things.next());
186+
/// assert_eq!(Some(Expensive), things.next());
187+
/// assert_eq!(Some(Expensive), things.next());
188+
/// assert_eq!(Some(Expensive), things.next());
189+
/// ```
190+
///
191+
/// Using mutation and going finite:
192+
///
193+
/// ```rust
194+
/// #![feature(iterator_repeat_with)]
195+
///
196+
/// use std::iter;
197+
///
198+
/// // From the zeroth to the third power of two:
199+
/// let mut curr = 1;
200+
/// let mut pow2 = iter::repeat_with(|| { let tmp = curr; curr *= 2; tmp })
201+
/// .take(4);
202+
///
203+
/// assert_eq!(Some(1), pow2.next());
204+
/// assert_eq!(Some(2), pow2.next());
205+
/// assert_eq!(Some(4), pow2.next());
206+
/// assert_eq!(Some(8), pow2.next());
207+
///
208+
/// // ... and now we're done
209+
/// assert_eq!(None, pow2.next());
210+
/// ```
211+
#[inline]
212+
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
213+
pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
214+
RepeatWith { repeater }
215+
}
216+
102217
/// An iterator that yields nothing.
103218
///
104219
/// This `struct` is created by the [`empty`] function. See its documentation for more.

src/libcore/iter/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ pub trait ExactSizeIterator: Iterator {
706706
/// ```
707707
/// #![feature(exact_size_is_empty)]
708708
///
709-
/// let mut one_element = 0..1;
709+
/// let mut one_element = std::iter::once(0);
710710
/// assert!(!one_element.is_empty());
711711
///
712712
/// assert_eq!(one_element.next(), Some(0));

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#![feature(unwind_attributes)]
9393
#![feature(doc_spotlight)]
9494
#![feature(rustc_const_unstable)]
95+
#![feature(iterator_repeat_with)]
9596

9697
#[prelude_import]
9798
#[allow(unused)]

src/libcore/marker.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ impl<T: ?Sized> !Send for *mut T { }
6363
/// struct BarUse(Bar<[i32]>); // OK
6464
/// ```
6565
///
66-
/// The one exception is the implicit `Self` type of a trait, which does not
67-
/// get an implicit `Sized` bound. This is because a `Sized` bound prevents
68-
/// the trait from being used to form a [trait object]:
66+
/// The one exception is the implicit `Self` type of a trait. A trait does not
67+
/// have an implicit `Sized` bound as this is incompatible with [trait object]s
68+
/// where, by definition, the trait needs to work with all possible implementors,
69+
/// and thus could be any size.
70+
///
71+
/// Although Rust will let you bind `Sized` to a trait, you won't
72+
/// be able to use it to form a trait object later:
6973
///
7074
/// ```
7175
/// # #![allow(unused_variables)]

src/libcore/num/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ pub enum FpCategory {
28812881
issue = "32110")]
28822882
pub trait Float: Sized {
28832883
/// Type used by `to_bits` and `from_bits`.
2884-
#[stable(feature = "core_float_bits", since = "1.24.0")]
2884+
#[stable(feature = "core_float_bits", since = "1.25.0")]
28852885
type Bits;
28862886

28872887
/// Returns `true` if this value is NaN and false otherwise.
@@ -2947,10 +2947,10 @@ pub trait Float: Sized {
29472947
fn min(self, other: Self) -> Self;
29482948

29492949
/// Raw transmutation to integer.
2950-
#[stable(feature = "core_float_bits", since="1.24.0")]
2950+
#[stable(feature = "core_float_bits", since="1.25.0")]
29512951
fn to_bits(self) -> Self::Bits;
29522952
/// Raw transmutation from integer.
2953-
#[stable(feature = "core_float_bits", since="1.24.0")]
2953+
#[stable(feature = "core_float_bits", since="1.25.0")]
29542954
fn from_bits(v: Self::Bits) -> Self;
29552955
}
29562956

0 commit comments

Comments
 (0)