Skip to content

Update subtree/library to 2025-05-06 #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: subtree/library
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 6 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bench = false

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

[features]
compiler-builtins-mem = ['compiler_builtins/mem']
Expand Down
22 changes: 14 additions & 8 deletions alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3659,28 +3659,34 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating
/// or the iteration short-circuits, then the remaining elements will be retained.
/// Use [`retain`] with a negated predicate if you do not need the returned iterator.
/// Use [`retain_mut`] with a negated predicate if you do not need the returned iterator.
///
/// [`retain`]: Vec::retain
/// [`retain_mut`]: Vec::retain_mut
///
/// Using this method is equivalent to the following code:
///
/// ```
/// # use std::cmp::min;
/// # let some_predicate = |x: &mut i32| { *x == 2 || *x == 3 || *x == 6 };
/// # let mut vec = vec![1, 2, 3, 4, 5, 6];
/// # let range = 1..4;
/// # let some_predicate = |x: &mut i32| { *x % 2 == 1 };
/// # let mut vec = vec![0, 1, 2, 3, 4, 5, 6];
/// # let mut vec2 = vec.clone();
/// # let range = 1..5;
/// let mut i = range.start;
/// while i < min(vec.len(), range.end) {
/// let end_items = vec.len() - range.end;
/// # let mut extracted = vec![];
///
/// while i < vec.len() - end_items {
/// if some_predicate(&mut vec[i]) {
/// let val = vec.remove(i);
/// # extracted.push(val);
/// // your code here
/// } else {
/// i += 1;
/// }
/// }
///
/// # assert_eq!(vec, vec![1, 4, 5]);
/// # let extracted2: Vec<_> = vec2.extract_if(range, some_predicate).collect();
/// # assert_eq!(vec, vec2);
/// # assert_eq!(extracted, extracted2);
/// ```
///
/// But `extract_if` is easier to use. `extract_if` is also more efficient,
Expand Down
1 change: 0 additions & 1 deletion core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,6 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
#[inline]
#[rustc_intrinsic]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_allow_const_fn_unstable(const_swap_nonoverlapping)] // this is anyway not called since CTFE implements the intrinsic
pub const unsafe fn typed_swap_nonoverlapping<T>(x: *mut T, y: *mut T) {
// SAFETY: The caller provided single non-overlapping items behind
// pointers, so swapping them with `count: 1` is fine.
Expand Down
88 changes: 2 additions & 86 deletions core/src/iter/adapters/cloned.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::num::NonZero;

use crate::cmp::Ordering;
use crate::iter::adapters::zip::try_get_unchecked;
use crate::iter::adapters::{SourceIter, TrustedRandomAccess, TrustedRandomAccessNoCoerce};
use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen, UncheckedIterator};
Expand Down Expand Up @@ -42,31 +41,13 @@ where
self.it.next().cloned()
}

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

#[inline]
fn count(self) -> usize {
self.it.count()
}

fn last(self) -> Option<T> {
self.it.last().cloned()
}

#[inline]
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
self.it.advance_by(n)
}

fn nth(&mut self, n: usize) -> Option<T> {
self.it.nth(n).cloned()
}

fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
{
Expand All @@ -80,58 +61,6 @@ where
self.it.map(T::clone).fold(init, f)
}

fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
self.it.find(move |x| predicate(&x)).cloned()
}

fn max_by<F>(self, mut compare: F) -> Option<Self::Item>
where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
{
self.it.max_by(move |&x, &y| compare(x, y)).cloned()
}

fn min_by<F>(self, mut compare: F) -> Option<Self::Item>
where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
{
self.it.min_by(move |&x, &y| compare(x, y)).cloned()
}

fn cmp<O>(self, other: O) -> Ordering
where
O: IntoIterator<Item = Self::Item>,
Self::Item: Ord,
{
self.it.cmp_by(other, |x, y| x.cmp(&y))
}

fn partial_cmp<O>(self, other: O) -> Option<Ordering>
where
O: IntoIterator,
Self::Item: PartialOrd<O::Item>,
{
self.it.partial_cmp_by(other, |x, y| x.partial_cmp(&y))
}

fn eq<O>(self, other: O) -> bool
where
O: IntoIterator,
Self::Item: PartialEq<O::Item>,
{
self.it.eq_by(other, |x, y| x == &y)
}

fn is_sorted_by<F>(self, mut compare: F) -> bool
where
F: FnMut(&Self::Item, &Self::Item) -> bool,
{
self.it.is_sorted_by(move |&x, &y| compare(x, y))
}

unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
where
Self: TrustedRandomAccessNoCoerce,
Expand All @@ -152,13 +81,9 @@ where
self.it.next_back().cloned()
}

#[inline]
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
self.it.advance_back_by(n)
}

fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
{
Expand All @@ -171,13 +96,6 @@ where
{
self.it.map(T::clone).rfold(init, f)
}

fn rfind<P>(&mut self, mut predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
self.it.rfind(move |x| predicate(&x)).cloned()
}
}

#[stable(feature = "iter_cloned", since = "1.1.0")]
Expand All @@ -186,12 +104,10 @@ where
I: ExactSizeIterator<Item = &'a T>,
T: Clone,
{
#[inline]
fn len(&self) -> usize {
self.it.len()
}

#[inline]
fn is_empty(&self) -> bool {
self.it.is_empty()
}
Expand Down
Loading