|
19 | 19 |
|
20 | 20 | use crate::walk::{filter_dirs, walk};
|
21 | 21 | use regex::{Regex, RegexSet};
|
| 22 | +use std::collections::HashMap; |
22 | 23 | use std::{ffi::OsStr, path::Path};
|
23 | 24 |
|
24 | 25 | /// Error code markdown is restricted to 80 columns because they can be
|
@@ -65,8 +66,39 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
|
65 | 66 | "//@ normalize-stderr-test",
|
66 | 67 | ];
|
67 | 68 |
|
| 69 | +fn generate_problems<'a>( |
| 70 | + consts: &'a [u32], |
| 71 | + letter_digit: &'a HashMap<char, char>, |
| 72 | +) -> impl Iterator<Item = u32> + 'a { |
| 73 | + consts.into_iter().flat_map(move |const_value| { |
| 74 | + let mut problem = format!("{:X}", const_value); |
| 75 | + for (key, value) in letter_digit { |
| 76 | + problem = problem.replace(&value.to_string(), &key.to_string()); |
| 77 | + } |
| 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 | + (0..1 << indexes.len()).map(move |i| { |
| 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 } |
| 90 | + } else { |
| 91 | + c |
| 92 | + } |
| 93 | + }) |
| 94 | + .collect::<String>(); |
| 95 | + u32::from_str_radix(&result, 0x10).unwrap() |
| 96 | + }) |
| 97 | + }) |
| 98 | +} |
| 99 | + |
68 | 100 | // Intentionally written in decimal rather than hex
|
69 |
| -const PROBLEMATIC_CONSTS: &[u32] = &[ |
| 101 | +const ROOT_PROBLEMATIC_CONSTS: &[u32] = &[ |
70 | 102 | 184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037,
|
71 | 103 | 3735927486, 3735932941, 4027431614, 4276992702, 195934910, 252707358, 762133, 179681982,
|
72 | 104 | 173390526,
|
@@ -268,16 +300,14 @@ pub fn check(path: &Path, bad: &mut bool) {
|
268 | 300 | // We only check CSS files in rustdoc.
|
269 | 301 | path.extension().map_or(false, |e| e == "css") && !is_in(path, "src", "librustdoc")
|
270 | 302 | }
|
271 |
| - let problematic_consts_strings: Vec<String> = (PROBLEMATIC_CONSTS.iter().map(u32::to_string)) |
272 |
| - .chain(PROBLEMATIC_CONSTS.iter().map(|v| { |
273 |
| - format!("{:x}", v) |
274 |
| - .replace("a", "[aA4]") |
275 |
| - .replace("b", "[bB8]") |
276 |
| - .replace("c", "[cC]") |
277 |
| - .replace("d", "[dD]") |
278 |
| - .replace("e", "[eE3]") |
279 |
| - .replace("f", "[fF]") |
280 |
| - })) |
| 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>>(); |
| 308 | + let problematic_consts_strings: Vec<String> = (problematic_consts.iter().map(u32::to_string)) |
| 309 | + .chain(problematic_consts.iter().map(|v| format!("{:x}", v))) |
| 310 | + .chain(problematic_consts.iter().map(|v| format!("{:X}", v))) |
281 | 311 | .collect();
|
282 | 312 | let problematic_regex = RegexSet::new(problematic_consts_strings.as_slice()).unwrap();
|
283 | 313 |
|
|
0 commit comments