1 //! Library used by tidy and other tools.
3 //! This library contains the tidy lints and exposes it
4 //! to be used by tools.
8 use walkdir::{DirEntry, WalkDir};
13 ($e:expr, $p:expr) => {
16 Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
23 Err(e) => panic!("{} failed with {}", stringify!($e), e),
28 macro_rules! tidy_error {
29 ($bad:expr, $fmt:expr) => ({
31 eprint!("tidy error: ");
34 ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
36 eprint!("tidy error: ");
37 eprintln!($fmt, $($arg)*);
42 pub mod debug_artifacts;
45 pub mod error_codes_check;
50 pub mod primitive_docs;
52 pub mod target_specific_tests;
55 pub mod unstable_book;
57 fn filter_dirs(path: &Path) -> bool {
60 "compiler/rustc_codegen_cranelift",
61 "compiler/rustc_codegen_gcc",
64 "library/portable-simd",
70 "src/tools/rust-analyzer",
71 "src/tools/rust-installer",
74 // Filter RLS output directories
77 skip.iter().any(|p| path.ends_with(p))
82 skip: &mut dyn FnMut(&Path) -> bool,
83 f: &mut dyn FnMut(&DirEntry, &str),
90 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
91 let mut contents = String::new();
92 walk_no_read(path, skip, &mut |entry| {
94 if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
101 fn walk_no_read(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry)) {
102 let walker = WalkDir::new(path).into_iter().filter_entry(|e| !skip(e.path()));
103 for entry in walker {
104 if let Ok(entry) = entry {
105 if entry.file_type().is_dir() {