Skip to content
Merged
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
52 changes: 26 additions & 26 deletions library/alloc/src/boxed/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,103 +93,103 @@ impl<S: ?Sized + AsyncIterator + Unpin> AsyncIterator for Box<S> {
}
}

/// This implementation is required to make sure that the `Box<[I]>: IntoIterator`
/// This implementation is required to make sure that the `Box<[T]>: IntoIterator`
/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
impl<I, A: Allocator> !Iterator for Box<[I], A> {}
impl<T, A: Allocator> !Iterator for Box<[T], A> {}

/// This implementation is required to make sure that the `&Box<[I]>: IntoIterator`
/// This implementation is required to make sure that the `&Box<[T]>: IntoIterator`
/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
impl<'a, I, A: Allocator> !Iterator for &'a Box<[I], A> {}
impl<'a, T, A: Allocator> !Iterator for &'a Box<[T], A> {}

/// This implementation is required to make sure that the `&mut Box<[I]>: IntoIterator`
/// This implementation is required to make sure that the `&mut Box<[T]>: IntoIterator`
/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
impl<'a, I, A: Allocator> !Iterator for &'a mut Box<[I], A> {}
impl<'a, T, A: Allocator> !Iterator for &'a mut Box<[T], A> {}

// Note: the `#[rustc_skip_during_method_dispatch(boxed_slice)]` on `trait IntoIterator`
// hides this implementation from explicit `.into_iter()` calls on editions < 2024,
// so those calls will still resolve to the slice implementation, by reference.
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
impl<I, A: Allocator> IntoIterator for Box<[I], A> {
type IntoIter = vec::IntoIter<I, A>;
type Item = I;
fn into_iter(self) -> vec::IntoIter<I, A> {
impl<T, A: Allocator> IntoIterator for Box<[T], A> {
type IntoIter = vec::IntoIter<T, A>;
type Item = T;
fn into_iter(self) -> vec::IntoIter<T, A> {
self.into_vec().into_iter()
}
}

#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
type IntoIter = slice::Iter<'a, I>;
type Item = &'a I;
fn into_iter(self) -> slice::Iter<'a, I> {
impl<'a, T, A: Allocator> IntoIterator for &'a Box<[T], A> {
type IntoIter = slice::Iter<'a, T>;
type Item = &'a T;
fn into_iter(self) -> slice::Iter<'a, T> {
self.iter()
}
}

#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
type IntoIter = slice::IterMut<'a, I>;
type Item = &'a mut I;
fn into_iter(self) -> slice::IterMut<'a, I> {
impl<'a, T, A: Allocator> IntoIterator for &'a mut Box<[T], A> {
type IntoIter = slice::IterMut<'a, T>;
type Item = &'a mut T;
fn into_iter(self) -> slice::IterMut<'a, T> {
self.iter_mut()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_slice_from_iter", since = "1.32.0")]
impl<I> FromIterator<I> for Box<[I]> {
fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self {
impl<T> FromIterator<T> for Box<[T]> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
iter.into_iter().collect::<Vec<_>>().into_boxed_slice()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
impl FromIterator<char> for Box<str> {
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> Self {
String::from_iter(iter).into_boxed_str()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
impl<'a> FromIterator<&'a char> for Box<str> {
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = &'a char>>(iter: I) -> Self {
String::from_iter(iter).into_boxed_str()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
impl<'a> FromIterator<&'a str> for Box<str> {
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> Self {
String::from_iter(iter).into_boxed_str()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
impl FromIterator<String> for Box<str> {
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> Self {
String::from_iter(iter).into_boxed_str()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
impl<A: Allocator> FromIterator<Box<str, A>> for Box<str> {
fn from_iter<T: IntoIterator<Item = Box<str, A>>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = Box<str, A>>>(iter: I) -> Self {
String::from_iter(iter).into_boxed_str()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
impl<'a> FromIterator<Cow<'a, str>> for Box<str> {
fn from_iter<T: IntoIterator<Item = Cow<'a, str>>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> Self {
String::from_iter(iter).into_boxed_str()
}
}
Expand Down
12 changes: 6 additions & 6 deletions library/alloc/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,31 +281,31 @@ impl<'a> From<&'a ByteString> for Cow<'a, ByteStr> {
#[unstable(feature = "bstr", issue = "134915")]
impl FromIterator<char> for ByteString {
#[inline]
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> Self {
ByteString(iter.into_iter().collect::<String>().into_bytes())
}
}

#[unstable(feature = "bstr", issue = "134915")]
impl FromIterator<u8> for ByteString {
#[inline]
fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = u8>>(iter: I) -> Self {
ByteString(iter.into_iter().collect())
}
}

#[unstable(feature = "bstr", issue = "134915")]
impl<'a> FromIterator<&'a str> for ByteString {
#[inline]
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> Self {
ByteString(iter.into_iter().collect::<String>().into_bytes())
}
}

#[unstable(feature = "bstr", issue = "134915")]
impl<'a> FromIterator<&'a [u8]> for ByteString {
#[inline]
fn from_iter<T: IntoIterator<Item = &'a [u8]>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = &'a [u8]>>(iter: I) -> Self {
let mut buf = Vec::new();
for b in iter {
buf.extend_from_slice(b);
Expand All @@ -317,7 +317,7 @@ impl<'a> FromIterator<&'a [u8]> for ByteString {
#[unstable(feature = "bstr", issue = "134915")]
impl<'a> FromIterator<&'a ByteStr> for ByteString {
#[inline]
fn from_iter<T: IntoIterator<Item = &'a ByteStr>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = &'a ByteStr>>(iter: I) -> Self {
let mut buf = Vec::new();
for b in iter {
buf.extend_from_slice(&b.0);
Expand All @@ -329,7 +329,7 @@ impl<'a> FromIterator<&'a ByteStr> for ByteString {
#[unstable(feature = "bstr", issue = "134915")]
impl FromIterator<ByteString> for ByteString {
#[inline]
fn from_iter<T: IntoIterator<Item = ByteString>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = ByteString>>(iter: I) -> Self {
let mut buf = Vec::new();
for mut b in iter {
buf.append(&mut b.0);
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
///
/// If the iterator produces any pairs with equal keys,
/// all but one of the corresponding values will be dropped.
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> BTreeMap<K, V> {
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> BTreeMap<K, V> {
let mut inputs: Vec<_> = iter.into_iter().collect();

if inputs.is_empty() {
Expand All @@ -2557,7 +2557,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V, A: Allocator + Clone> Extend<(K, V)> for BTreeMap<K, V, A> {
#[inline]
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
iter.into_iter().for_each(move |(k, v)| {
self.insert(k, v);
});
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2480,7 +2480,7 @@ impl<'a> FromIterator<Cow<'a, str>> for String {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl FromIterator<core::ascii::Char> for String {
fn from_iter<T: IntoIterator<Item = core::ascii::Char>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = core::ascii::Char>>(iter: I) -> Self {
let buf = iter.into_iter().map(core::ascii::Char::to_u8).collect();
// SAFETY: `buf` is guaranteed to be valid UTF-8 because the `core::ascii::Char` type
// only contains ASCII values (0x00-0x7F), which are valid UTF-8.
Expand All @@ -2491,7 +2491,7 @@ impl FromIterator<core::ascii::Char> for String {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl<'a> FromIterator<&'a core::ascii::Char> for String {
fn from_iter<T: IntoIterator<Item = &'a core::ascii::Char>>(iter: T) -> Self {
fn from_iter<I: IntoIterator<Item = &'a core::ascii::Char>>(iter: I) -> Self {
let buf = iter.into_iter().copied().map(core::ascii::Char::to_u8).collect();
// SAFETY: `buf` is guaranteed to be valid UTF-8 because the `core::ascii::Char` type
// only contains ASCII values (0x00-0x7F), which are valid UTF-8.
Expand Down Expand Up @@ -3332,7 +3332,7 @@ impl<'a> FromIterator<String> for Cow<'a, str> {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl<'a> FromIterator<core::ascii::Char> for Cow<'a, str> {
fn from_iter<T: IntoIterator<Item = core::ascii::Char>>(it: T) -> Self {
fn from_iter<I: IntoIterator<Item = core::ascii::Char>>(it: I) -> Self {
Cow::Owned(FromIterator::from_iter(it))
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/wtf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl Wtf8Buf {
/// This replaces surrogate code point pairs with supplementary code points,
/// like concatenating ill-formed UTF-16 strings effectively would.
impl FromIterator<CodePoint> for Wtf8Buf {
fn from_iter<T: IntoIterator<Item = CodePoint>>(iter: T) -> Wtf8Buf {
fn from_iter<I: IntoIterator<Item = CodePoint>>(iter: I) -> Wtf8Buf {
let mut string = Wtf8Buf::new();
string.extend(iter);
string
Expand All @@ -435,7 +435,7 @@ impl FromIterator<CodePoint> for Wtf8Buf {
/// This replaces surrogate code point pairs with supplementary code points,
/// like concatenating ill-formed UTF-16 strings effectively would.
impl Extend<CodePoint> for Wtf8Buf {
fn extend<T: IntoIterator<Item = CodePoint>>(&mut self, iter: T) {
fn extend<I: IntoIterator<Item = CodePoint>>(&mut self, iter: I) {
let iterator = iter.into_iter();
let (low, _high) = iterator.size_hint();
// Lower bound of one byte per code point (ASCII only)
Expand Down
46 changes: 23 additions & 23 deletions library/core/src/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,41 +97,41 @@ use super::TrustedLen;
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented(
on(
Self = "&[{A}]",
Self = "&[{T}]",
message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
label = "try explicitly collecting into a `Vec<{A}>`",
label = "try explicitly collecting into a `Vec<{T}>`",
),
on(
all(A = "{integer}", any(Self = "&[{integral}]",)),
all(T = "{integer}", any(Self = "&[{integral}]",)),
message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
label = "try explicitly collecting into a `Vec<{A}>`",
label = "try explicitly collecting into a `Vec<{T}>`",
),
on(
Self = "[{A}]",
Self = "[{T}]",
message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size",
label = "try explicitly collecting into a `Vec<{A}>`",
label = "try explicitly collecting into a `Vec<{T}>`",
),
on(
all(A = "{integer}", any(Self = "[{integral}]",)),
all(T = "{integer}", any(Self = "[{integral}]",)),
message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size",
label = "try explicitly collecting into a `Vec<{A}>`",
label = "try explicitly collecting into a `Vec<{T}>`",
),
on(
Self = "[{A}; _]",
Self = "[{T}; _]",
message = "an array of type `{Self}` cannot be built directly from an iterator",
label = "try collecting into a `Vec<{A}>`, then using `.try_into()`",
label = "try collecting into a `Vec<{T}>`, then using `.try_into()`",
),
on(
all(A = "{integer}", any(Self = "[{integral}; _]",)),
all(T = "{integer}", any(Self = "[{integral}; _]",)),
message = "an array of type `{Self}` cannot be built directly from an iterator",
label = "try collecting into a `Vec<{A}>`, then using `.try_into()`",
label = "try collecting into a `Vec<{T}>`, then using `.try_into()`",
),
message = "a value of type `{Self}` cannot be built from an iterator \
over elements of type `{A}`",
label = "value of type `{Self}` cannot be built from `std::iter::Iterator<Item={A}>`"
over elements of type `{T}`",
label = "value of type `{Self}` cannot be built from `std::iter::Iterator<Item={T}>`"
)]
#[rustc_diagnostic_item = "FromIterator"]
pub trait FromIterator<A>: Sized {
pub trait FromIterator<T>: Sized {
/// Creates a value from an iterator.
///
/// See the [module-level documentation] for more.
Expand All @@ -149,7 +149,7 @@ pub trait FromIterator<A>: Sized {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "from_iter_fn"]
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self;
}

/// Conversion into an [`Iterator`].
Expand Down Expand Up @@ -371,7 +371,7 @@ const impl<I: [const] Iterator> IntoIterator for I {
/// // This is a bit simpler with the concrete type signature: we can call
/// // extend on anything which can be turned into an Iterator which gives
/// // us i32s. Because we need i32s to put into MyCollection.
/// fn extend<T: IntoIterator<Item=i32>>(&mut self, iter: T) {
/// fn extend<I: IntoIterator<Item=i32>>(&mut self, iter: I) {
///
/// // The implementation is very straightforward: loop through the
/// // iterator, and add() each element to ourselves.
Expand All @@ -394,7 +394,7 @@ const impl<I: [const] Iterator> IntoIterator for I {
/// assert_eq!("MyCollection([5, 6, 7, 1, 2, 3])", format!("{c:?}"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Extend<A> {
pub trait Extend<T> {
/// Extends a collection with the contents of an iterator.
///
/// As this is the only required method for this trait, the [trait-level] docs
Expand All @@ -413,11 +413,11 @@ pub trait Extend<A> {
/// assert_eq!("abcdef", &message);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I);

/// Extends a collection with exactly one element.
#[unstable(feature = "extend_one", issue = "72631")]
fn extend_one(&mut self, item: A) {
fn extend_one(&mut self, item: T) {
self.extend(Some(item));
}

Expand All @@ -442,7 +442,7 @@ pub trait Extend<A> {
// This method is for internal usage only. It is only on the trait because of specialization's limitations.
#[unstable(feature = "extend_one_unchecked", issue = "none")]
#[doc(hidden)]
unsafe fn extend_one_unchecked(&mut self, item: A)
unsafe fn extend_one_unchecked(&mut self, item: T)
where
Self: Sized,
{
Expand All @@ -452,7 +452,7 @@ pub trait Extend<A> {

#[stable(feature = "extend_for_unit", since = "1.28.0")]
impl Extend<()> for () {
fn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T) {
fn extend<I: IntoIterator<Item = ()>>(&mut self, iter: I) {
iter.into_iter().for_each(drop)
}
fn extend_one(&mut self, _item: ()) {}
Expand Down Expand Up @@ -620,7 +620,7 @@ macro_rules! impl_extend_tuple {
where
$($extend_ty: Extend<$ty>,)+
{
fn extend<T: IntoIterator<Item = ($($ty,)+)>>(&mut self, iter: T) {
fn extend<Iter: IntoIterator<Item = ($($ty,)+)>>(&mut self, iter: Iter) {
default_extend(self, iter)
}

Expand Down
6 changes: 3 additions & 3 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
//! [`Option`] of a collection of each contained value of the original
//! [`Option`] values, or [`None`] if any of the elements was [`None`].
//!
//! [impl-FromIterator]: Option#impl-FromIterator%3COption%3CA%3E%3E-for-Option%3CV%3E
//! [impl-FromIterator]: Option#impl-FromIterator%3COption%3CT%3E%3E-for-Option%3CV%3E
//!
//! ```
//! let v = [Some(2), Some(4), None, Some(8)];
Expand Down Expand Up @@ -2786,7 +2786,7 @@ unsafe impl<A: TrustedLen> TrustedLen for OptionFlatten<A> {}
/////////////////////////////////////////////////////////////////////////////

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
impl<T, V: FromIterator<T>> FromIterator<Option<T>> for Option<V> {
/// Takes each element in the [`Iterator`]: if it is [`None`][Option::None],
/// no further elements are taken, and the [`None`][Option::None] is
/// returned. Should no [`None`][Option::None] occur, a container of type
Expand Down Expand Up @@ -2848,7 +2848,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// Since the third element caused an underflow, no further elements were taken,
/// so the final value of `shared` is 6 (= `3 + 2 + 1`), not 16.
#[inline]
fn from_iter<I: IntoIterator<Item = Option<A>>>(iter: I) -> Option<V> {
fn from_iter<I: IntoIterator<Item = Option<T>>>(iter: I) -> Option<V> {
iter::try_process(iter.into_iter(), |i| i.collect())
}
}
Expand Down
Loading
Loading