|
19 | 19 |
|
20 | 20 | use crate::walk::{filter_dirs, walk};
|
21 | 21 | use regex::{Regex, RegexSet};
|
22 |
| -use std::{ffi::OsStr, path::Path}; |
23 | 22 | use std::collections::HashMap;
|
| 23 | +use std::{ffi::OsStr, path::Path}; |
24 | 24 |
|
25 | 25 | /// Error code markdown is restricted to 80 columns because they can be
|
26 | 26 | /// displayed on the console with --example.
|
@@ -66,40 +66,42 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
|
66 | 66 | "//@ normalize-stderr-test",
|
67 | 67 | ];
|
68 | 68 |
|
69 |
| -fn generate_problems<'a>(consts: &'a[u32], letter_digit: &'a HashMap<char, char>) -> impl Iterator<Item = u32> + 'a { |
| 69 | +fn generate_problems<'a>( |
| 70 | + consts: &'a [u32], |
| 71 | + letter_digit: &'a HashMap<char, char>, |
| 72 | +) -> impl Iterator<Item = u32> + 'a { |
70 | 73 | consts.into_iter().flat_map(move |const_value| {
|
71 | 74 | let mut problem = format!("{:X}", const_value);
|
72 | 75 | for (key, value) in letter_digit {
|
73 | 76 | problem = problem.replace(&value.to_string(), &key.to_string());
|
74 | 77 | }
|
75 |
| - let indexes: Vec<usize> = problem.chars().enumerate().filter_map(|(index, c)| { |
76 |
| - if letter_digit.contains_key(&c) { |
77 |
| - Some(index) |
78 |
| - } |
79 |
| - else { |
80 |
| - None |
81 |
| - } |
82 |
| - }).collect(); |
| 78 | + let indexes: Vec<usize> = problem |
| 79 | + .chars() |
| 80 | + .enumerate() |
| 81 | + .filter_map(|(index, c)| if letter_digit.contains_key(&c) { Some(index) } else { None }) |
| 82 | + .collect(); |
83 | 83 | (0..1 << indexes.len()).map(move |i| {
|
84 |
| - let result = problem.chars().enumerate().map(|(index, c)| { |
85 |
| - if let Some(pos) = indexes.iter().position(|&x| x == index) { |
86 |
| - if (i >> pos) & 1 == 1 { |
87 |
| - letter_digit[&c] |
| 84 | + let result = problem |
| 85 | + .chars() |
| 86 | + .enumerate() |
| 87 | + .map(|(index, c)| { |
| 88 | + if let Some(pos) = indexes.iter().position(|&x| x == index) { |
| 89 | + if (i >> pos) & 1 == 1 { letter_digit[&c] } else { c } |
88 | 90 | } else {
|
89 | 91 | c
|
90 | 92 | }
|
91 |
| - } else { |
92 |
| - c |
93 |
| - } |
94 |
| - }).collect::<String>(); |
| 93 | + }) |
| 94 | + .collect::<String>(); |
95 | 95 | u32::from_str_radix(&result, 0x10).unwrap()
|
96 | 96 | })
|
97 | 97 | })
|
98 | 98 | }
|
99 | 99 |
|
| 100 | +// Intentionally written in decimal rather than hex |
100 | 101 | const ROOT_PROBLEMATIC_CONSTS: &[u32] = &[
|
101 |
| - 184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037, |
102 |
| - 3735927486, 3735932941, 4027431614, 4276992702, 195934910, 252707358, 762133, 179681982, 173390526, |
| 102 | + 184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037, |
| 103 | + 3735927486, 3735932941, 4027431614, 4276992702, 195934910, 252707358, 762133, 179681982, |
| 104 | + 173390526, |
103 | 105 | ];
|
104 | 106 |
|
105 | 107 | const INTERNAL_COMPILER_DOCS_LINE: &str = "#### This error code is internal to the compiler and will not be emitted with normal Rust code.";
|
@@ -298,7 +300,11 @@ pub fn check(path: &Path, bad: &mut bool) {
|
298 | 300 | // We only check CSS files in rustdoc.
|
299 | 301 | path.extension().map_or(false, |e| e == "css") && !is_in(path, "src", "librustdoc")
|
300 | 302 | }
|
301 |
| - let problematic_consts = generate_problems(ROOT_PROBLEMATIC_CONSTS, &[('A', '4'), ('B', '8'), ('E', '3')].iter().cloned().collect()).collect::<Vec<u32>>(); |
| 303 | + let problematic_consts = generate_problems( |
| 304 | + ROOT_PROBLEMATIC_CONSTS, |
| 305 | + &[('A', '4'), ('B', '8'), ('E', '3')].iter().cloned().collect(), |
| 306 | + ) |
| 307 | + .collect::<Vec<u32>>(); |
302 | 308 | let problematic_consts_strings: Vec<String> = (problematic_consts.iter().map(u32::to_string))
|
303 | 309 | .chain(problematic_consts.iter().map(|v| format!("{:x}", v)))
|
304 | 310 | .chain(problematic_consts.iter().map(|v| format!("{:X}", v)))
|
@@ -590,4 +596,4 @@ pub fn check(path: &Path, bad: &mut bool) {
|
590 | 596 | let _unused = skip_line_length;
|
591 | 597 | let _unused = skip_file_length;
|
592 | 598 | })
|
593 |
| - } |
| 599 | + } |
0 commit comments