use std::default::Default;
use std::time::{Duration, Instant};
-#[must_use]
+/// A summary of a Rustfmt run.
#[derive(Debug, Default, Clone, Copy)]
pub struct Summary {
// Encountered e.g. an IO error.
// Code is valid, but it is impossible to format it properly.
has_formatting_errors: bool,
- // Formatted code differs from existing code (write-mode diff only).
+ // Code contains macro call that was unable to format.
+ pub(crate) has_macro_format_failure: bool,
+
+ // Failed a check, such as the license check or other opt-in checking.
+ has_check_errors: bool,
+
+ /// Formatted code differs from existing code (--check only).
pub has_diff: bool,
// Keeps track of time spent in parsing and formatting steps.
}
impl Summary {
- pub fn mark_parse_time(&mut self) {
+ pub(crate) fn mark_parse_time(&mut self) {
self.timer = self.timer.done_parsing();
}
- pub fn mark_format_time(&mut self) {
+ pub(crate) fn mark_format_time(&mut self) {
self.timer = self.timer.done_formatting();
}
/// Returns the time it took to parse the source files in nanoseconds.
- pub fn get_parse_time(&self) -> Option<Duration> {
+ pub(crate) fn get_parse_time(&self) -> Option<Duration> {
match self.timer {
Timer::DoneParsing(init, parse_time) | Timer::DoneFormatting(init, parse_time, _) => {
// This should never underflow since `Instant::now()` guarantees monotonicity.
/// Returns the time it took to go from the parsed AST to the formatted output. Parsing time is
/// not included.
- pub fn get_format_time(&self) -> Option<Duration> {
+ pub(crate) fn get_format_time(&self) -> Option<Duration> {
match self.timer {
Timer::DoneFormatting(_init, parse_time, format_time) => {
Some(format_time.duration_since(parse_time))
self.has_formatting_errors
}
+ pub fn has_check_errors(&self) -> bool {
+ self.has_check_errors
+ }
+
+ pub(crate) fn has_macro_formatting_failure(&self) -> bool {
+ self.has_macro_format_failure
+ }
+
pub fn add_operational_error(&mut self) {
self.has_operational_errors = true;
}
- pub fn add_parsing_error(&mut self) {
+ pub(crate) fn add_parsing_error(&mut self) {
self.has_parsing_errors = true;
}
- pub fn add_formatting_error(&mut self) {
+ pub(crate) fn add_formatting_error(&mut self) {
self.has_formatting_errors = true;
}
- pub fn add_diff(&mut self) {
+ pub(crate) fn add_check_error(&mut self) {
+ self.has_check_errors = true;
+ }
+
+ pub(crate) fn add_diff(&mut self) {
self.has_diff = true;
}
+ pub(crate) fn add_macro_foramt_failure(&mut self) {
+ self.has_macro_format_failure = true;
+ }
+
pub fn has_no_errors(&self) -> bool {
- !(self.has_operational_errors || self.has_parsing_errors || self.has_formatting_errors
+ !(self.has_operational_errors
+ || self.has_parsing_errors
+ || self.has_formatting_errors
|| self.has_diff)
}
+ /// Combine two summaries together.
pub fn add(&mut self, other: Summary) {
self.has_operational_errors |= other.has_operational_errors;
self.has_formatting_errors |= other.has_formatting_errors;
self.has_parsing_errors |= other.has_parsing_errors;
+ self.has_check_errors |= other.has_check_errors;
self.has_diff |= other.has_diff;
}
-
- pub fn print_exit_codes() {
- let exit_codes = r#"Exit Codes:
- 0 = No errors
- 1 = Encountered operational errors e.g. an IO error
- 2 = Failed to reformat code because of parsing errors
- 3 = Code is valid, but it is impossible to format it properly
- 4 = Formatted code differs from existing code (write-mode diff only)"#;
- println!("{}", exit_codes);
- }
}
#[derive(Clone, Copy, Debug)]