Skip to content

Commit 445be5b

Browse files
authored
Unrolled build for #143960
Rollup merge of #143960 - hkBst:tidy-cleanup-2, r=Mark-Simulacrum Tidy cleanup 2
2 parents 0d95920 + 32391f7 commit 445be5b

File tree

10 files changed

+114
-115
lines changed

10 files changed

+114
-115
lines changed

src/tools/tidy/src/features.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,9 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
331331
continue;
332332
}
333333

334-
if in_feature_group {
335-
if let Some(doc_comment) = line.strip_prefix("///") {
336-
doc_comments.push(doc_comment.trim().to_string());
337-
continue;
338-
}
334+
if in_feature_group && let Some(doc_comment) = line.strip_prefix("///") {
335+
doc_comments.push(doc_comment.trim().to_string());
336+
continue;
339337
}
340338

341339
let mut parts = line.split(',');
@@ -465,19 +463,20 @@ fn get_and_check_lib_features(
465463
map_lib_features(base_src_path, &mut |res, file, line| match res {
466464
Ok((name, f)) => {
467465
let mut check_features = |f: &Feature, list: &Features, display: &str| {
468-
if let Some(s) = list.get(name) {
469-
if f.tracking_issue != s.tracking_issue && f.level != Status::Accepted {
470-
tidy_error!(
471-
bad,
472-
"{}:{}: feature gate {} has inconsistent `issue`: \"{}\" mismatches the {} `issue` of \"{}\"",
473-
file.display(),
474-
line,
475-
name,
476-
f.tracking_issue_display(),
477-
display,
478-
s.tracking_issue_display(),
479-
);
480-
}
466+
if let Some(s) = list.get(name)
467+
&& f.tracking_issue != s.tracking_issue
468+
&& f.level != Status::Accepted
469+
{
470+
tidy_error!(
471+
bad,
472+
"{}:{}: feature gate {} has inconsistent `issue`: \"{}\" mismatches the {} `issue` of \"{}\"",
473+
file.display(),
474+
line,
475+
name,
476+
f.tracking_issue_display(),
477+
display,
478+
s.tracking_issue_display(),
479+
);
481480
}
482481
};
483482
check_features(&f, lang_features, "corresponding lang feature");

src/tools/tidy/src/fluent_period.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ fn check_period(filename: &str, contents: &str, bad: &mut bool) {
3333
continue;
3434
}
3535

36-
if let Some(pat) = &m.value {
37-
if let Some(PatternElement::TextElement { value }) = pat.elements.last() {
38-
// We don't care about ellipses.
39-
if value.ends_with(".") && !value.ends_with("...") {
40-
let ll = find_line(contents, value);
41-
let name = m.id.name;
42-
tidy_error!(bad, "{filename}:{ll}: message `{name}` ends in a period");
43-
}
36+
if let Some(pat) = &m.value
37+
&& let Some(PatternElement::TextElement { value }) = pat.elements.last()
38+
{
39+
// We don't care about ellipses.
40+
if value.ends_with(".") && !value.ends_with("...") {
41+
let ll = find_line(contents, value);
42+
let name = m.id.name;
43+
tidy_error!(bad, "{filename}:{ll}: message `{name}` ends in a period");
4444
}
4545
}
4646

@@ -50,12 +50,13 @@ fn check_period(filename: &str, contents: &str, bad: &mut bool) {
5050
continue;
5151
}
5252

53-
if let Some(PatternElement::TextElement { value }) = attr.value.elements.last() {
54-
if value.ends_with(".") && !value.ends_with("...") {
55-
let ll = find_line(contents, value);
56-
let name = attr.id.name;
57-
tidy_error!(bad, "{filename}:{ll}: attr `{name}` ends in a period");
58-
}
53+
if let Some(PatternElement::TextElement { value }) = attr.value.elements.last()
54+
&& value.ends_with(".")
55+
&& !value.ends_with("...")
56+
{
57+
let ll = find_line(contents, value);
58+
let name = attr.id.name;
59+
tidy_error!(bad, "{filename}:{ll}: attr `{name}` ends in a period");
5960
}
6061
}
6162
}

src/tools/tidy/src/fluent_used.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn filter_used_messages(
1212
) {
1313
// we don't just check messages never appear in Rust files,
1414
// because messages can be used as parts of other fluent messages in Fluent files,
15-
// so we do checking messages appear only once in all Rust and Fluent files.
15+
// so we check messages appear only once in all Rust and Fluent files.
1616
let matches = static_regex!(r"\w+").find_iter(contents);
1717
for name in matches {
1818
if let Some((name, filename)) = msgs_not_appeared_yet.remove_entry(name.as_str()) {

src/tools/tidy/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use termcolor::WriteColor;
1313

1414
macro_rules! static_regex {
1515
($re:literal) => {{
16-
static RE: ::std::sync::OnceLock<::regex::Regex> = ::std::sync::OnceLock::new();
17-
RE.get_or_init(|| ::regex::Regex::new($re).unwrap())
16+
static RE: ::std::sync::LazyLock<::regex::Regex> =
17+
::std::sync::LazyLock::new(|| ::regex::Regex::new($re).unwrap());
18+
&*RE
1819
}};
1920
}
2021

@@ -134,7 +135,7 @@ pub fn files_modified(ci_info: &CiInfo, pred: impl Fn(&str) -> bool) -> bool {
134135
eprintln!("No base commit, assuming all files are modified");
135136
return true;
136137
};
137-
match crate::git_diff(&base_commit, "--name-status") {
138+
match crate::git_diff(base_commit, "--name-status") {
138139
Some(output) => {
139140
let modified_files = output.lines().filter_map(|ln| {
140141
let (status, name) = ln

src/tools/tidy/src/mir_opt_tests.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,21 @@ fn check_dash_files(path: &Path, bless: bool, bad: &mut bool) {
5555
.filter(|e| e.file_type().is_file())
5656
{
5757
let path = file.path();
58-
if path.extension() == Some("rs".as_ref()) {
59-
if let Some(name) = path.file_name().and_then(|s| s.to_str()) {
60-
if name.contains('-') {
61-
if !bless {
62-
tidy_error!(
63-
bad,
64-
"mir-opt test files should not have dashes in them: {}",
65-
path.display()
66-
);
67-
} else {
68-
let new_name = name.replace('-', "_");
69-
let mut new_path = path.to_owned();
70-
new_path.set_file_name(new_name);
71-
let _ = std::fs::rename(path, new_path);
72-
}
73-
}
58+
if path.extension() == Some("rs".as_ref())
59+
&& let Some(name) = path.file_name().and_then(|s| s.to_str())
60+
&& name.contains('-')
61+
{
62+
if !bless {
63+
tidy_error!(
64+
bad,
65+
"mir-opt test files should not have dashes in them: {}",
66+
path.display()
67+
);
68+
} else {
69+
let new_name = name.replace('-', "_");
70+
let mut new_path = path.to_owned();
71+
new_path.set_file_name(new_name);
72+
let _ = std::fs::rename(path, new_path);
7473
}
7574
}
7675
}

src/tools/tidy/src/rustdoc_templates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn check(librustdoc_path: &Path, bad: &mut bool) {
2626
None
2727
// Then we check if this a comment tag.
2828
} else if *tag != "{#" {
29-
return Some(false);
29+
Some(false)
3030
// And finally we check if the comment is empty (ie, only there to strip
3131
// extra whitespace characters).
3232
} else if let Some(start_pos) = line.rfind(tag) {

src/tools/tidy/src/style.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ pub fn check(path: &Path, bad: &mut bool) {
417417
return;
418418
}
419419
// Shell completions are automatically generated
420-
if let Some(p) = file.parent() {
421-
if p.ends_with(Path::new("src/etc/completions")) {
422-
return;
423-
}
420+
if let Some(p) = file.parent()
421+
&& p.ends_with(Path::new("src/etc/completions"))
422+
{
423+
return;
424424
}
425425
let [
426426
mut skip_cr,
@@ -604,25 +604,25 @@ pub fn check(path: &Path, bad: &mut bool) {
604604
backtick_count += comment_text.chars().filter(|ch| *ch == '`').count();
605605
}
606606
comment_block = Some((start_line, backtick_count));
607-
} else if let Some((start_line, backtick_count)) = comment_block.take() {
608-
if backtick_count % 2 == 1 {
609-
let mut err = |msg: &str| {
610-
tidy_error!(bad, "{}:{start_line}: {msg}", file.display());
611-
};
612-
let block_len = (i + 1) - start_line;
613-
if block_len == 1 {
614-
suppressible_tidy_err!(
615-
err,
616-
skip_odd_backticks,
617-
"comment with odd number of backticks"
618-
);
619-
} else {
620-
suppressible_tidy_err!(
621-
err,
622-
skip_odd_backticks,
623-
"{block_len}-line comment block with odd number of backticks"
624-
);
625-
}
607+
} else if let Some((start_line, backtick_count)) = comment_block.take()
608+
&& backtick_count % 2 == 1
609+
{
610+
let mut err = |msg: &str| {
611+
tidy_error!(bad, "{}:{start_line}: {msg}", file.display());
612+
};
613+
let block_len = (i + 1) - start_line;
614+
if block_len == 1 {
615+
suppressible_tidy_err!(
616+
err,
617+
skip_odd_backticks,
618+
"comment with odd number of backticks"
619+
);
620+
} else {
621+
suppressible_tidy_err!(
622+
err,
623+
skip_odd_backticks,
624+
"{block_len}-line comment block with odd number of backticks"
625+
);
626626
}
627627
}
628628
}

src/tools/tidy/src/target_specific_tests.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
3030
comp_vec.push(component);
3131
}
3232
}
33-
} else if let Some(compile_flags) = directive.strip_prefix(COMPILE_FLAGS_HEADER) {
34-
if let Some((_, v)) = compile_flags.split_once("--target") {
35-
let v = v.trim_start_matches([' ', '=']);
36-
let v = if v == "{{target}}" { Some((v, v)) } else { v.split_once("-") };
37-
if let Some((arch, _)) = v {
38-
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
39-
info.target_arch.replace(arch);
40-
} else {
41-
eprintln!("{file}: seems to have a malformed --target value");
42-
*bad = true;
43-
}
33+
} else if let Some(compile_flags) = directive.strip_prefix(COMPILE_FLAGS_HEADER)
34+
&& let Some((_, v)) = compile_flags.split_once("--target")
35+
{
36+
let v = v.trim_start_matches([' ', '=']);
37+
let v = if v == "{{target}}" { Some((v, v)) } else { v.split_once("-") };
38+
if let Some((arch, _)) = v {
39+
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
40+
info.target_arch.replace(arch);
41+
} else {
42+
eprintln!("{file}: seems to have a malformed --target value");
43+
*bad = true;
4444
}
4545
}
4646
});

src/tools/tidy/src/ui_tests.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,31 +161,30 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) {
161161
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
162162
}
163163

164-
if let Ok(metadata) = fs::metadata(file_path) {
165-
if metadata.len() == 0 {
166-
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
167-
}
164+
if let Ok(metadata) = fs::metadata(file_path)
165+
&& metadata.len() == 0
166+
{
167+
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
168168
}
169169
}
170170

171-
if ext == "rs" {
172-
if let Some(test_name) = static_regex!(r"^issues?[-_]?(\d{3,})").captures(testname)
173-
{
174-
// these paths are always relative to the passed `path` and always UTF8
175-
let stripped_path = file_path
176-
.strip_prefix(path)
177-
.unwrap()
178-
.to_str()
179-
.unwrap()
180-
.replace(std::path::MAIN_SEPARATOR_STR, "/");
181-
182-
if !remaining_issue_names.remove(stripped_path.as_str()) {
183-
tidy_error!(
184-
bad,
185-
"file `tests/{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`",
186-
issue_n = &test_name[1],
187-
);
188-
}
171+
if ext == "rs"
172+
&& let Some(test_name) = static_regex!(r"^issues?[-_]?(\d{3,})").captures(testname)
173+
{
174+
// these paths are always relative to the passed `path` and always UTF8
175+
let stripped_path = file_path
176+
.strip_prefix(path)
177+
.unwrap()
178+
.to_str()
179+
.unwrap()
180+
.replace(std::path::MAIN_SEPARATOR_STR, "/");
181+
182+
if !remaining_issue_names.remove(stripped_path.as_str()) {
183+
tidy_error!(
184+
bad,
185+
"file `tests/{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`",
186+
issue_n = &test_name[1],
187+
);
189188
}
190189
}
191190
}

src/tools/tidy/src/x_version.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
2525
if let Some(version) = iter.next() {
2626
// Check this is the rust-lang/rust x tool installation since it should be
2727
// installed at a path containing `src/tools/x`.
28-
if let Some(path) = iter.next() {
29-
if path.contains("src/tools/x") {
30-
let version = version.strip_prefix("v").unwrap();
31-
installed = Some(Version::parse(version).unwrap());
32-
break;
33-
}
28+
if let Some(path) = iter.next()
29+
&& path.contains("src/tools/x")
30+
{
31+
let version = version.strip_prefix("v").unwrap();
32+
installed = Some(Version::parse(version).unwrap());
33+
break;
3434
};
3535
}
3636
} else {

0 commit comments

Comments
 (0)