Skip to content

Commit cd923ac

Browse files
authored
Rollup merge of #149597 - jdonszelmann:revert-iterator-exactly-one, r=wafflelapkin
Revert "implement and test `Iterator::{exactly_one, collect_array}`" This reverts #149270 I was quite excited it merged, and immediately realized with `@WaffleLapkin` that this is a breaking change on nightly! Despite still being marked as unstable, the name conflicts with the name on itertools as was discussed on the PR itself: #149270 (comment). I'll reopen the PR though, and mark it as blocked on #148605
2 parents d2403c6 + c340732 commit cd923ac

File tree

6 files changed

+10
-72
lines changed

6 files changed

+10
-72
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ impl MetadataLoader for DefaultMetadataLoader {
8686
format!("failed to parse aix dylib '{}': {}", path.display(), e)
8787
})?;
8888

89-
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
90-
match Itertools::exactly_one(archive.members()) {
89+
match archive.members().exactly_one() {
9190
Ok(lib) => {
9291
let lib = lib.map_err(|e| {
9392
format!("failed to parse aix dylib '{}': {}", path.display(), e)

library/core/src/iter/traits/iterator.rs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,62 +4034,6 @@ pub trait Iterator {
40344034
{
40354035
unreachable!("Always specialized");
40364036
}
4037-
4038-
/// Checks if the iterator contains *exactly* one element.
4039-
/// If so, returns this one element.
4040-
///
4041-
/// See also [`collect_array`](Iterator::collect_array) for lengths other than `1`.
4042-
///
4043-
/// # Examples
4044-
///
4045-
/// ```
4046-
/// #![feature(exact_length_collection)]
4047-
///
4048-
/// assert_eq!([1].into_iter().exactly_one(), Some(1));
4049-
/// assert_eq!([].into_iter().exactly_one(), None::<()>);
4050-
///
4051-
/// // There is exactly one even integer in the array:
4052-
/// assert_eq!([1, 2, 3].into_iter().filter(|x| x % 2 == 0).exactly_one(), Some(2));
4053-
/// // But there are two odds, which is too many:
4054-
/// assert_eq!([1, 2, 3].into_iter().filter(|x| x % 2 == 1).exactly_one(), None);
4055-
/// ```
4056-
#[inline]
4057-
#[unstable(feature = "exact_length_collection", issue = "149266")]
4058-
fn exactly_one(self) -> Option<Self::Item>
4059-
where
4060-
Self: Sized,
4061-
{
4062-
self.collect_array::<1>().map(|[i]| i)
4063-
}
4064-
4065-
/// Checks if an iterator has *exactly* `N` elements.
4066-
/// If so, returns those `N` elements in an array.
4067-
///
4068-
/// See also [`exactly_one`](Iterator::exactly_one) when expecting a single element.
4069-
///
4070-
/// # Examples
4071-
///
4072-
/// ```
4073-
/// #![feature(exact_length_collection)]
4074-
///
4075-
/// assert_eq!([1, 2, 3, 4].into_iter().collect_array(), Some([1, 2, 3, 4]));
4076-
/// assert_eq!([1, 2].into_iter().chain([3, 4]).collect_array(), Some([1, 2, 3, 4]));
4077-
///
4078-
/// // Iterator contains too few elements:
4079-
/// assert_eq!([1, 2].into_iter().collect_array::<4>(), None);
4080-
/// // Iterator contains too many elements:
4081-
/// assert_eq!([1, 2, 3, 4, 5].into_iter().collect_array::<4>(), None);
4082-
/// // Taking 4 makes it work again:
4083-
/// assert_eq!([1, 2, 3, 4, 5].into_iter().take(4).collect_array(), Some([1, 2, 3, 4]));
4084-
/// ```
4085-
#[inline]
4086-
#[unstable(feature = "exact_length_collection", issue = "149266")]
4087-
fn collect_array<const N: usize>(mut self) -> Option<[Self::Item; N]>
4088-
where
4089-
Self: Sized,
4090-
{
4091-
self.next_chunk().ok().filter(|_| self.next().is_none())
4092-
}
40934037
}
40944038

40954039
trait SpecIterEq<B: Iterator>: Iterator {

src/librustdoc/html/format.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,7 @@ pub(crate) fn print_impl(
11261126
}
11271127
if impl_.kind.is_fake_variadic()
11281128
&& let Some(generics) = ty.generics()
1129-
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
1130-
&& let Ok(inner_type) = Itertools::exactly_one(generics)
1129+
&& let Ok(inner_type) = generics.exactly_one()
11311130
{
11321131
let last = ty.last();
11331132
if f.alternate() {
@@ -1207,8 +1206,7 @@ impl clean::Impl {
12071206
}
12081207
} else if let clean::Type::Path { path } = type_
12091208
&& let Some(generics) = path.generics()
1210-
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
1211-
&& let Ok(ty) = Itertools::exactly_one(generics)
1209+
&& let Ok(ty) = generics.exactly_one()
12121210
&& self.kind.is_fake_variadic()
12131211
{
12141212
print_anchor(path.def_id(), path.last(), cx).fmt(f)?;

src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
9292
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir_attrs(v.hir_id)))
9393
.then_some((v.def_id, v.span))
9494
});
95-
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
96-
if let Ok((id, span)) = Itertools::exactly_one(iter)
95+
if let Ok((id, span)) = iter.exactly_one()
9796
&& !find_attr!(cx.tcx.hir_attrs(item.hir_id()), AttributeKind::NonExhaustive(..))
9897
{
9998
self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
@@ -105,8 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
105104
.iter()
106105
.filter(|field| !cx.effective_visibilities.is_exported(field.def_id));
107106
if fields.len() > 1
108-
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
109-
&& let Ok(field) = Itertools::exactly_one(private_fields)
107+
&& let Ok(field) = private_fields.exactly_one()
110108
&& let TyKind::Tup([]) = field.ty.kind
111109
{
112110
span_lint_and_then(

tests/ui/const-generics/type-dependent/issue-71805.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem::MaybeUninit;
44
trait CollectSlice<'a>: Iterator {
55
fn inner_array<const N: usize>(&mut self) -> [Self::Item; N];
66

7-
fn custom_collect_array<const N: usize>(&mut self) -> [Self::Item; N] {
7+
fn collect_array<const N: usize>(&mut self) -> [Self::Item; N] {
88
let result = self.inner_array();
99
assert!(self.next().is_none());
1010
result
@@ -34,5 +34,5 @@ where
3434

3535
fn main() {
3636
let mut foos = [0u64; 9].iter().cloned();
37-
let _bar: [u64; 9] = foos.custom_collect_array::<9_usize>();
37+
let _bar: [u64; 9] = foos.collect_array::<9_usize>();
3838
}

tests/ui/mir/mir-inlining/ice-issue-77564.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ where
2929

3030
fn main() {
3131
assert_eq!(
32-
CollectArray::collect_array(
33-
&mut [[1, 2], [3, 4]]
32+
[[1, 2], [3, 4]]
3433
.iter()
35-
.map(|row| CollectArray::collect_array(&mut row.iter()))
36-
),
34+
.map(|row| row.iter().collect_array())
35+
.collect_array(),
3736
[[&1, &2], [&3, &4]]
3837
);
3938
}

0 commit comments

Comments
 (0)