Skip to content

Commit 0dcf99b

Browse files
Rollup merge of #80025 - JohnTitor:tidy-error, r=Mark-Simulacrum
Replace some `println!` with `tidy_error!` to simplify
2 parents 6990419 + becd0e8 commit 0dcf99b

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

src/tools/tidy/src/deps.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
214214
for (name, license) in EXCEPTIONS {
215215
// Check that the package actually exists.
216216
if !metadata.packages.iter().any(|p| p.name == *name) {
217-
println!(
217+
tidy_error!(
218+
bad,
218219
"could not find exception package `{}`\n\
219220
Remove from EXCEPTIONS list if it is no longer used.",
220221
name
221222
);
222-
*bad = true;
223223
}
224224
// Check that the license hasn't changed.
225225
for pkg in metadata.packages.iter().filter(|p| p.name == *name) {
@@ -232,11 +232,11 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
232232
}
233233
match &pkg.license {
234234
None => {
235-
println!(
235+
tidy_error!(
236+
bad,
236237
"dependency exception `{}` does not declare a license expression",
237238
pkg.id
238239
);
239-
*bad = true;
240240
}
241241
Some(pkg_license) => {
242242
if pkg_license.as_str() != *license {
@@ -273,8 +273,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
273273
let license = match &pkg.license {
274274
Some(license) => license,
275275
None => {
276-
println!("dependency `{}` does not define a license expression", pkg.id,);
277-
*bad = true;
276+
tidy_error!(bad, "dependency `{}` does not define a license expression", pkg.id);
278277
continue;
279278
}
280279
};
@@ -286,8 +285,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
286285
// general, these should never be added.
287286
continue;
288287
}
289-
println!("invalid license `{}` in `{}`", license, pkg.id);
290-
*bad = true;
288+
tidy_error!(bad, "invalid license `{}` in `{}`", license, pkg.id);
291289
}
292290
}
293291
}
@@ -300,12 +298,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
300298
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.
301299
for name in PERMITTED_DEPENDENCIES {
302300
if !metadata.packages.iter().any(|p| p.name == *name) {
303-
println!(
301+
tidy_error!(
302+
bad,
304303
"could not find allowed package `{}`\n\
305304
Remove from PERMITTED_DEPENDENCIES list if it is no longer used.",
306305
name
307306
);
308-
*bad = true;
309307
}
310308
}
311309
// Get the list in a convenient form.
@@ -322,11 +320,10 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
322320
}
323321

324322
if !unapproved.is_empty() {
325-
println!("Dependencies not explicitly permitted:");
323+
tidy_error!(bad, "Dependencies not explicitly permitted:");
326324
for dep in unapproved {
327325
println!("* {}", dep);
328326
}
329-
*bad = true;
330327
}
331328
}
332329

@@ -381,16 +378,17 @@ fn check_crate_duplicate(metadata: &Metadata, bad: &mut bool) {
381378
let matches: Vec<_> = metadata.packages.iter().filter(|pkg| pkg.name == name).collect();
382379
match matches.len() {
383380
0 => {
384-
println!(
381+
tidy_error!(
382+
bad,
385383
"crate `{}` is missing, update `check_crate_duplicate` \
386384
if it is no longer used",
387385
name
388386
);
389-
*bad = true;
390387
}
391388
1 => {}
392389
_ => {
393-
println!(
390+
tidy_error!(
391+
bad,
394392
"crate `{}` is duplicated in `Cargo.lock`, \
395393
it is too expensive to build multiple times, \
396394
so make sure only one version appears across all dependencies",
@@ -399,7 +397,6 @@ fn check_crate_duplicate(metadata: &Metadata, bad: &mut bool) {
399397
for pkg in matches {
400398
println!(" * {}", pkg.id);
401399
}
402-
*bad = true;
403400
}
404401
}
405402
}

src/tools/tidy/src/extdeps.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn check(root: &Path, bad: &mut bool) {
2727

2828
// Ensure source is allowed.
2929
if !ALLOWED_SOURCES.contains(&&*source) {
30-
println!("invalid source: {}", source);
31-
*bad = true;
30+
tidy_error!(bad, "invalid source: {}", source);
3231
}
3332
}
3433
}

src/tools/tidy/src/features.rs

-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
330330
let issue_str = parts.next().unwrap().trim();
331331
let tracking_issue = if issue_str.starts_with("None") {
332332
if level == Status::Unstable && !next_feature_omits_tracking_issue {
333-
*bad = true;
334333
tidy_error!(
335334
bad,
336335
"{}:{}: no tracking issue for feature {}",

src/tools/tidy/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ macro_rules! t {
2828
}
2929

3030
macro_rules! tidy_error {
31+
($bad:expr, $fmt:expr) => ({
32+
*$bad = true;
33+
eprintln!("tidy error: {}", $fmt);
34+
});
3135
($bad:expr, $fmt:expr, $($arg:tt)*) => ({
3236
*$bad = true;
3337
eprint!("tidy error: ");

src/tools/tidy/src/ui_tests.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ pub fn check(path: &Path, bad: &mut bool) {
6767
let testname =
6868
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
6969
if !file_path.with_file_name(testname).with_extension("rs").exists() {
70-
println!("Stray file with UI testing output: {:?}", file_path);
71-
*bad = true;
70+
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
7271
}
7372

7473
if let Ok(metadata) = fs::metadata(file_path) {
7574
if metadata.len() == 0 {
76-
println!("Empty file with UI testing output: {:?}", file_path);
77-
*bad = true;
75+
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
7876
}
7977
}
8078
}

0 commit comments

Comments
 (0)