]> git.proxmox.com Git - rustc.git/blame - src/tools/tidy/src/lib.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / tidy / src / lib.rs
CommitLineData
9fa01778 1//! Library used by tidy and other tools.
041b39d2
XL
2//!
3//! This library contains the tidy lints and exposes it
4//! to be used by tools.
5
9c376795
FG
6use std::fmt::Display;
7
8use termcolor::WriteColor;
9
f2b60f7d
FG
10/// A helper macro to `unwrap` a result except also print out details like:
11///
12/// * The expression that failed
13/// * The error itself
14/// * (optionally) a path connected to the error (e.g. failure to open a file)
15#[macro_export]
041b39d2 16macro_rules! t {
dfeec247
XL
17 ($e:expr, $p:expr) => {
18 match $e {
19 Ok(e) => e,
20 Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
21 }
22 };
041b39d2 23
dfeec247
XL
24 ($e:expr) => {
25 match $e {
26 Ok(e) => e,
27 Err(e) => panic!("{} failed with {}", stringify!($e), e),
28 }
29 };
041b39d2
XL
30}
31
32macro_rules! tidy_error {
9c376795
FG
33 ($bad:expr, $($fmt:tt)*) => ({
34 $crate::tidy_error($bad, format_args!($($fmt)*)).expect("failed to output error");
041b39d2
XL
35 });
36}
37
9c376795
FG
38fn tidy_error(bad: &mut bool, args: impl Display) -> std::io::Result<()> {
39 use std::io::Write;
40 use termcolor::{Color, ColorChoice, ColorSpec, StandardStream};
41
42 *bad = true;
43
44 let mut stderr = StandardStream::stdout(ColorChoice::Auto);
45 stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
46
47 write!(&mut stderr, "tidy error")?;
48 stderr.set_color(&ColorSpec::new())?;
49
50 writeln!(&mut stderr, ": {args}")?;
51 Ok(())
52}
53
2b03887a 54pub mod alphabetical;
041b39d2 55pub mod bins;
e74abb32 56pub mod debug_artifacts;
dfeec247
XL
57pub mod deps;
58pub mod edition;
9c376795 59pub mod error_codes;
add651ee 60pub mod ext_tool_checks;
dfeec247 61pub mod extdeps;
041b39d2 62pub mod features;
49aad941 63pub mod fluent_alphabetical;
487cf647 64pub mod mir_opt_tests;
041b39d2 65pub mod pal;
781aab86 66pub mod rustdoc_css_themes;
9c376795 67pub mod rustdoc_gui_tests;
dfeec247 68pub mod style;
136023e0 69pub mod target_specific_tests;
9c376795 70pub mod tests_placement;
0531ce1d 71pub mod ui_tests;
416331ca 72pub mod unit_tests;
041b39d2 73pub mod unstable_book;
f2b60f7d 74pub mod walk;
9c376795 75pub mod x_version;