]>
Commit | Line | Data |
---|---|---|
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 |
6 | use std::fmt::Display; |
7 | ||
8 | use 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 | 16 | macro_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 | ||
32 | macro_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 |
38 | fn 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 | 54 | pub mod alphabetical; |
041b39d2 | 55 | pub mod bins; |
e74abb32 | 56 | pub mod debug_artifacts; |
dfeec247 XL |
57 | pub mod deps; |
58 | pub mod edition; | |
9c376795 | 59 | pub mod error_codes; |
add651ee | 60 | pub mod ext_tool_checks; |
dfeec247 | 61 | pub mod extdeps; |
041b39d2 | 62 | pub mod features; |
49aad941 | 63 | pub mod fluent_alphabetical; |
487cf647 | 64 | pub mod mir_opt_tests; |
041b39d2 | 65 | pub mod pal; |
781aab86 | 66 | pub mod rustdoc_css_themes; |
9c376795 | 67 | pub mod rustdoc_gui_tests; |
dfeec247 | 68 | pub mod style; |
136023e0 | 69 | pub mod target_specific_tests; |
9c376795 | 70 | pub mod tests_placement; |
0531ce1d | 71 | pub mod ui_tests; |
416331ca | 72 | pub mod unit_tests; |
041b39d2 | 73 | pub mod unstable_book; |
f2b60f7d | 74 | pub mod walk; |
9c376795 | 75 | pub mod x_version; |