Skip to content

Commit d3fb063

Browse files
committed
Auto merge of #48203 - kennytm:rollup, r=kennytm
Rollup of 22 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 - Failed merges:
2 parents 3ec5a99 + ce89c3d commit d3fb063

File tree

49 files changed

+798
-208
lines changed

Some content is hidden

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

49 files changed

+798
-208
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
@@ -159,6 +159,14 @@ impl Step for Llvm {
159159
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
160160
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
161161

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

163171
// This setting makes the LLVM tools link to the dynamic LLVM library,
164172
// 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/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

src/libcore/ops/range.rs

+81-9
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ impl fmt::Debug for RangeFull {
6060
/// (`start..end`).
6161
///
6262
/// The `Range` `start..end` contains all values with `x >= start` and
63-
/// `x < end`.
63+
/// `x < end`. It is empty unless `start < end`.
6464
///
6565
/// # Examples
6666
///
6767
/// ```
6868
/// assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
6969
/// assert_eq!(3 + 4 + 5, (3..6).sum());
7070
///
71-
/// let arr = [0, 1, 2, 3];
72-
/// assert_eq!(arr[ .. ], [0,1,2,3]);
73-
/// assert_eq!(arr[ ..3], [0,1,2 ]);
74-
/// assert_eq!(arr[1.. ], [ 1,2,3]);
75-
/// assert_eq!(arr[1..3], [ 1,2 ]); // Range
71+
/// let arr = ['a', 'b', 'c', 'd'];
72+
/// assert_eq!(arr[ .. ], ['a', 'b', 'c', 'd']);
73+
/// assert_eq!(arr[ ..3], ['a', 'b', 'c', ]);
74+
/// assert_eq!(arr[1.. ], [ 'b', 'c', 'd']);
75+
/// assert_eq!(arr[1..3], [ 'b', 'c' ]); // Range
7676
/// ```
7777
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
7878
#[stable(feature = "rust1", since = "1.0.0")]
@@ -92,7 +92,6 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
9292
}
9393
}
9494

95-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
9695
impl<Idx: PartialOrd<Idx>> Range<Idx> {
9796
/// Returns `true` if `item` is contained in the range.
9897
///
@@ -109,9 +108,37 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
109108
/// assert!(!(3..3).contains(3));
110109
/// assert!(!(3..2).contains(3));
111110
/// ```
111+
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
112112
pub fn contains(&self, item: Idx) -> bool {
113113
(self.start <= item) && (item < self.end)
114114
}
115+
116+
/// Returns `true` if the range contains no items.
117+
///
118+
/// # Examples
119+
///
120+
/// ```
121+
/// #![feature(range_is_empty)]
122+
///
123+
/// assert!(!(3..5).is_empty());
124+
/// assert!( (3..3).is_empty());
125+
/// assert!( (3..2).is_empty());
126+
/// ```
127+
///
128+
/// The range is empty if either side is incomparable:
129+
///
130+
/// ```
131+
/// #![feature(range_is_empty,inclusive_range_syntax)]
132+
///
133+
/// use std::f32::NAN;
134+
/// assert!(!(3.0..5.0).is_empty());
135+
/// assert!( (3.0..NAN).is_empty());
136+
/// assert!( (NAN..5.0).is_empty());
137+
/// ```
138+
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
139+
pub fn is_empty(&self) -> bool {
140+
!(self.start < self.end)
141+
}
115142
}
116143

117144
/// A range only bounded inclusively below (`start..`).
@@ -244,7 +271,14 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
244271
/// An range bounded inclusively below and above (`start..=end`).
245272
///
246273
/// The `RangeInclusive` `start..=end` contains all values with `x >= start`
247-
/// and `x <= end`.
274+
/// and `x <= end`. It is empty unless `start <= end`.
275+
///
276+
/// This iterator is [fused], but the specific values of `start` and `end` after
277+
/// iteration has finished are **unspecified** other than that [`.is_empty()`]
278+
/// will return `true` once no more values will be produced.
279+
///
280+
/// [fused]: ../iter/trait.FusedIterator.html
281+
/// [`.is_empty()`]: #method.is_empty
248282
///
249283
/// # Examples
250284
///
@@ -280,7 +314,6 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
280314
}
281315
}
282316

283-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
284317
impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
285318
/// Returns `true` if `item` is contained in the range.
286319
///
@@ -298,9 +331,48 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
298331
/// assert!( (3..=3).contains(3));
299332
/// assert!(!(3..=2).contains(3));
300333
/// ```
334+
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
301335
pub fn contains(&self, item: Idx) -> bool {
302336
self.start <= item && item <= self.end
303337
}
338+
339+
/// Returns `true` if the range contains no items.
340+
///
341+
/// # Examples
342+
///
343+
/// ```
344+
/// #![feature(range_is_empty,inclusive_range_syntax)]
345+
///
346+
/// assert!(!(3..=5).is_empty());
347+
/// assert!(!(3..=3).is_empty());
348+
/// assert!( (3..=2).is_empty());
349+
/// ```
350+
///
351+
/// The range is empty if either side is incomparable:
352+
///
353+
/// ```
354+
/// #![feature(range_is_empty,inclusive_range_syntax)]
355+
///
356+
/// use std::f32::NAN;
357+
/// assert!(!(3.0..=5.0).is_empty());
358+
/// assert!( (3.0..=NAN).is_empty());
359+
/// assert!( (NAN..=5.0).is_empty());
360+
/// ```
361+
///
362+
/// This method returns `true` after iteration has finished:
363+
///
364+
/// ```
365+
/// #![feature(range_is_empty,inclusive_range_syntax)]
366+
///
367+
/// let mut r = 3..=5;
368+
/// for _ in r.by_ref() {}
369+
/// // Precise field values are unspecified here
370+
/// assert!(r.is_empty());
371+
/// ```
372+
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
373+
pub fn is_empty(&self) -> bool {
374+
!(self.start <= self.end)
375+
}
304376
}
305377

306378
/// A range only bounded inclusively above (`..=end`).

0 commit comments

Comments
 (0)