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 eprintln!("tidy error: {}", $fmt);
33 ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
35 eprint!("tidy error: ");
36 eprintln!($fmt, $($arg)*);
41 pub mod debug_artifacts;
44 pub mod error_codes_check;
49 pub mod primitive_docs;
51 pub mod target_specific_tests;
54 pub mod unstable_book;
56 fn filter_dirs(path: &Path) -> bool {
59 "compiler/rustc_codegen_cranelift",
60 "compiler/rustc_codegen_gcc",
68 "src/tools/rust-analyzer",
69 "src/tools/rust-installer",
72 // Filter RLS output directories
75 skip.iter().any(|p| path.ends_with(p))
80 skip: &mut dyn FnMut(&Path) -> bool,
81 f: &mut dyn FnMut(&DirEntry, &str),
88 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
89 let mut contents = String::new();
90 walk_no_read(path, skip, &mut |entry| {
92 if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
99 fn walk_no_read(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry)) {
100 let walker = WalkDir::new(path).into_iter().filter_entry(|e| !skip(e.path()));
101 for entry in walker {
102 if let Ok(entry) = entry {
103 if entry.file_type().is_dir() {