Replace some once(x).chain(once(y)) with [x, y] IntoIter

Now that we have by-value array iterators...
This commit is contained in:
Scott McMurray 2020-10-03 16:51:43 -07:00
parent 738d4a7a36
commit d74b8e0505
7 changed files with 11 additions and 9 deletions

View File

@ -341,9 +341,7 @@ impl<T> PerNS<Option<T>> {
/// Returns an iterator over the items which are `Some`. /// Returns an iterator over the items which are `Some`.
pub fn present_items(self) -> impl Iterator<Item = T> { pub fn present_items(self) -> impl Iterator<Item = T> {
use std::iter::once; IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
} }
} }

View File

@ -11,6 +11,7 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(drain_filter)] #![feature(drain_filter)]

View File

@ -24,6 +24,7 @@ use rustc_span::symbol::Symbol;
use rustc_span::Span; use rustc_span::Span;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::array;
use std::iter; use std::iter;
pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation}; pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation};
@ -652,8 +653,7 @@ fn receiver_is_dispatchable<'tcx>(
let caller_bounds: Vec<Predicate<'tcx>> = param_env let caller_bounds: Vec<Predicate<'tcx>> = param_env
.caller_bounds() .caller_bounds()
.iter() .iter()
.chain(iter::once(unsize_predicate)) .chain(array::IntoIter::new([unsize_predicate, trait_predicate]))
.chain(iter::once(trait_predicate))
.collect(); .collect();
ty::ParamEnv::new(tcx.intern_predicates(&caller_bounds), param_env.reveal()) ty::ParamEnv::new(tcx.intern_predicates(&caller_bounds), param_env.reveal())

View File

@ -35,8 +35,8 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
use rustc_trait_selection::traits::wf::object_region_bounds; use rustc_trait_selection::traits::wf::object_region_bounds;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::array;
use std::collections::BTreeSet; use std::collections::BTreeSet;
use std::iter;
use std::slice; use std::slice;
#[derive(Debug)] #[derive(Debug)]
@ -1346,7 +1346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2); debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
let is_equality = is_equality(); let is_equality = is_equality();
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates); let bounds = array::IntoIter::new([bound, bound2]).chain(matching_candidates);
let mut err = if is_equality.is_some() { let mut err = if is_equality.is_some() {
// More specific Error Index entry. // More specific Error Index entry.
struct_span_err!( struct_span_err!(

View File

@ -56,6 +56,7 @@ This API is completely unstable and subject to change.
*/ */
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]

View File

@ -9,10 +9,11 @@
// ignore-tidy-filelength // ignore-tidy-filelength
use core::array;
use core::cmp::{self, Ordering}; use core::cmp::{self, Ordering};
use core::fmt; use core::fmt;
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use core::iter::{once, repeat_with, FromIterator, FusedIterator}; use core::iter::{repeat_with, FromIterator, FusedIterator};
use core::mem::{self, replace, ManuallyDrop}; use core::mem::{self, replace, ManuallyDrop};
use core::ops::{Index, IndexMut, Range, RangeBounds, Try}; use core::ops::{Index, IndexMut, Range, RangeBounds, Try};
use core::ptr::{self, NonNull}; use core::ptr::{self, NonNull};
@ -99,7 +100,7 @@ impl<'a, 'b, T> PairSlices<'a, 'b, T> {
} }
fn remainder(self) -> impl Iterator<Item = &'b [T]> { fn remainder(self) -> impl Iterator<Item = &'b [T]> {
once(self.b0).chain(once(self.b1)) array::IntoIter::new([self.b0, self.b1])
} }
} }

View File

@ -77,6 +77,7 @@
#![cfg_attr(test, feature(new_uninit))] #![cfg_attr(test, feature(new_uninit))]
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(array_chunks)] #![feature(array_chunks)]
#![feature(array_value_iter)]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(allow_internal_unstable)] #![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)] #![feature(arbitrary_self_types)]