diff options
| author | Ralf Jung <post@ralfj.de> | 2020-09-20 12:08:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-20 12:08:26 +0200 |
| commit | 50d56bc774f9ecb2b43640651401f3cb346c1b89 (patch) | |
| tree | eb0a2096eb5f22ed3c126d0ec3ed6fbac5970398 /compiler/rustc_span/src | |
| parent | df4e4ef2b9c6674cc93444b925ca8c3d0c17ab90 (diff) | |
| parent | bfb221b21e13e8fd71a8fc3a2df23e7f0e775df3 (diff) | |
| download | rust-50d56bc774f9ecb2b43640651401f3cb346c1b89.tar.gz rust-50d56bc774f9ecb2b43640651401f3cb346c1b89.zip | |
Rollup merge of #76825 - lcnr:array-windows-apply, r=varkor
use `array_windows` instead of `windows` in the compiler I do think these changes are beautiful, but do have to admit that using type inference for the window length can easily be confusing. This seems like a general issue with const generics, where inferring constants adds an additional complexity which users have to learn and keep in mind.
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 1d1013967b7..a730c303788 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -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)] @@ -1156,7 +1157,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 { @@ -1171,7 +1177,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 => { |
