3
3
//! This library contains the tidy lints and exposes it
4
4
//! to be used by tools.
5
5
6
+ use std:: fmt:: Display ;
7
+
8
+ use termcolor:: WriteColor ;
9
+
6
10
/// A helper macro to `unwrap` a result except also print out details like:
7
11
///
8
12
/// * The expression that failed
@@ -26,18 +30,27 @@ macro_rules! t {
26
30
}
27
31
28
32
macro_rules! tidy_error {
29
- ( $bad: expr, $fmt: expr) => ( {
30
- * $bad = true ;
31
- eprint!( "tidy error: " ) ;
32
- eprintln!( $fmt) ;
33
- } ) ;
34
- ( $bad: expr, $fmt: expr, $( $arg: tt) * ) => ( {
35
- * $bad = true ;
36
- eprint!( "tidy error: " ) ;
37
- eprintln!( $fmt, $( $arg) * ) ;
33
+ ( $bad: expr, $( $fmt: tt) * ) => ( {
34
+ $crate:: tidy_error( $bad, format_args!( $( $fmt) * ) ) . expect( "failed to output error" ) ;
38
35
} ) ;
39
36
}
40
37
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
+
41
54
pub mod alphabetical;
42
55
pub mod bins;
43
56
pub mod debug_artifacts;
0 commit comments