Skip to content

Commit d12f1a7

Browse files
committed
tidy: apply considerable clippy suggestions
Signed-off-by: onur-ozkan <[email protected]>
1 parent a31b1b2 commit d12f1a7

File tree

8 files changed

+52
-58
lines changed

8 files changed

+52
-58
lines changed

Diff for: src/tools/tidy/src/alphabetical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn check_section<'a>(
8888
let trimmed_line = line.trim_start_matches(' ');
8989

9090
if trimmed_line.starts_with("//")
91-
|| (trimmed_line.starts_with("#") && !trimmed_line.starts_with("#!"))
91+
|| (trimmed_line.starts_with('#') && !trimmed_line.starts_with("#!"))
9292
|| trimmed_line.starts_with(is_close_bracket)
9393
{
9494
continue;

Diff for: src/tools/tidy/src/bins.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mod os_impl {
6161
fs::remove_file(&path).expect("Deleted temp file");
6262
// If the file is executable, then we assume that this
6363
// filesystem does not track executability, so skip this check.
64-
return if exec { Unsupported } else { Supported };
64+
if exec { Unsupported } else { Supported }
6565
}
6666
Err(e) => {
6767
// If the directory is read-only or we otherwise don't have rights,
@@ -76,7 +76,7 @@ mod os_impl {
7676

7777
panic!("unable to create temporary file `{:?}`: {:?}", path, e);
7878
}
79-
};
79+
}
8080
}
8181

8282
for &source_dir in sources {
@@ -92,7 +92,7 @@ mod os_impl {
9292
}
9393
}
9494

95-
return true;
95+
true
9696
}
9797

9898
// FIXME: check when rust-installer test sh files will be removed,

Diff for: src/tools/tidy/src/deps.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,9 @@ fn check_permitted_dependencies(
699699
for dep in deps {
700700
let dep = pkg_from_id(metadata, dep);
701701
// If this path is in-tree, we don't require it to be explicitly permitted.
702-
if dep.source.is_some() {
703-
if !permitted_dependencies.contains(dep.name.as_str()) {
704-
tidy_error!(bad, "Dependency for {descr} not explicitly permitted: {}", dep.id);
705-
has_permitted_dep_error = true;
706-
}
702+
if dep.source.is_some() && !permitted_dependencies.contains(dep.name.as_str()) {
703+
tidy_error!(bad, "Dependency for {descr} not explicitly permitted: {}", dep.id);
704+
has_permitted_dep_error = true;
707705
}
708706
}
709707

Diff for: src/tools/tidy/src/error_codes.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,9 @@ fn check_error_codes_tests(
308308
for line in file.lines() {
309309
let s = line.trim();
310310
// Assuming the line starts with `error[E`, we can substring the error code out.
311-
if s.starts_with("error[E") {
312-
if &s[6..11] == code {
313-
found_code = true;
314-
break;
315-
}
311+
if s.starts_with("error[E") && &s[6..11] == code {
312+
found_code = true;
313+
break;
316314
};
317315
}
318316

Diff for: src/tools/tidy/src/ext_tool_checks.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ fn check_impl(
7878
let mut py_path = None;
7979

8080
let (cfg_args, file_args): (Vec<_>, Vec<_>) = pos_args
81-
.into_iter()
81+
.iter()
8282
.map(OsStr::new)
83-
.partition(|arg| arg.to_str().is_some_and(|s| s.starts_with("-")));
83+
.partition(|arg| arg.to_str().is_some_and(|s| s.starts_with('-')));
8484

8585
if python_lint || python_fmt {
8686
let venv_path = outdir.join("venv");
@@ -277,10 +277,11 @@ fn create_venv_at_path(path: &Path) -> Result<(), Error> {
277277

278278
let stderr = String::from_utf8_lossy(&out.stderr);
279279
let err = if stderr.contains("No module named virtualenv") {
280-
Error::Generic(format!(
280+
Error::Generic(
281281
"virtualenv not found: you may need to install it \
282282
(`python3 -m pip install venv`)"
283-
))
283+
.to_owned(),
284+
)
284285
} else {
285286
Error::Generic(format!(
286287
"failed to create venv at '{}' using {sys_py}: {stderr}",

Diff for: src/tools/tidy/src/style.rs

+29-28
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,13 @@ pub fn check(path: &Path, bad: &mut bool) {
463463
}
464464
}
465465
// for now we just check libcore
466-
if trimmed.contains("unsafe {") && !trimmed.starts_with("//") && !last_safety_comment {
467-
if file.components().any(|c| c.as_os_str() == "core") && !is_test {
468-
suppressible_tidy_err!(err, skip_undocumented_unsafe, "undocumented unsafe");
469-
}
466+
if trimmed.contains("unsafe {")
467+
&& !trimmed.starts_with("//")
468+
&& !last_safety_comment
469+
&& file.components().any(|c| c.as_os_str() == "core")
470+
&& !is_test
471+
{
472+
suppressible_tidy_err!(err, skip_undocumented_unsafe, "undocumented unsafe");
470473
}
471474
if trimmed.contains("// SAFETY:") {
472475
last_safety_comment = true;
@@ -487,10 +490,10 @@ pub fn check(path: &Path, bad: &mut bool) {
487490
"copyright notices attributed to the Rust Project Developers are deprecated"
488491
);
489492
}
490-
if !file.components().any(|c| c.as_os_str() == "rustc_baked_icu_data") {
491-
if is_unexplained_ignore(&extension, line) {
492-
err(UNEXPLAINED_IGNORE_DOCTEST_INFO);
493-
}
493+
if !file.components().any(|c| c.as_os_str() == "rustc_baked_icu_data")
494+
&& is_unexplained_ignore(&extension, line)
495+
{
496+
err(UNEXPLAINED_IGNORE_DOCTEST_INFO);
494497
}
495498

496499
if filename.ends_with(".cpp") && line.contains("llvm_unreachable") {
@@ -525,26 +528,24 @@ pub fn check(path: &Path, bad: &mut bool) {
525528
backtick_count += comment_text.chars().filter(|ch| *ch == '`').count();
526529
}
527530
comment_block = Some((start_line, backtick_count));
528-
} else {
529-
if let Some((start_line, backtick_count)) = comment_block.take() {
530-
if backtick_count % 2 == 1 {
531-
let mut err = |msg: &str| {
532-
tidy_error!(bad, "{}:{start_line}: {msg}", file.display());
533-
};
534-
let block_len = (i + 1) - start_line;
535-
if block_len == 1 {
536-
suppressible_tidy_err!(
537-
err,
538-
skip_odd_backticks,
539-
"comment with odd number of backticks"
540-
);
541-
} else {
542-
suppressible_tidy_err!(
543-
err,
544-
skip_odd_backticks,
545-
"{block_len}-line comment block with odd number of backticks"
546-
);
547-
}
531+
} else if let Some((start_line, backtick_count)) = comment_block.take() {
532+
if backtick_count % 2 == 1 {
533+
let mut err = |msg: &str| {
534+
tidy_error!(bad, "{}:{start_line}: {msg}", file.display());
535+
};
536+
let block_len = (i + 1) - start_line;
537+
if block_len == 1 {
538+
suppressible_tidy_err!(
539+
err,
540+
skip_odd_backticks,
541+
"comment with odd number of backticks"
542+
);
543+
} else {
544+
suppressible_tidy_err!(
545+
err,
546+
skip_odd_backticks,
547+
"{block_len}-line comment block with odd number of backticks"
548+
);
548549
}
549550
}
550551
}

Diff for: src/tools/tidy/src/walk.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ pub(crate) fn walk_no_read(
7979
let walker = walker.filter_entry(move |e| {
8080
!skip(e.path(), e.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
8181
});
82-
for entry in walker.build() {
83-
if let Ok(entry) = entry {
84-
if entry.file_type().map_or(true, |kind| kind.is_dir() || kind.is_symlink()) {
85-
continue;
86-
}
87-
f(&entry);
82+
for entry in walker.build().flatten() {
83+
if entry.file_type().map_or(true, |kind| kind.is_dir() || kind.is_symlink()) {
84+
continue;
8885
}
86+
f(&entry);
8987
}
9088
}
9189

@@ -97,11 +95,9 @@ pub(crate) fn walk_dir(
9795
) {
9896
let mut walker = ignore::WalkBuilder::new(path);
9997
let walker = walker.filter_entry(move |e| !skip(e.path()));
100-
for entry in walker.build() {
101-
if let Ok(entry) = entry {
102-
if entry.path().is_dir() {
103-
f(&entry);
104-
}
98+
for entry in walker.build().flatten() {
99+
if entry.path().is_dir() {
100+
f(&entry);
105101
}
106102
}
107103
}

Diff for: src/tools/tidy/src/x_version.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
5252
);
5353
}
5454
} else {
55-
return tidy_error!(bad, "failed to check version of `x`: {}", cargo_list.status);
55+
tidy_error!(bad, "failed to check version of `x`: {}", cargo_list.status)
5656
}
5757
}
5858

0 commit comments

Comments
 (0)