|
19 | 19 |
|
20 | 20 | use crate::walk::{filter_dirs, walk};
|
21 | 21 | use regex::{Regex, RegexSet};
|
| 22 | +use rustc_hash::FxHashMap; |
22 | 23 | use std::{ffi::OsStr, path::Path};
|
23 | 24 |
|
| 25 | +#[cfg(test)] |
| 26 | +mod tests; |
| 27 | + |
24 | 28 | /// Error code markdown is restricted to 80 columns because they can be
|
25 | 29 | /// displayed on the console with --example.
|
26 | 30 | const ERROR_CODE_COLS: usize = 80;
|
@@ -65,12 +69,56 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
|
65 | 69 | "//@ normalize-stderr-test",
|
66 | 70 | ];
|
67 | 71 |
|
| 72 | +fn generate_problems<'a>( |
| 73 | + consts: &'a [u32], |
| 74 | + letter_digit: &'a FxHashMap<char, char>, |
| 75 | +) -> impl Iterator<Item = u32> + 'a { |
| 76 | + consts.iter().flat_map(move |const_value| { |
| 77 | + let problem = |
| 78 | + letter_digit.iter().fold(format!("{:X}", const_value), |acc, (key, value)| { |
| 79 | + acc.replace(&value.to_string(), &key.to_string()) |
| 80 | + }); |
| 81 | + let indexes: Vec<usize> = problem |
| 82 | + .chars() |
| 83 | + .enumerate() |
| 84 | + .filter_map(|(index, c)| if letter_digit.contains_key(&c) { Some(index) } else { None }) |
| 85 | + .collect(); |
| 86 | + (0..1 << indexes.len()).map(move |i| { |
| 87 | + u32::from_str_radix( |
| 88 | + &problem |
| 89 | + .chars() |
| 90 | + .enumerate() |
| 91 | + .map(|(index, c)| { |
| 92 | + if let Some(pos) = indexes.iter().position(|&x| x == index) { |
| 93 | + if (i >> pos) & 1 == 1 { letter_digit[&c] } else { c } |
| 94 | + } else { |
| 95 | + c |
| 96 | + } |
| 97 | + }) |
| 98 | + .collect::<String>(), |
| 99 | + 0x10, |
| 100 | + ) |
| 101 | + .unwrap() |
| 102 | + }) |
| 103 | + }) |
| 104 | +} |
| 105 | + |
68 | 106 | // Intentionally written in decimal rather than hex
|
69 |
| -const PROBLEMATIC_CONSTS: &[u32] = &[ |
| 107 | +const ROOT_PROBLEMATIC_CONSTS: &[u32] = &[ |
70 | 108 | 184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037,
|
71 |
| - 3735927486, 3735932941, 4027431614, 4276992702, |
| 109 | + 3735927486, 3735932941, 4027431614, 4276992702, 195934910, 252707358, 762133, 179681982, |
| 110 | + 173390526, 721077, |
72 | 111 | ];
|
73 | 112 |
|
| 113 | +fn generate_problematic_strings( |
| 114 | + consts: &[u32], |
| 115 | + letter_digit: &FxHashMap<char, char>, |
| 116 | +) -> Vec<String> { |
| 117 | + generate_problems(consts, letter_digit) |
| 118 | + .flat_map(|v| vec![v.to_string(), format!("{:x}", v), format!("{:X}", v)]) |
| 119 | + .collect() |
| 120 | +} |
| 121 | + |
74 | 122 | const INTERNAL_COMPILER_DOCS_LINE: &str = "#### This error code is internal to the compiler and will not be emitted with normal Rust code.";
|
75 | 123 |
|
76 | 124 | /// Parser states for `line_is_url`.
|
@@ -267,11 +315,10 @@ pub fn check(path: &Path, bad: &mut bool) {
|
267 | 315 | // We only check CSS files in rustdoc.
|
268 | 316 | path.extension().map_or(false, |e| e == "css") && !is_in(path, "src", "librustdoc")
|
269 | 317 | }
|
270 |
| - |
271 |
| - let problematic_consts_strings: Vec<String> = (PROBLEMATIC_CONSTS.iter().map(u32::to_string)) |
272 |
| - .chain(PROBLEMATIC_CONSTS.iter().map(|v| format!("{:x}", v))) |
273 |
| - .chain(PROBLEMATIC_CONSTS.iter().map(|v| format!("{:X}", v))) |
274 |
| - .collect(); |
| 318 | + let problematic_consts_strings = generate_problematic_strings( |
| 319 | + ROOT_PROBLEMATIC_CONSTS, |
| 320 | + &[('A', '4'), ('B', '8'), ('E', '3')].iter().cloned().collect(), |
| 321 | + ); |
275 | 322 | let problematic_regex = RegexSet::new(problematic_consts_strings.as_slice()).unwrap();
|
276 | 323 |
|
277 | 324 | walk(path, skip, &mut |entry, contents| {
|
|
0 commit comments