Skip to content

Commit c113a37

Browse files
Pass contents and DirEntry to walkers
1 parent 5c33c3e commit c113a37

File tree

8 files changed

+29
-12
lines changed

8 files changed

+29
-12
lines changed

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

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

2828
super::walk(path,
2929
&mut |path| super::filter_dirs(path) || path.ends_with("src/etc"),
30-
&mut |file| {
30+
&mut |entry, _contents| {
31+
let file = entry.path();
3132
let filename = file.file_name().unwrap().to_string_lossy();
3233
let extensions = [".py", ".sh"];
3334
if extensions.iter().any(|e| filename.ends_with(e)) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub fn check(path: &Path, bad: &mut bool) {
1313
let mut map: HashMap<_, Vec<_>> = HashMap::new();
1414
super::walk(path,
1515
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
16-
&mut |file| {
16+
&mut |entry, _contents| {
17+
let file = entry.path();
1718
let filename = file.file_name().unwrap().to_string_lossy();
1819
if filename != "error_codes.rs" {
1920
return

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
6464
&path.join("test/ui-fulldeps"),
6565
&path.join("test/compile-fail")],
6666
&mut |path| super::filter_dirs(path),
67-
&mut |file| {
67+
&mut |entry, _contents| {
68+
let file = entry.path();
6869
let filename = file.file_name().unwrap().to_string_lossy();
6970
if !filename.ends_with(".rs") || filename == "features.rs" ||
7071
filename == "diagnostic_list.rs" {
@@ -371,7 +372,8 @@ fn map_lib_features(base_src_path: &Path,
371372
let mut contents = String::new();
372373
super::walk(base_src_path,
373374
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
374-
&mut |file| {
375+
&mut |entry, _contents| {
376+
let file = entry.path();
375377
let filename = file.file_name().unwrap().to_string_lossy();
376378
if !filename.ends_with(".rs") || filename == "features.rs" ||
377379
filename == "diagnostic_list.rs" {

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
//! This library contains the tidy lints and exposes it
44
//! to be used by tools.
55
6-
use walkdir::WalkDir;
6+
use walkdir::{DirEntry, WalkDir};
7+
use std::fs::File;
8+
use std::io::Read;
79

810
use std::path::Path;
911

@@ -65,21 +67,28 @@ fn filter_dirs(path: &Path) -> bool {
6567
skip.iter().any(|p| path.ends_with(p))
6668
}
6769

68-
fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
70+
fn walk_many(
71+
paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)
72+
) {
6973
for path in paths {
7074
walk(path, skip, f);
7175
}
7276
}
7377

74-
fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
78+
fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
7579
let walker = WalkDir::new(path).into_iter()
7680
.filter_entry(|e| !skip(e.path()));
81+
let mut contents = String::new();
7782
for entry in walker {
7883
if let Ok(entry) = entry {
7984
if entry.file_type().is_dir() {
8085
continue;
8186
}
82-
f(&entry.path());
87+
contents.clear();
88+
if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
89+
contents.clear();
90+
}
91+
f(&entry, &contents);
8392
}
8493
}
8594
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pub fn check(path: &Path, bad: &mut bool) {
1111
super::walk(
1212
&libcore_path,
1313
&mut |subpath| t!(subpath.strip_prefix(&libcore_path)).starts_with("tests"),
14-
&mut |subpath| {
14+
&mut |entry, _contents| {
15+
let subpath = entry.path();
1516
if let Some("rs") = subpath.extension().and_then(|e| e.to_str()) {
1617
match read_to_string(subpath) {
1718
Ok(contents) => {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ pub fn check(path: &Path, bad: &mut bool) {
9191
// Sanity check that the complex parsing here works.
9292
let mut saw_target_arch = false;
9393
let mut saw_cfg_bang = false;
94-
super::walk(path, &mut super::filter_dirs, &mut |file| {
94+
super::walk(path, &mut super::filter_dirs, &mut |entry, _contents| {
95+
let file = entry.path();
9596
let filestr = file.to_string_lossy().replace("\\", "/");
9697
if !filestr.ends_with(".rs") { return }
9798

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ macro_rules! suppressible_tidy_err {
130130

131131
pub fn check(path: &Path, bad: &mut bool) {
132132
let mut contents = String::new();
133-
super::walk(path, &mut super::filter_dirs, &mut |file| {
133+
super::walk(path, &mut super::filter_dirs, &mut |entry, _contents| {
134+
let file = entry.path();
134135
let filename = file.file_name().unwrap().to_string_lossy();
135136
let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h"];
136137
if extensions.iter().all(|e| !filename.ends_with(e)) ||

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ pub fn check(path: &Path, bad: &mut bool) {
77
super::walk_many(
88
&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
99
&mut |_| false,
10-
&mut |file_path| {
10+
&mut |entry, _contents| {
11+
let file_path = entry.path();
1112
if let Some(ext) = file_path.extension() {
1213
if ext == "stderr" || ext == "stdout" {
1314
// Test output filenames have one of the formats:

0 commit comments

Comments
 (0)