Skip to content

Commit 91590f9

Browse files
committed
Migrate the rustdoc_json check to diagnostics
1 parent 6f4e724 commit 91590f9

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

src/tools/tidy/src/diagnostics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ impl RunningCheck {
116116
eprintln!("{t}");
117117
}
118118

119+
/// Output a message only if verbose output is enabled.
120+
pub fn verbose_msg<T: Display>(&mut self, t: T) {
121+
if self.ctx.lock().unwrap().verbose {
122+
self.message(t);
123+
}
124+
}
125+
119126
fn mark_as_bad(&mut self) {
120127
self.bad = true;
121128
}

src/tools/tidy/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn main() {
113113
check!(rustdoc_gui_tests, &tests_path);
114114
check!(rustdoc_css_themes, &librustdoc_path);
115115
check!(rustdoc_templates, &librustdoc_path);
116-
// check!(rustdoc_json, &src_path, &ci_info);
116+
check!(rustdoc_json, &src_path, &ci_info);
117117
check!(known_bug, &crashes_path);
118118
check!(unknown_revision, &tests_path);
119119

src/tools/tidy/src/rustdoc_json.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
use std::path::Path;
55
use std::str::FromStr;
66

7+
use crate::diagnostics::{CheckId, DiagCtx};
8+
79
const RUSTDOC_JSON_TYPES: &str = "src/rustdoc-json-types";
810

9-
pub fn check(src_path: &Path, ci_info: &crate::CiInfo, bad: &mut bool) {
10-
println!("Checking tidy rustdoc_json...");
11+
pub fn check(src_path: &Path, ci_info: &crate::CiInfo, diag_ctx: DiagCtx) {
12+
let mut check = diag_ctx.start_check(CheckId::new("rustdoc_json").path(src_path));
13+
1114
let Some(base_commit) = &ci_info.base_commit else {
12-
eprintln!("No base commit, skipping rustdoc_json check");
15+
check.verbose_msg("No base commit, skipping rustdoc_json check");
1316
return;
1417
};
1518

1619
// First we check that `src/rustdoc-json-types` was modified.
1720
if !crate::files_modified(ci_info, |p| p == RUSTDOC_JSON_TYPES) {
1821
// `rustdoc-json-types` was not modified so nothing more to check here.
19-
println!("`rustdoc-json-types` was not modified.");
22+
check.verbose_msg("`rustdoc-json-types` was not modified.");
2023
return;
2124
}
2225
// Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated.
@@ -45,34 +48,29 @@ pub fn check(src_path: &Path, ci_info: &crate::CiInfo, bad: &mut bool) {
4548
}
4649
}
4750
if format_version_updated != latest_feature_comment_updated {
48-
*bad = true;
49-
if latest_feature_comment_updated {
50-
eprintln!(
51-
"error in `rustdoc_json` tidy check: `Latest feature` comment was updated \
52-
whereas `FORMAT_VERSION` wasn't in `{RUSTDOC_JSON_TYPES}/lib.rs`"
53-
);
51+
let msg = if latest_feature_comment_updated {
52+
format!(
53+
"`Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't in `{RUSTDOC_JSON_TYPES}/lib.rs`"
54+
)
5455
} else {
55-
eprintln!(
56-
"error in `rustdoc_json` tidy check: `Latest feature` comment was not \
57-
updated whereas `FORMAT_VERSION` was in `{RUSTDOC_JSON_TYPES}/lib.rs`"
58-
);
59-
}
56+
format!(
57+
"`Latest feature` comment was not updated whereas `FORMAT_VERSION` was in `{RUSTDOC_JSON_TYPES}/lib.rs`"
58+
)
59+
};
60+
check.error(msg);
6061
}
6162
match (new_version, old_version) {
6263
(Some(new_version), Some(old_version)) if new_version != old_version + 1 => {
63-
*bad = true;
64-
eprintln!(
65-
"error in `rustdoc_json` tidy check: invalid `FORMAT_VERSION` increase in \
66-
`{RUSTDOC_JSON_TYPES}/lib.rs`, should be `{}`, found `{new_version}`",
64+
check.error(format!(
65+
"invalid `FORMAT_VERSION` increase in `{RUSTDOC_JSON_TYPES}/lib.rs`, should be `{}`, found `{new_version}`",
6766
old_version + 1,
68-
);
67+
));
6968
}
7069
_ => {}
7170
}
7271
}
7372
None => {
74-
*bad = true;
75-
eprintln!("error: failed to run `git diff` in rustdoc_json check");
73+
check.error("failed to run `git diff` in rustdoc_json check");
7674
}
7775
}
7876
}

0 commit comments

Comments
 (0)