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 termcolor::WriteColor;
10 /// A helper macro to `unwrap` a result except also print out details like:
12 /// * The expression that failed
13 /// * The error itself
14 /// * (optionally) a path connected to the error (e.g. failure to open a file)
17 ($e:expr, $p:expr) => {
20 Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
27 Err(e) => panic!("{} failed with {}", stringify!($e), e),
32 macro_rules! tidy_error {
33 ($bad:expr, $($fmt:tt)*) => ({
34 $crate::tidy_error($bad, format_args!($($fmt)*)).expect("failed to output error");
38 fn tidy_error(bad: &mut bool, args: impl Display) -> std::io::Result<()> {
40 use termcolor::{Color, ColorChoice, ColorSpec, StandardStream};
44 let mut stderr = StandardStream::stdout(ColorChoice::Auto);
45 stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
47 write!(&mut stderr, "tidy error")?;
48 stderr.set_color(&ColorSpec::new())?;
50 writeln!(&mut stderr, ": {args}")?;
56 pub mod debug_artifacts;
62 pub mod mir_opt_tests;
64 pub mod primitive_docs;
66 pub mod target_specific_tests;
69 pub mod unstable_book;