Skip to content

Commit 9dbc9ed

Browse files
authored
Rollup merge of #77514 - scottmcm:less-once-chain-once, r=estebank
Replace some once(x).chain(once(y)) with [x, y] IntoIter Now that we have by-value array iterators that are [already used](https://github.com/rust-lang/rust/blob/25c8c53dd994acb3f4f7c02fe6bb46076393f8b0/compiler/rustc_hir/src/def.rs#L305-L307)... For example, ```diff - once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it) + IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it) ```
2 parents 5fbb411 + d74b8e0 commit 9dbc9ed

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

compiler/rustc_hir/src/def.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ impl<T> PerNS<Option<T>> {
341341

342342
/// Returns an iterator over the items which are `Some`.
343343
pub fn present_items(self) -> impl Iterator<Item = T> {
344-
use std::iter::once;
345-
346-
once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
344+
IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
347345
}
348346
}
349347

compiler/rustc_trait_selection/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! This API is completely unstable and subject to change.
1212
1313
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
14+
#![feature(array_value_iter)]
1415
#![feature(bool_to_option)]
1516
#![feature(box_patterns)]
1617
#![feature(drain_filter)]

compiler/rustc_trait_selection/src/traits/object_safety.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_span::symbol::Symbol;
2424
use rustc_span::Span;
2525
use smallvec::SmallVec;
2626

27+
use std::array;
2728
use std::iter;
2829

2930
pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation};
@@ -652,8 +653,7 @@ fn receiver_is_dispatchable<'tcx>(
652653
let caller_bounds: Vec<Predicate<'tcx>> = param_env
653654
.caller_bounds()
654655
.iter()
655-
.chain(iter::once(unsize_predicate))
656-
.chain(iter::once(trait_predicate))
656+
.chain(array::IntoIter::new([unsize_predicate, trait_predicate]))
657657
.collect();
658658

659659
ty::ParamEnv::new(tcx.intern_predicates(&caller_bounds), param_env.reveal())

compiler/rustc_typeck/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
3535
use rustc_trait_selection::traits::wf::object_region_bounds;
3636

3737
use smallvec::SmallVec;
38+
use std::array;
3839
use std::collections::BTreeSet;
39-
use std::iter;
4040
use std::slice;
4141

4242
#[derive(Debug)]
@@ -1346,7 +1346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13461346
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
13471347

13481348
let is_equality = is_equality();
1349-
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
1349+
let bounds = array::IntoIter::new([bound, bound2]).chain(matching_candidates);
13501350
let mut err = if is_equality.is_some() {
13511351
// More specific Error Index entry.
13521352
struct_span_err!(

compiler/rustc_typeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This API is completely unstable and subject to change.
5656
*/
5757

5858
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
59+
#![feature(array_value_iter)]
5960
#![feature(bool_to_option)]
6061
#![feature(box_syntax)]
6162
#![feature(crate_visibility_modifier)]

library/alloc/src/collections/vec_deque.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
// ignore-tidy-filelength
1111

12+
use core::array;
1213
use core::cmp::{self, Ordering};
1314
use core::fmt;
1415
use core::hash::{Hash, Hasher};
15-
use core::iter::{once, repeat_with, FromIterator, FusedIterator};
16+
use core::iter::{repeat_with, FromIterator, FusedIterator};
1617
use core::mem::{self, replace, ManuallyDrop};
1718
use core::ops::{Index, IndexMut, Range, RangeBounds, Try};
1819
use core::ptr::{self, NonNull};
@@ -99,7 +100,7 @@ impl<'a, 'b, T> PairSlices<'a, 'b, T> {
99100
}
100101

101102
fn remainder(self) -> impl Iterator<Item = &'b [T]> {
102-
once(self.b0).chain(once(self.b1))
103+
array::IntoIter::new([self.b0, self.b1])
103104
}
104105
}
105106

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#![cfg_attr(test, feature(new_uninit))]
7878
#![feature(allocator_api)]
7979
#![feature(array_chunks)]
80+
#![feature(array_value_iter)]
8081
#![feature(array_windows)]
8182
#![feature(allow_internal_unstable)]
8283
#![feature(arbitrary_self_types)]

0 commit comments

Comments
 (0)