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",
63 "library/portable-simd",
69 "src/tools/rust-analyzer",
70 "src/tools/rust-installer",
73 // Filter RLS output directories
76 skip.iter().any(|p| path.ends_with(p))
81 skip: &mut dyn FnMut(&Path) -> bool,
82 f: &mut dyn FnMut(&DirEntry, &str),
89 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
90 let mut contents = String::new();
91 walk_no_read(path, skip, &mut |entry| {
93 if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
100 fn walk_no_read(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry)) {
101 let walker = WalkDir::new(path).into_iter().filter_entry(|e| !skip(e.path()));
102 for entry in walker {
103 if let Ok(entry) = entry {
104 if entry.file_type().is_dir() {