use array_windows instead of windows in the compiler

This commit is contained in:
Bastian Kauschke 2020-09-17 09:28:14 +02:00
parent 255a4c58f5
commit 3435683fd5
11 changed files with 21 additions and 17 deletions

View File

@ -8,6 +8,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![allow(incomplete_features)]
#![feature(array_windows)]
#![feature(control_flow_enum)]
#![feature(in_band_lifetimes)]
#![feature(unboxed_closures)]

View File

@ -34,7 +34,7 @@ impl<K: Ord, V> SortedMap<K, V> {
/// and that there are no duplicates.
#[inline]
pub fn from_presorted_elements(elements: Vec<(K, V)>) -> SortedMap<K, V> {
debug_assert!(elements.windows(2).all(|w| w[0].0 < w[1].0));
debug_assert!(elements.array_windows().all(|[fst, snd]| fst.0 < snd.0));
SortedMap { data: elements }
}
@ -159,7 +159,7 @@ impl<K: Ord, V> SortedMap<K, V> {
return;
}
debug_assert!(elements.windows(2).all(|w| w[0].0 < w[1].0));
debug_assert!(elements.array_windows().all(|[fst, snd]| fst.0 < snd.0));
let start_index = self.lookup_index_for(&elements[0].0);

View File

@ -27,6 +27,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![cfg_attr(test, feature(test))]
#![feature(array_windows)]
#![feature(bool_to_option)]
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]

View File

@ -70,9 +70,9 @@ fn is_camel_case(name: &str) -> bool {
// ones (some scripts don't have a concept of upper/lowercase)
!name.chars().next().unwrap().is_lowercase()
&& !name.contains("__")
&& !name.chars().collect::<Vec<_>>().windows(2).any(|pair| {
&& !name.chars().collect::<Vec<_>>().array_windows().any(|&[fst, snd]| {
// contains a capitalisable character followed by, or preceded by, an underscore
char_has_case(pair[0]) && pair[1] == '_' || char_has_case(pair[1]) && pair[0] == '_'
char_has_case(fst) && snd == '_' || char_has_case(snd) && fst == '_'
})
}

View File

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

View File

@ -2419,7 +2419,7 @@ impl<'tcx> TyCtxt<'tcx> {
eps: &[ExistentialPredicate<'tcx>],
) -> &'tcx List<ExistentialPredicate<'tcx>> {
assert!(!eps.is_empty());
assert!(eps.windows(2).all(|w| w[0].stable_cmp(self, &w[1]) != Ordering::Greater));
assert!(eps.array_windows().all(|[a, b]| a.stable_cmp(self, b) != Ordering::Greater));
self._intern_existential_predicates(eps)
}

View File

@ -6,6 +6,7 @@ Rust MIR: a lowered representation of Rust.
#![feature(nll)]
#![feature(in_band_lifetimes)]
#![feature(array_windows)]
#![feature(bindings_after_at)]
#![feature(bool_to_option)]
#![feature(box_patterns)]

View File

@ -277,14 +277,8 @@ where
symbols.sort_by_key(|sym| sym.1);
for pair in symbols.windows(2) {
let sym1 = &pair[0].1;
let sym2 = &pair[1].1;
for &[(mono_item1, ref sym1), (mono_item2, ref sym2)] in symbols.array_windows() {
if sym1 == sym2 {
let mono_item1 = pair[0].0;
let mono_item2 = pair[1].0;
let span1 = mono_item1.local_span(tcx);
let span2 = mono_item2.local_span(tcx);

View File

@ -1,7 +1,7 @@
//! Construction of MIR from HIR.
//!
//! This crate also contains the match exhaustiveness and usefulness checking.
#![feature(array_windows)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(const_fn)]

View File

@ -2299,8 +2299,8 @@ fn split_grouped_constructors<'p, 'tcx>(
// interval into a constructor.
split_ctors.extend(
borders
.windows(2)
.filter_map(|window| match (window[0], window[1]) {
.array_windows()
.filter_map(|&[fst, snd]| match (fst, snd) {
(Border::JustBefore(n), Border::JustBefore(m)) => {
if n < m {
Some(IntRange { range: n..=(m - 1), ty, span })

View File

@ -5,6 +5,7 @@
//! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(array_windows)]
#![feature(crate_visibility_modifier)]
#![feature(const_fn)]
#![feature(const_panic)]
@ -1158,7 +1159,12 @@ impl<S: Encoder> Encodable<S> for SourceFile {
let max_line_length = if lines.len() == 1 {
0
} else {
lines.windows(2).map(|w| w[1] - w[0]).map(|bp| bp.to_usize()).max().unwrap()
lines
.array_windows()
.map(|&[fst, snd]| snd - fst)
.map(|bp| bp.to_usize())
.max()
.unwrap()
};
let bytes_per_diff: u8 = match max_line_length {
@ -1173,7 +1179,7 @@ impl<S: Encoder> Encodable<S> for SourceFile {
// Encode the first element.
lines[0].encode(s)?;
let diff_iter = (&lines[..]).windows(2).map(|w| (w[1] - w[0]));
let diff_iter = lines[..].array_windows().map(|&[fst, snd]| snd - fst);
match bytes_per_diff {
1 => {