Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have been .flatten()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustratingly, flatten gives worse size_hints than filter_map today (#48544) and has more complicated code (needs to keep the iterator in its state after giving out an item, since unlike Option it doesn't know if that's the only item), so that's potentially a pessimization.

}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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!(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 3 additions & 2 deletions library/alloc/src/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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])
}
}

Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down