Skip to content

Commit e741187

Browse files
committed
Auto merge of rust-lang#140650 - tgross35:rollup-0mp4h1s, r=tgross35
Rollup of 4 pull requests Successful merges: - rust-lang#135734 (Correct `extract_if` sample equivalent.) - rust-lang#140307 (Refactor rustc_on_unimplemented's filter parser) - rust-lang#140644 (Revert "Avoid unused clones in Cloned<I> and Copied<I>") - rust-lang#140648 (Update `compiler-builtins` to 0.1.157) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a8840b1 + ec85f11 commit e741187

File tree

6 files changed

+36
-173
lines changed

6 files changed

+36
-173
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
compiler_builtins = { version = "=0.1.156", features = ['rustc-dep-of-std'] }
19+
compiler_builtins = { version = "=0.1.157", features = ['rustc-dep-of-std'] }
2020

2121
[features]
2222
compiler-builtins-mem = ['compiler_builtins/mem']

alloc/src/vec/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,21 +3666,27 @@ impl<T, A: Allocator> Vec<T, A> {
36663666
/// Using this method is equivalent to the following code:
36673667
///
36683668
/// ```
3669-
/// # use std::cmp::min;
3670-
/// # let some_predicate = |x: &mut i32| { *x == 2 || *x == 3 || *x == 6 };
3671-
/// # let mut vec = vec![1, 2, 3, 4, 5, 6];
3672-
/// # let range = 1..4;
3669+
/// # let some_predicate = |x: &mut i32| { *x % 2 == 1 };
3670+
/// # let mut vec = vec![0, 1, 2, 3, 4, 5, 6];
3671+
/// # let mut vec2 = vec.clone();
3672+
/// # let range = 1..5;
36733673
/// let mut i = range.start;
3674-
/// while i < min(vec.len(), range.end) {
3674+
/// let end_items = vec.len() - range.end;
3675+
/// # let mut extracted = vec![];
3676+
///
3677+
/// while i < vec.len() - end_items {
36753678
/// if some_predicate(&mut vec[i]) {
36763679
/// let val = vec.remove(i);
3680+
/// # extracted.push(val);
36773681
/// // your code here
36783682
/// } else {
36793683
/// i += 1;
36803684
/// }
36813685
/// }
36823686
///
3683-
/// # assert_eq!(vec, vec![1, 4, 5]);
3687+
/// # let extracted2: Vec<_> = vec2.extract_if(range, some_predicate).collect();
3688+
/// # assert_eq!(vec, vec2);
3689+
/// # assert_eq!(extracted, extracted2);
36843690
/// ```
36853691
///
36863692
/// But `extract_if` is easier to use. `extract_if` is also more efficient,

core/src/iter/adapters/cloned.rs

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::num::NonZero;
22

3-
use crate::cmp::Ordering;
43
use crate::iter::adapters::zip::try_get_unchecked;
54
use crate::iter::adapters::{SourceIter, TrustedRandomAccess, TrustedRandomAccessNoCoerce};
65
use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen, UncheckedIterator};
@@ -42,31 +41,13 @@ where
4241
self.it.next().cloned()
4342
}
4443

45-
#[inline]
4644
fn size_hint(&self) -> (usize, Option<usize>) {
4745
self.it.size_hint()
4846
}
4947

50-
#[inline]
51-
fn count(self) -> usize {
52-
self.it.count()
53-
}
54-
55-
fn last(self) -> Option<T> {
56-
self.it.last().cloned()
57-
}
58-
59-
#[inline]
60-
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
61-
self.it.advance_by(n)
62-
}
63-
64-
fn nth(&mut self, n: usize) -> Option<T> {
65-
self.it.nth(n).cloned()
66-
}
67-
6848
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
6949
where
50+
Self: Sized,
7051
F: FnMut(B, Self::Item) -> R,
7152
R: Try<Output = B>,
7253
{
@@ -80,58 +61,6 @@ where
8061
self.it.map(T::clone).fold(init, f)
8162
}
8263

83-
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item>
84-
where
85-
P: FnMut(&Self::Item) -> bool,
86-
{
87-
self.it.find(move |x| predicate(&x)).cloned()
88-
}
89-
90-
fn max_by<F>(self, mut compare: F) -> Option<Self::Item>
91-
where
92-
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
93-
{
94-
self.it.max_by(move |&x, &y| compare(x, y)).cloned()
95-
}
96-
97-
fn min_by<F>(self, mut compare: F) -> Option<Self::Item>
98-
where
99-
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
100-
{
101-
self.it.min_by(move |&x, &y| compare(x, y)).cloned()
102-
}
103-
104-
fn cmp<O>(self, other: O) -> Ordering
105-
where
106-
O: IntoIterator<Item = Self::Item>,
107-
Self::Item: Ord,
108-
{
109-
self.it.cmp_by(other, |x, y| x.cmp(&y))
110-
}
111-
112-
fn partial_cmp<O>(self, other: O) -> Option<Ordering>
113-
where
114-
O: IntoIterator,
115-
Self::Item: PartialOrd<O::Item>,
116-
{
117-
self.it.partial_cmp_by(other, |x, y| x.partial_cmp(&y))
118-
}
119-
120-
fn eq<O>(self, other: O) -> bool
121-
where
122-
O: IntoIterator,
123-
Self::Item: PartialEq<O::Item>,
124-
{
125-
self.it.eq_by(other, |x, y| x == &y)
126-
}
127-
128-
fn is_sorted_by<F>(self, mut compare: F) -> bool
129-
where
130-
F: FnMut(&Self::Item, &Self::Item) -> bool,
131-
{
132-
self.it.is_sorted_by(move |&x, &y| compare(x, y))
133-
}
134-
13564
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
13665
where
13766
Self: TrustedRandomAccessNoCoerce,
@@ -152,13 +81,9 @@ where
15281
self.it.next_back().cloned()
15382
}
15483

155-
#[inline]
156-
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
157-
self.it.advance_back_by(n)
158-
}
159-
16084
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
16185
where
86+
Self: Sized,
16287
F: FnMut(B, Self::Item) -> R,
16388
R: Try<Output = B>,
16489
{
@@ -171,13 +96,6 @@ where
17196
{
17297
self.it.map(T::clone).rfold(init, f)
17398
}
174-
175-
fn rfind<P>(&mut self, mut predicate: P) -> Option<Self::Item>
176-
where
177-
P: FnMut(&Self::Item) -> bool,
178-
{
179-
self.it.rfind(move |x| predicate(&x)).cloned()
180-
}
18199
}
182100

183101
#[stable(feature = "iter_cloned", since = "1.1.0")]
@@ -186,12 +104,10 @@ where
186104
I: ExactSizeIterator<Item = &'a T>,
187105
T: Clone,
188106
{
189-
#[inline]
190107
fn len(&self) -> usize {
191108
self.it.len()
192109
}
193110

194-
#[inline]
195111
fn is_empty(&self) -> bool {
196112
self.it.is_empty()
197113
}

core/src/iter/adapters/copied.rs

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::cmp::Ordering;
21
use crate::iter::adapters::zip::try_get_unchecked;
32
use crate::iter::adapters::{SourceIter, TrustedRandomAccess, TrustedRandomAccessNoCoerce};
43
use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen};
@@ -49,35 +48,20 @@ where
4948

5049
fn next_chunk<const N: usize>(
5150
&mut self,
52-
) -> Result<[Self::Item; N], array::IntoIter<Self::Item, N>> {
51+
) -> Result<[Self::Item; N], array::IntoIter<Self::Item, N>>
52+
where
53+
Self: Sized,
54+
{
5355
<I as SpecNextChunk<'_, N, T>>::spec_next_chunk(&mut self.it)
5456
}
5557

56-
#[inline]
5758
fn size_hint(&self) -> (usize, Option<usize>) {
5859
self.it.size_hint()
5960
}
6061

61-
#[inline]
62-
fn count(self) -> usize {
63-
self.it.count()
64-
}
65-
66-
fn last(self) -> Option<T> {
67-
self.it.last().copied()
68-
}
69-
70-
#[inline]
71-
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
72-
self.it.advance_by(n)
73-
}
74-
75-
fn nth(&mut self, n: usize) -> Option<T> {
76-
self.it.nth(n).copied()
77-
}
78-
7962
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
8063
where
64+
Self: Sized,
8165
F: FnMut(B, Self::Item) -> R,
8266
R: Try<Output = B>,
8367
{
@@ -91,56 +75,21 @@ where
9175
self.it.fold(init, copy_fold(f))
9276
}
9377

94-
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item>
95-
where
96-
P: FnMut(&Self::Item) -> bool,
97-
{
98-
self.it.find(move |x| predicate(&x)).copied()
99-
}
100-
101-
fn max_by<F>(self, mut compare: F) -> Option<Self::Item>
102-
where
103-
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
104-
{
105-
self.it.max_by(move |&x, &y| compare(x, y)).copied()
106-
}
107-
108-
fn min_by<F>(self, mut compare: F) -> Option<Self::Item>
109-
where
110-
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
111-
{
112-
self.it.min_by(move |&x, &y| compare(x, y)).copied()
113-
}
114-
115-
fn cmp<O>(self, other: O) -> Ordering
116-
where
117-
O: IntoIterator<Item = Self::Item>,
118-
Self::Item: Ord,
119-
{
120-
self.it.cmp_by(other, |x, y| x.cmp(&y))
78+
fn nth(&mut self, n: usize) -> Option<T> {
79+
self.it.nth(n).copied()
12180
}
12281

123-
fn partial_cmp<O>(self, other: O) -> Option<Ordering>
124-
where
125-
O: IntoIterator,
126-
Self::Item: PartialOrd<O::Item>,
127-
{
128-
self.it.partial_cmp_by(other, |x, y| x.partial_cmp(&y))
82+
fn last(self) -> Option<T> {
83+
self.it.last().copied()
12984
}
13085

131-
fn eq<O>(self, other: O) -> bool
132-
where
133-
O: IntoIterator,
134-
Self::Item: PartialEq<O::Item>,
135-
{
136-
self.it.eq_by(other, |x, y| x == &y)
86+
fn count(self) -> usize {
87+
self.it.count()
13788
}
13889

139-
fn is_sorted_by<F>(self, mut compare: F) -> bool
140-
where
141-
F: FnMut(&Self::Item, &Self::Item) -> bool,
142-
{
143-
self.it.is_sorted_by(move |&x, &y| compare(x, y))
90+
#[inline]
91+
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
92+
self.it.advance_by(n)
14493
}
14594

14695
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
@@ -163,13 +112,9 @@ where
163112
self.it.next_back().copied()
164113
}
165114

166-
#[inline]
167-
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
168-
self.it.advance_back_by(n)
169-
}
170-
171115
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
172116
where
117+
Self: Sized,
173118
F: FnMut(B, Self::Item) -> R,
174119
R: Try<Output = B>,
175120
{
@@ -183,11 +128,9 @@ where
183128
self.it.rfold(init, copy_fold(f))
184129
}
185130

186-
fn rfind<P>(&mut self, mut predicate: P) -> Option<Self::Item>
187-
where
188-
P: FnMut(&Self::Item) -> bool,
189-
{
190-
self.it.rfind(move |x| predicate(&x)).copied()
131+
#[inline]
132+
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
133+
self.it.advance_back_by(n)
191134
}
192135
}
193136

@@ -197,12 +140,10 @@ where
197140
I: ExactSizeIterator<Item = &'a T>,
198141
T: Copy,
199142
{
200-
#[inline]
201143
fn len(&self) -> usize {
202144
self.it.len()
203145
}
204146

205-
#[inline]
206147
fn is_empty(&self) -> bool {
207148
self.it.is_empty()
208149
}

std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1818
panic_unwind = { path = "../panic_unwind", optional = true }
1919
panic_abort = { path = "../panic_abort" }
2020
core = { path = "../core", public = true }
21-
compiler_builtins = { version = "=0.1.156" }
21+
compiler_builtins = { version = "=0.1.157" }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.15", default-features = false, features = [
2424
'rustc-dep-of-std',

0 commit comments

Comments
 (0)