From 2b42625e5b77c306e63f12c185b3105a78d5e294 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Sat, 19 Feb 2022 14:05:11 -0500 Subject: [PATCH 1/2] `impl Extend for ()` --- library/core/src/iter/traits/collect.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 637d7bc44885e..6eabf08cd4bed 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -374,11 +374,11 @@ pub trait Extend { } #[stable(feature = "extend_for_unit", since = "1.28.0")] -impl Extend<()> for () { - fn extend>(&mut self, iter: T) { +impl Extend for () { + fn extend>(&mut self, iter: A) { iter.into_iter().for_each(drop) } - fn extend_one(&mut self, _item: ()) {} + fn extend_one(&mut self, _item: T) {} } #[stable(feature = "extend_for_tuple", since = "1.56.0")] From d1e444da4efb50deed02cc907454ea5e817266be Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Sat, 19 Feb 2022 14:11:58 -0500 Subject: [PATCH 2/2] `impl FromIterator for ()` --- library/core/src/unit.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/library/core/src/unit.rs b/library/core/src/unit.rs index f41f4a5e94a76..aec06e0ddd364 100644 --- a/library/core/src/unit.rs +++ b/library/core/src/unit.rs @@ -1,9 +1,10 @@ use crate::iter::FromIterator; -/// Collapses all unit items from an iterator into one. +/// Drains all items from an iterator. /// -/// This is more useful when combined with higher-level abstractions, like -/// collecting to a `Result<(), E>` where you only care about errors: +/// This is useful to run an iterator to completion when you don't +/// care about the result, or to collect into a `Result<(), E>` when +/// you only care about errors: /// /// ``` /// use std::io::*; @@ -14,8 +15,8 @@ use crate::iter::FromIterator; /// assert!(res.is_ok()); /// ``` #[stable(feature = "unit_from_iter", since = "1.23.0")] -impl FromIterator<()> for () { - fn from_iter>(iter: I) -> Self { - iter.into_iter().for_each(|()| {}) +impl FromIterator for () { + fn from_iter>(iter: A) -> Self { + iter.into_iter().for_each(|_| {}) } }