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](25c8c53dd9/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)
```
This commit is contained in:
Dylan DPC 2020-10-05 02:29:42 +02:00 committed by GitHub
commit 9dbc9ed870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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`.
pub fn present_items(self) -> impl Iterator<Item = T> {
use std::iter::once;
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)
}
}

View File

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

View File

@ -24,6 +24,7 @@ use rustc_span::symbol::Symbol;
use rustc_span::Span;
use smallvec::SmallVec;
use std::array;
use std::iter;
pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation};
@ -652,8 +653,7 @@ fn receiver_is_dispatchable<'tcx>(
let caller_bounds: Vec<Predicate<'tcx>> = param_env
.caller_bounds()
.iter()
.chain(iter::once(unsize_predicate))
.chain(iter::once(trait_predicate))
.chain(array::IntoIter::new([unsize_predicate, trait_predicate]))
.collect();
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 smallvec::SmallVec;
use std::array;
use std::collections::BTreeSet;
use std::iter;
use std::slice;
#[derive(Debug)]
@ -1346,7 +1346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
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() {
// More specific Error Index entry.
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/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)]
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]

View File

@ -9,10 +9,11 @@
// ignore-tidy-filelength
use core::array;
use core::cmp::{self, Ordering};
use core::fmt;
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::ops::{Index, IndexMut, Range, RangeBounds, Try};
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]> {
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))]
#![feature(allocator_api)]
#![feature(array_chunks)]
#![feature(array_value_iter)]
#![feature(array_windows)]
#![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)]