Skip to content

Commit 9cf485b

Browse files
committed
Migrate the rustdoc_css_themes check to diagnostics
1 parent 65f8492 commit 9cf485b

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

src/tools/tidy/src/main.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn main() {
111111
check!(ui_tests, &root_path, bless);
112112
check!(mir_opt_tests, &tests_path, bless);
113113
check!(rustdoc_gui_tests, &tests_path);
114-
// check!(rustdoc_css_themes, &librustdoc_path);
114+
check!(rustdoc_css_themes, &librustdoc_path);
115115
// check!(rustdoc_templates, &librustdoc_path);
116116
// check!(rustdoc_json, &src_path, &ci_info);
117117
check!(known_bug, &crashes_path);
@@ -160,19 +160,14 @@ fn main() {
160160
let collected = {
161161
drain_handles(&mut handles);
162162

163-
let mut flag = false;
164-
let r = features::check(
163+
features::check(
165164
&src_path,
166165
&tests_path,
167166
&compiler_path,
168167
&library_path,
169-
&mut flag,
168+
diag_ctx.clone(),
170169
verbose,
171-
);
172-
if flag {
173-
bad.store(true, Ordering::Relaxed);
174-
}
175-
r
170+
)
176171
};
177172
// check!(unstable_book, &src_path, collected);
178173
//

src/tools/tidy/src/rustdoc_css_themes.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
44
use std::path::Path;
55

6-
pub fn check(librustdoc_path: &Path, bad: &mut bool) {
6+
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
7+
8+
pub fn check(librustdoc_path: &Path, diag_ctx: DiagCtx) {
9+
let mut check = diag_ctx.start_check(CheckId::new("rustdoc_css_themes").path(librustdoc_path));
10+
711
let rustdoc_css = "html/static/css/rustdoc.css";
812
let noscript_css = "html/static/css/noscript.css";
913
let rustdoc_css_contents = std::fs::read_to_string(librustdoc_path.join(rustdoc_css))
@@ -14,21 +18,21 @@ pub fn check(librustdoc_path: &Path, bad: &mut bool) {
1418
"light",
1519
rustdoc_css_contents.lines().enumerate().map(|(i, l)| (i + 1, l.trim())),
1620
noscript_css_contents.lines().enumerate().map(|(i, l)| (i + 1, l.trim())),
17-
bad,
21+
&mut check,
1822
);
1923
compare_themes_from_files(
2024
"dark",
2125
rustdoc_css_contents.lines().enumerate(),
2226
noscript_css_contents.lines().enumerate(),
23-
bad,
27+
&mut check,
2428
);
2529
}
2630

2731
fn compare_themes_from_files<'a>(
2832
name: &str,
2933
mut rustdoc_css_lines: impl Iterator<Item = (usize, &'a str)>,
3034
mut noscript_css_lines: impl Iterator<Item = (usize, &'a str)>,
31-
bad: &mut bool,
35+
check: &mut RunningCheck,
3236
) {
3337
let begin_theme_pat = format!("/* Begin theme: {name}");
3438
let mut found_theme = None;
@@ -38,10 +42,9 @@ fn compare_themes_from_files<'a>(
3842
continue;
3943
}
4044
if let Some(found_theme) = found_theme {
41-
tidy_error!(
42-
bad,
45+
check.error(format!(
4346
"rustdoc.css contains two {name} themes on lines {rustdoc_css_line_number} and {found_theme}",
44-
);
47+
));
4548
return;
4649
}
4750
found_theme = Some(rustdoc_css_line_number);
@@ -50,14 +53,13 @@ fn compare_themes_from_files<'a>(
5053
continue;
5154
}
5255
if let Some(found_theme_noscript) = found_theme_noscript {
53-
tidy_error!(
54-
bad,
56+
check.error(format!(
5557
"noscript.css contains two {name} themes on lines {noscript_css_line_number} and {found_theme_noscript}",
56-
);
58+
));
5759
return;
5860
}
5961
found_theme_noscript = Some(noscript_css_line_number);
60-
compare_themes(name, &mut rustdoc_css_lines, &mut noscript_css_lines, bad);
62+
compare_themes(name, &mut rustdoc_css_lines, &mut noscript_css_lines, check);
6163
}
6264
}
6365
}
@@ -66,7 +68,7 @@ fn compare_themes<'a>(
6668
name: &str,
6769
rustdoc_css_lines: impl Iterator<Item = (usize, &'a str)>,
6870
noscript_css_lines: impl Iterator<Item = (usize, &'a str)>,
69-
bad: &mut bool,
71+
check: &mut RunningCheck,
7072
) {
7173
let end_theme_pat = format!("/* End theme: {name}");
7274
for (
@@ -90,12 +92,11 @@ fn compare_themes<'a>(
9092
break;
9193
}
9294
if rustdoc_css_line != noscript_css_line {
93-
tidy_error!(
94-
bad,
95-
"noscript.css:{noscript_css_line_number} and rustdoc.css:{rustdoc_css_line_number} contain copies of {name} theme that are not the same",
96-
);
97-
eprintln!("- {noscript_css_line}");
98-
eprintln!("+ {rustdoc_css_line}");
95+
check.error(format!(
96+
r#"noscript.css:{noscript_css_line_number} and rustdoc.css:{rustdoc_css_line_number} contain copies of {name} theme that are not the same
97+
- {noscript_css_line}
98+
+ {rustdoc_css_line}"#,
99+
));
99100
return;
100101
}
101102
}

0 commit comments

Comments
 (0)