1 //! Library used by tidy and other tools.
3 //! This library contains the tidy lints and exposes it
4 //! to be used by tools.
6 use walkdir::{DirEntry, WalkDir};
13 ($e:expr, $p:expr) => (match $e {
15 Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
18 ($e:expr) => (match $e {
20 Err(e) => panic!("{} failed with {}", stringify!($e), e),
24 macro_rules! tidy_error {
25 ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
27 eprint!("tidy error: ");
28 eprintln!($fmt, $($arg)*);
41 pub mod unstable_book;
44 fn filter_dirs(path: &Path) -> bool {
48 "src/llvm-emscripten",
50 "src/librustc_data_structures/owning_ref",
56 "src/tools/rust-installer",
67 skip.iter().any(|p| path.ends_with(p))
72 paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)
79 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
80 let mut contents = String::new();
81 walk_no_read(path, skip, &mut |entry| {
83 if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
90 fn walk_no_read(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry)) {
91 let walker = WalkDir::new(path).into_iter()
92 .filter_entry(|e| !skip(e.path()));
94 if let Ok(entry) = entry {
95 if entry.file_type().is_dir() {