Skip to content

Commit 7520894

Browse files
committed
Auto merge of #70474 - Dylan-DPC:rollup-0lsxmmk, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #65222 (Proposal: `fold_self` and `try_fold_self` for Iterators) - #69887 (clean up E0404 explanation) - #70068 (use "gcc" instead of "cc" on *-sun-solaris systems when linking) - #70470 (Clean up E0463 explanation) Failed merges: r? @ghost
2 parents 0a2df62 + 3de5a89 commit 7520894

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

src/libcore/iter/traits/iterator.rs

+39-16
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,43 @@ pub trait Iterator {
20052005
self.try_fold(init, ok(f)).unwrap()
20062006
}
20072007

2008+
/// The same as [`fold()`](#method.fold), but uses the first element in the
2009+
/// iterator as the initial value, folding every subsequent element into it.
2010+
/// If the iterator is empty, return `None`; otherwise, return the result
2011+
/// of the fold.
2012+
///
2013+
/// # Example
2014+
///
2015+
/// Find the maximum value:
2016+
///
2017+
/// ```
2018+
/// #![feature(iterator_fold_self)]
2019+
///
2020+
/// fn find_max<I>(iter: I) -> Option<I::Item>
2021+
/// where I: Iterator,
2022+
/// I::Item: Ord,
2023+
/// {
2024+
/// iter.fold_first(|a, b| {
2025+
/// if a >= b { a } else { b }
2026+
/// })
2027+
/// }
2028+
/// let a = [10, 20, 5, -23, 0];
2029+
/// let b: [u32; 0] = [];
2030+
///
2031+
/// assert_eq!(find_max(a.iter()), Some(&20));
2032+
/// assert_eq!(find_max(b.iter()), None);
2033+
/// ```
2034+
#[inline]
2035+
#[unstable(feature = "iterator_fold_self", issue = "68125")]
2036+
fn fold_first<F>(mut self, f: F) -> Option<Self::Item>
2037+
where
2038+
Self: Sized,
2039+
F: FnMut(Self::Item, Self::Item) -> Self::Item,
2040+
{
2041+
let first = self.next()?;
2042+
Some(self.fold(first, f))
2043+
}
2044+
20082045
/// Tests if every element of the iterator matches a predicate.
20092046
///
20102047
/// `all()` takes a closure that returns `true` or `false`. It applies
@@ -2497,7 +2534,7 @@ pub trait Iterator {
24972534
move |x, y| cmp::max_by(x, y, &mut compare)
24982535
}
24992536

2500-
fold1(self, fold(compare))
2537+
self.fold_first(fold(compare))
25012538
}
25022539

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

2564-
fold1(self, fold(compare))
2601+
self.fold_first(fold(compare))
25652602
}
25662603

25672604
/// Reverses an iterator's direction.
@@ -3214,20 +3251,6 @@ pub trait Iterator {
32143251
}
32153252
}
32163253

3217-
/// Fold an iterator without having to provide an initial value.
3218-
#[inline]
3219-
fn fold1<I, F>(mut it: I, f: F) -> Option<I::Item>
3220-
where
3221-
I: Iterator,
3222-
F: FnMut(I::Item, I::Item) -> I::Item,
3223-
{
3224-
// start with the first element as our selection. This avoids
3225-
// having to use `Option`s inside the loop, translating to a
3226-
// sizeable performance gain (6x in one case).
3227-
let first = it.next()?;
3228-
Some(it.fold(first, f))
3229-
}
3230-
32313254
#[stable(feature = "rust1", since = "1.0.0")]
32323255
impl<I: Iterator + ?Sized> Iterator for &mut I {
32333256
type Item = I::Item;

src/librustc_codegen_ssa/back/link.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,19 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
838838
"emcc"
839839
}
840840
}
841-
LinkerFlavor::Gcc => "cc",
841+
LinkerFlavor::Gcc => {
842+
if cfg!(target_os = "solaris") {
843+
// On historical Solaris systems, "cc" may have
844+
// been Sun Studio, which is not flag-compatible
845+
// with "gcc". This history casts a long shadow,
846+
// and many modern illumos distributions today
847+
// ship GCC as "gcc" without also making it
848+
// available as "cc".
849+
"gcc"
850+
} else {
851+
"cc"
852+
}
853+
}
842854
LinkerFlavor::Ld => "ld",
843855
LinkerFlavor::Msvc => "link.exe",
844856
LinkerFlavor::Lld(_) => "lld",

src/librustc_error_codes/error_codes/E0404.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
You tried to use something which is not a trait in a trait position, such as
2-
a bound or `impl`.
1+
A type that is not a trait was used in a trait position, such as a bound
2+
or `impl`.
33

44
Erroneous code example:
55

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

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

2424
```
2525
trait Foo {
@@ -32,7 +32,7 @@ impl Foo for Bar { // ok!
3232
}
3333
```
3434

35-
or
35+
or:
3636

3737
```
3838
trait Foo {

src/librustc_error_codes/error_codes/E0463.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
A plugin/crate was declared but cannot be found. Erroneous code example:
1+
A plugin/crate was declared but cannot be found.
2+
3+
Erroneous code example:
24

35
```compile_fail,E0463
46
#![feature(plugin)]

0 commit comments

Comments
 (0)