Skip to content

Commit f789d89

Browse files
committed
Print tidy errors to stderr, prefix with 'tidy error: ', handle 'bad' state.
1 parent bd698b9 commit f789d89

File tree

8 files changed

+34
-37
lines changed

8 files changed

+34
-37
lines changed

src/tools/tidy/src/bins.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ pub fn check(path: &Path, bad: &mut bool) {
6262
});
6363
let path_bytes = rel_path.as_os_str().as_bytes();
6464
if output.status.success() && output.stdout.starts_with(path_bytes) {
65-
println!("binary checked into source: {}", file.display());
66-
*bad = true;
65+
tidy_error!(bad, "binary checked into source: {}", file.display());
6766
}
6867
}
6968
})

src/tools/tidy/src/cargo.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
100100
}
101101

102102
if !librs.contains(&format!("extern crate {}", krate)) {
103-
println!("{} doesn't have `extern crate {}`, but Cargo.toml \
104-
depends on it", libfile.display(), krate);
105-
*bad = true;
103+
tidy_error!(bad, "{} doesn't have `extern crate {}`, but Cargo.toml \
104+
depends on it", libfile.display(), krate);
106105
}
107106
}
108107
}

src/tools/tidy/src/errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ pub fn check(path: &Path, bad: &mut bool) {
7979
continue
8080
}
8181

82-
println!("duplicate error code: {}", code);
82+
tidy_error!(bad, "duplicate error code: {}", code);
8383
for &(ref file, line_num, ref line) in entries.iter() {
84-
println!("{}:{}: {}", file.display(), line_num, line);
84+
tidy_error!(bad, "{}:{}: {}", file.display(), line_num, line);
8585
}
86-
*bad = true;
8786
}
8887

8988
if !*bad {

src/tools/tidy/src/features.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ pub fn check(path: &Path, bad: &mut bool) {
7777

7878
for (i, line) in contents.lines().enumerate() {
7979
let mut err = |msg: &str| {
80-
println!("{}:{}: {}", file.display(), i + 1, msg);
81-
*bad = true;
80+
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
8281
};
8382

8483
let gate_test_str = "gate-test-";
@@ -126,8 +125,7 @@ pub fn check(path: &Path, bad: &mut bool) {
126125
}
127126

128127
if gate_untested.len() > 0 {
129-
println!("Found {} features without a gate test.", gate_untested.len());
130-
*bad = true;
128+
tidy_error!(bad, "Found {} features without a gate test.", gate_untested.len());
131129
}
132130

133131
if *bad {
@@ -221,8 +219,7 @@ pub fn collect_lib_features(base_src_path: &Path,
221219

222220
for (i, line) in contents.lines().enumerate() {
223221
let mut err = |msg: &str| {
224-
println!("{}:{}: {}", file.display(), i + 1, msg);
225-
*bad = true;
222+
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
226223
};
227224
let level = if line.contains("[unstable(") {
228225
Status::Unstable

src/tools/tidy/src/main.rs

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ macro_rules! t {
3434
})
3535
}
3636

37+
macro_rules! tidy_error {
38+
($bad:expr, $fmt:expr, $($arg:tt)*) => ({
39+
use std::io::Write;
40+
*$bad = true;
41+
write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr");
42+
writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr");
43+
});
44+
}
45+
3746
mod bins;
3847
mod style;
3948
mod errors;

src/tools/tidy/src/pal.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ fn check_cfgs(contents: &mut String, file: &Path,
126126
Ok(_) => unreachable!(),
127127
Err(i) => i + 1
128128
};
129-
println!("{}:{}: platform-specific cfg: {}", file.display(), line, cfg);
130-
*bad = true;
129+
tidy_error!(bad, "{}:{}: platform-specific cfg: {}", file.display(), line, cfg);
131130
};
132131

133132
for (idx, cfg) in cfgs.into_iter() {

src/tools/tidy/src/style.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ pub fn check(path: &Path, bad: &mut bool) {
112112
let skip_length = contents.contains("ignore-tidy-linelength");
113113
for (i, line) in contents.split("\n").enumerate() {
114114
let mut err = |msg: &str| {
115-
println!("{}:{}: {}", file.display(), i + 1, msg);
116-
*bad = true;
115+
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
117116
};
118117
if !skip_length && line.chars().count() > COLS
119118
&& !long_line_is_ok(line) {
@@ -138,8 +137,7 @@ pub fn check(path: &Path, bad: &mut bool) {
138137
}
139138
}
140139
if !licenseck(file, &contents) {
141-
println!("{}: incorrect license", file.display());
142-
*bad = true;
140+
tidy_error!(bad, "{}: incorrect license", file.display());
143141
}
144142
})
145143
}

src/tools/tidy/src/unstable_book.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use std::collections::HashSet;
1212
use std::fs;
13-
use std::io::{self, BufRead, Write};
13+
use std::io::{self, BufRead};
1414
use std::path;
1515
use features::{collect_lang_features, collect_lib_features, Status};
1616

@@ -110,29 +110,26 @@ pub fn check(path: &path::Path, bad: &mut bool) {
110110

111111
// Check for Unstable Book section names with no corresponding SUMMARY.md link
112112
for feature_name in &unstable_book_section_file_names - &unstable_book_links {
113-
*bad = true;
114-
writeln!(io::stderr(),
115-
"The Unstable Book section '{}' needs to have a link in SUMMARY.md",
116-
feature_name)
117-
.expect("could not write to stderr")
113+
tidy_error!(
114+
bad,
115+
"The Unstable Book section '{}' needs to have a link in SUMMARY.md",
116+
feature_name);
118117
}
119118

120119
// Check for unstable features that don't have Unstable Book sections
121120
for feature_name in &unstable_feature_names - &unstable_book_section_file_names {
122-
*bad = true;
123-
writeln!(io::stderr(),
124-
"Unstable feature '{}' needs to have a section in The Unstable Book",
125-
feature_name)
126-
.expect("could not write to stderr")
121+
tidy_error!(
122+
bad,
123+
"Unstable feature '{}' needs to have a section in The Unstable Book",
124+
feature_name);
127125
}
128126

129127
// Check for Unstable Book sections that don't have a corresponding unstable feature
130128
for feature_name in &unstable_book_section_file_names - &unstable_feature_names {
131-
*bad = true;
132-
writeln!(io::stderr(),
133-
"The Unstable Book has a section '{}' which doesn't correspond \
134-
to an unstable feature",
135-
feature_name)
136-
.expect("could not write to stderr")
129+
tidy_error!(
130+
bad,
131+
"The Unstable Book has a section '{}' which doesn't correspond \
132+
to an unstable feature",
133+
feature_name)
137134
}
138135
}

0 commit comments

Comments
 (0)