Skip to content

Commit 047a0c6

Browse files
committed
use regex to check for problems
1 parent 7b7a26b commit 047a0c6

File tree

1 file changed

+11
-41
lines changed

1 file changed

+11
-41
lines changed

src/tools/tidy/src/style.rs

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use crate::walk::{filter_dirs, walk};
2121
use regex::{Regex, RegexSet};
22-
use std::collections::HashMap;
2322
use std::{ffi::OsStr, path::Path};
2423

2524
/// Error code markdown is restricted to 80 columns because they can be
@@ -66,39 +65,8 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
6665
"//@ normalize-stderr-test",
6766
];
6867

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-
10068
// Intentionally written in decimal rather than hex
101-
const ROOT_PROBLEMATIC_CONSTS: &[u32] = &[
69+
const PROBLEMATIC_CONSTS: &[u32] = &[
10270
184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037,
10371
3735927486, 3735932941, 4027431614, 4276992702, 195934910, 252707358, 762133, 179681982,
10472
173390526,
@@ -300,14 +268,16 @@ pub fn check(path: &Path, bad: &mut bool) {
300268
// We only check CSS files in rustdoc.
301269
path.extension().map_or(false, |e| e == "css") && !is_in(path, "src", "librustdoc")
302270
}
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)))
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+
}))
311281
.collect();
312282
let problematic_regex = RegexSet::new(problematic_consts_strings.as_slice()).unwrap();
313283

0 commit comments

Comments
 (0)