Skip to content

Commit 08300e1

Browse files
committed
tidy: apply considerable clippy suggestions
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 0da5e92 commit 08300e1

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
@@ -692,11 +692,9 @@ fn check_permitted_dependencies(
692692
for dep in deps {
693693
let dep = pkg_from_id(metadata, dep);
694694
// If this path is in-tree, we don't require it to be explicitly permitted.
695-
if dep.source.is_some() {
696-
if !permitted_dependencies.contains(dep.name.as_str()) {
697-
tidy_error!(bad, "Dependency for {descr} not explicitly permitted: {}", dep.id);
698-
has_permitted_dep_error = true;
699-
}
695+
if dep.source.is_some() && !permitted_dependencies.contains(dep.name.as_str()) {
696+
tidy_error!(bad, "Dependency for {descr} not explicitly permitted: {}", dep.id);
697+
has_permitted_dep_error = true;
700698
}
701699
}
702700

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");
@@ -275,10 +275,11 @@ fn create_venv_at_path(path: &Path) -> Result<(), Error> {
275275
return Ok(());
276276
}
277277
let err = if String::from_utf8_lossy(&out.stderr).contains("No module named virtualenv") {
278-
Error::Generic(format!(
278+
Error::Generic(
279279
"virtualenv not found: you may need to install it \
280280
(`python3 -m pip install venv`)"
281-
))
281+
.to_owned(),
282+
)
282283
} else {
283284
Error::Generic(format!("failed to create venv at '{}' using {sys_py}", path.display()))
284285
};

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

+29-28
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,13 @@ pub fn check(path: &Path, bad: &mut bool) {
461461
}
462462
}
463463
// for now we just check libcore
464-
if trimmed.contains("unsafe {") && !trimmed.starts_with("//") && !last_safety_comment {
465-
if file.components().any(|c| c.as_os_str() == "core") && !is_test {
466-
suppressible_tidy_err!(err, skip_undocumented_unsafe, "undocumented unsafe");
467-
}
464+
if trimmed.contains("unsafe {")
465+
&& !trimmed.starts_with("//")
466+
&& !last_safety_comment
467+
&& file.components().any(|c| c.as_os_str() == "core")
468+
&& !is_test
469+
{
470+
suppressible_tidy_err!(err, skip_undocumented_unsafe, "undocumented unsafe");
468471
}
469472
if trimmed.contains("// SAFETY:") {
470473
last_safety_comment = true;
@@ -485,10 +488,10 @@ pub fn check(path: &Path, bad: &mut bool) {
485488
"copyright notices attributed to the Rust Project Developers are deprecated"
486489
);
487490
}
488-
if !file.components().any(|c| c.as_os_str() == "rustc_baked_icu_data") {
489-
if is_unexplained_ignore(&extension, line) {
490-
err(UNEXPLAINED_IGNORE_DOCTEST_INFO);
491-
}
491+
if !file.components().any(|c| c.as_os_str() == "rustc_baked_icu_data")
492+
&& is_unexplained_ignore(&extension, line)
493+
{
494+
err(UNEXPLAINED_IGNORE_DOCTEST_INFO);
492495
}
493496

494497
if filename.ends_with(".cpp") && line.contains("llvm_unreachable") {
@@ -523,26 +526,24 @@ pub fn check(path: &Path, bad: &mut bool) {
523526
backtick_count += comment_text.chars().filter(|ch| *ch == '`').count();
524527
}
525528
comment_block = Some((start_line, backtick_count));
526-
} else {
527-
if let Some((start_line, backtick_count)) = comment_block.take() {
528-
if backtick_count % 2 == 1 {
529-
let mut err = |msg: &str| {
530-
tidy_error!(bad, "{}:{start_line}: {msg}", file.display());
531-
};
532-
let block_len = (i + 1) - start_line;
533-
if block_len == 1 {
534-
suppressible_tidy_err!(
535-
err,
536-
skip_odd_backticks,
537-
"comment with odd number of backticks"
538-
);
539-
} else {
540-
suppressible_tidy_err!(
541-
err,
542-
skip_odd_backticks,
543-
"{block_len}-line comment block with odd number of backticks"
544-
);
545-
}
529+
} else 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+
);
546547
}
547548
}
548549
}

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

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

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

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)