]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/lib.rs
Rollup merge of #60513 - chrisvittal:remove-borrowck-compare, r=matthewjasper
[rust.git] / src / tools / tidy / src / lib.rs
1 //! Library used by tidy and other tools.
2 //!
3 //! This library contains the tidy lints and exposes it
4 //! to be used by tools.
5
6 #![deny(rust_2018_idioms)]
7
8 extern crate regex;
9 extern crate serde_json;
10 #[macro_use]
11 extern crate serde_derive;
12
13 use std::fs;
14
15 use std::path::Path;
16
17 macro_rules! t {
18     ($e:expr, $p:expr) => (match $e {
19         Ok(e) => e,
20         Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
21     });
22
23     ($e:expr) => (match $e {
24         Ok(e) => e,
25         Err(e) => panic!("{} failed with {}", stringify!($e), e),
26     })
27 }
28
29 macro_rules! tidy_error {
30     ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
31         *$bad = true;
32         eprint!("tidy error: ");
33         eprintln!($fmt, $($arg)*);
34     });
35 }
36
37 pub mod bins;
38 pub mod style;
39 pub mod errors;
40 pub mod features;
41 pub mod cargo;
42 pub mod pal;
43 pub mod deps;
44 pub mod extdeps;
45 pub mod ui_tests;
46 pub mod unstable_book;
47 pub mod libcoretest;
48
49 fn filter_dirs(path: &Path) -> bool {
50     let skip = [
51         "src/llvm",
52         "src/llvm-project",
53         "src/llvm-emscripten",
54         "src/libbacktrace",
55         "src/librustc_data_structures/owning_ref",
56         "src/vendor",
57         "src/tools/cargo",
58         "src/tools/clang",
59         "src/tools/rls",
60         "src/tools/clippy",
61         "src/tools/rust-installer",
62         "src/tools/rustfmt",
63         "src/tools/miri",
64         "src/tools/lld",
65         "src/tools/lldb",
66         "src/target",
67         "src/stdsimd",
68         "src/rust-sgx",
69         "target",
70         "vendor",
71     ];
72     skip.iter().any(|p| path.ends_with(p))
73 }
74
75 fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
76     for path in paths {
77         walk(path, skip, f);
78     }
79 }
80
81 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
82     if let Ok(dir) = fs::read_dir(path) {
83         for entry in dir {
84             let entry = t!(entry);
85             let kind = t!(entry.file_type());
86             let path = entry.path();
87             if kind.is_dir() {
88                 if !skip(&path) {
89                     walk(&path, skip, f);
90                 }
91             } else {
92                 f(&path);
93             }
94         }
95     }
96 }