Skip to content

Commit 2793672

Browse files
committed
use array_windows instead of windows in the compiler
1 parent 95386b6 commit 2793672

File tree

11 files changed

+21
-17
lines changed

11 files changed

+21
-17
lines changed

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
1010
#![allow(incomplete_features)]
11+
#![feature(array_windows)]
1112
#![feature(control_flow_enum)]
1213
#![feature(in_band_lifetimes)]
1314
#![feature(unboxed_closures)]

compiler/rustc_data_structures/src/sorted_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<K: Ord, V> SortedMap<K, V> {
3434
/// and that there are no duplicates.
3535
#[inline]
3636
pub fn from_presorted_elements(elements: Vec<(K, V)>) -> SortedMap<K, V> {
37-
debug_assert!(elements.windows(2).all(|w| w[0].0 < w[1].0));
37+
debug_assert!(elements.array_windows().all(|[fst, snd]| fst.0 < snd.0));
3838

3939
SortedMap { data: elements }
4040
}
@@ -159,7 +159,7 @@ impl<K: Ord, V> SortedMap<K, V> {
159159
return;
160160
}
161161

162-
debug_assert!(elements.windows(2).all(|w| w[0].0 < w[1].0));
162+
debug_assert!(elements.array_windows().all(|[fst, snd]| fst.0 < snd.0));
163163

164164
let start_index = self.lookup_index_for(&elements[0].0);
165165

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
2828
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
2929
#![cfg_attr(test, feature(test))]
30+
#![feature(array_windows)]
3031
#![feature(bool_to_option)]
3132
#![feature(box_syntax)]
3233
#![feature(crate_visibility_modifier)]

compiler/rustc_lint/src/nonstandard_style.rs

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

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//! This API is completely unstable and subject to change.
2424
2525
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
26+
#![feature(array_windows)]
2627
#![feature(backtrace)]
2728
#![feature(bool_to_option)]
2829
#![feature(box_patterns)]

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ impl<'tcx> TyCtxt<'tcx> {
24192419
eps: &[ExistentialPredicate<'tcx>],
24202420
) -> &'tcx List<ExistentialPredicate<'tcx>> {
24212421
assert!(!eps.is_empty());
2422-
assert!(eps.windows(2).all(|w| w[0].stable_cmp(self, &w[1]) != Ordering::Greater));
2422+
assert!(eps.array_windows().all(|[a, b]| a.stable_cmp(self, b) != Ordering::Greater));
24232423
self._intern_existential_predicates(eps)
24242424
}
24252425

compiler/rustc_mir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Rust MIR: a lowered representation of Rust.
66

77
#![feature(nll)]
88
#![feature(in_band_lifetimes)]
9+
#![feature(array_windows)]
910
#![feature(bool_to_option)]
1011
#![feature(box_patterns)]
1112
#![feature(box_syntax)]

compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,8 @@ where
277277

278278
symbols.sort_by_key(|sym| sym.1);
279279

280-
for pair in symbols.windows(2) {
281-
let sym1 = &pair[0].1;
282-
let sym2 = &pair[1].1;
283-
280+
for &[(mono_item1, ref sym1), (mono_item2, ref sym2)] in symbols.array_windows() {
284281
if sym1 == sym2 {
285-
let mono_item1 = pair[0].0;
286-
let mono_item2 = pair[1].0;
287-
288282
let span1 = mono_item1.local_span(tcx);
289283
let span2 = mono_item2.local_span(tcx);
290284

compiler/rustc_mir_build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Construction of MIR from HIR.
22
//!
33
//! This crate also contains the match exhaustiveness and usefulness checking.
4-
4+
#![feature(array_windows)]
55
#![feature(box_patterns)]
66
#![feature(box_syntax)]
77
#![feature(const_fn)]

compiler/rustc_mir_build/src/thir/pattern/_match.rs

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

compiler/rustc_span/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! This API is completely unstable and subject to change.
66
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
8+
#![feature(array_windows)]
89
#![feature(crate_visibility_modifier)]
910
#![feature(const_fn)]
1011
#![feature(const_panic)]
@@ -1158,7 +1159,12 @@ impl<S: Encoder> Encodable<S> for SourceFile {
11581159
let max_line_length = if lines.len() == 1 {
11591160
0
11601161
} else {
1161-
lines.windows(2).map(|w| w[1] - w[0]).map(|bp| bp.to_usize()).max().unwrap()
1162+
lines
1163+
.array_windows()
1164+
.map(|&[fst, snd]| snd - fst)
1165+
.map(|bp| bp.to_usize())
1166+
.max()
1167+
.unwrap()
11621168
};
11631169

11641170
let bytes_per_diff: u8 = match max_line_length {
@@ -1173,7 +1179,7 @@ impl<S: Encoder> Encodable<S> for SourceFile {
11731179
// Encode the first element.
11741180
lines[0].encode(s)?;
11751181

1176-
let diff_iter = (&lines[..]).windows(2).map(|w| (w[1] - w[0]));
1182+
let diff_iter = lines[..].array_windows().map(|&[fst, snd]| snd - fst);
11771183

11781184
match bytes_per_diff {
11791185
1 => {

0 commit comments

Comments
 (0)