Skip to main content

noirc_errors/
lib.rs

1#![forbid(unsafe_code)]
2#![warn(unused_crate_dependencies, unused_extern_crates)]
3
4pub mod call_stack;
5pub mod debug_info;
6mod position;
7pub mod reporter;
8pub use position::{Located, Location, Position, Span, Spanned};
9pub use reporter::{CustomDiagnostic, DiagnosticKind};
10use std::io::Write;
11
12/// Print the input to stdout, and exit gracefully if `SIGPIPE` is received.
13/// Rust ignores `SIGPIPE` by default, converting pipe errors into `ErrorKind::BrokenPipe`
14pub fn print_to_stdout(args: std::fmt::Arguments) {
15    let mut stdout = std::io::stdout();
16    if let Err(e) = stdout.write_fmt(args) {
17        if e.kind() == std::io::ErrorKind::BrokenPipe {
18            // Gracefully exit on broken pipe
19            std::process::exit(0);
20        } else {
21            panic!("Unexpected error: {e}");
22        }
23    }
24}
25
26/// Macro to print formatted output to stdout
27#[macro_export]
28macro_rules! print_to_stdout {
29    ($($arg:tt)*) => {
30        noirc_errors::print_to_stdout(format_args!($($arg)*))
31    };
32}
33
34#[macro_export]
35macro_rules! println_to_stdout {
36    ($($arg:tt)*) => {
37        noirc_errors::print_to_stdout(format_args!("{}\n", format!($($arg)*)))
38    };
39}