Skip to content

Commit

Permalink
Auto merge of rust-lang#70474 - Dylan-DPC:rollup-0lsxmmk, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - rust-lang#65222 (Proposal: `fold_self` and `try_fold_self` for Iterators)
 - rust-lang#69887 (clean up E0404 explanation)
 - rust-lang#70068 (use "gcc" instead of "cc" on *-sun-solaris systems when linking)
 - rust-lang#70470 (Clean up E0463 explanation)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 27, 2020
2 parents 0a2df62 + 3de5a89 commit 7520894
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
55 changes: 39 additions & 16 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,43 @@ pub trait Iterator {
self.try_fold(init, ok(f)).unwrap()
}

/// The same as [`fold()`](#method.fold), but uses the first element in the
/// iterator as the initial value, folding every subsequent element into it.
/// If the iterator is empty, return `None`; otherwise, return the result
/// of the fold.
///
/// # Example
///
/// Find the maximum value:
///
/// ```
/// #![feature(iterator_fold_self)]
///
/// fn find_max<I>(iter: I) -> Option<I::Item>
/// where I: Iterator,
/// I::Item: Ord,
/// {
/// iter.fold_first(|a, b| {
/// if a >= b { a } else { b }
/// })
/// }
/// let a = [10, 20, 5, -23, 0];
/// let b: [u32; 0] = [];
///
/// assert_eq!(find_max(a.iter()), Some(&20));
/// assert_eq!(find_max(b.iter()), None);
/// ```
#[inline]
#[unstable(feature = "iterator_fold_self", issue = "68125")]
fn fold_first<F>(mut self, f: F) -> Option<Self::Item>
where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
{
let first = self.next()?;
Some(self.fold(first, f))
}

/// Tests if every element of the iterator matches a predicate.
///
/// `all()` takes a closure that returns `true` or `false`. It applies
Expand Down Expand Up @@ -2497,7 +2534,7 @@ pub trait Iterator {
move |x, y| cmp::max_by(x, y, &mut compare)
}

fold1(self, fold(compare))
self.fold_first(fold(compare))
}

/// Returns the element that gives the minimum value from the
Expand Down Expand Up @@ -2561,7 +2598,7 @@ pub trait Iterator {
move |x, y| cmp::min_by(x, y, &mut compare)
}

fold1(self, fold(compare))
self.fold_first(fold(compare))
}

/// Reverses an iterator's direction.
Expand Down Expand Up @@ -3214,20 +3251,6 @@ pub trait Iterator {
}
}

/// Fold an iterator without having to provide an initial value.
#[inline]
fn fold1<I, F>(mut it: I, f: F) -> Option<I::Item>
where
I: Iterator,
F: FnMut(I::Item, I::Item) -> I::Item,
{
// start with the first element as our selection. This avoids
// having to use `Option`s inside the loop, translating to a
// sizeable performance gain (6x in one case).
let first = it.next()?;
Some(it.fold(first, f))
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I: Iterator + ?Sized> Iterator for &mut I {
type Item = I::Item;
Expand Down
14 changes: 13 additions & 1 deletion src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,19 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
"emcc"
}
}
LinkerFlavor::Gcc => "cc",
LinkerFlavor::Gcc => {
if cfg!(target_os = "solaris") {
// On historical Solaris systems, "cc" may have
// been Sun Studio, which is not flag-compatible
// with "gcc". This history casts a long shadow,
// and many modern illumos distributions today
// ship GCC as "gcc" without also making it
// available as "cc".
"gcc"
} else {
"cc"
}
}
LinkerFlavor::Ld => "ld",
LinkerFlavor::Msvc => "link.exe",
LinkerFlavor::Lld(_) => "lld",
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_error_codes/error_codes/E0404.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
You tried to use something which is not a trait in a trait position, such as
a bound or `impl`.
A type that is not a trait was used in a trait position, such as a bound
or `impl`.

Erroneous code example:

Expand All @@ -18,8 +18,8 @@ struct Foo;
fn bar<T: Foo>(t: T) {} // error: `Foo` is not a trait
```

Please verify that you didn't misspell the trait's name or otherwise use the
wrong identifier. Example:
Please verify that the trait's name was not misspelled or that the right
identifier was used. Example:

```
trait Foo {
Expand All @@ -32,7 +32,7 @@ impl Foo for Bar { // ok!
}
```

or
or:

```
trait Foo {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0463.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
A plugin/crate was declared but cannot be found. Erroneous code example:
A plugin/crate was declared but cannot be found.

Erroneous code example:

```compile_fail,E0463
#![feature(plugin)]
Expand Down

0 comments on commit 7520894

Please sign in to comment.