// option. This file may not be copied, modified, or distributed
// except according to those terms.
-#![feature(tool_attributes)]
#![feature(decl_macro)]
#![allow(unused_attributes)]
#![feature(type_ascription)]
use comment::LineClasses;
use failure::Fail;
-use formatting::{FileMap, FormatErrorMap, FormattingError, ReportedErrors, Summary};
+use formatting::{FormatErrorMap, FormattingError, ReportedErrors, SourceFile};
use issues::Issue;
use shape::Indent;
mod chains;
pub(crate) mod checkstyle;
mod closures;
-pub(crate) mod codemap;
mod comment;
pub(crate) mod config;
mod expr;
-pub(crate) mod filemap;
pub(crate) mod formatting;
mod imports;
mod issues;
mod rewrite;
pub(crate) mod rustfmt_diff;
mod shape;
+pub(crate) mod source_file;
+pub(crate) mod source_map;
mod spanned;
mod string;
#[cfg(test)]
fn track_errors(&self, new_errors: &[FormattingError]) {
let errs = &mut self.internal.borrow_mut().1;
+ if !new_errors.is_empty() {
+ errs.has_formatting_errors = true;
+ }
if errs.has_operational_errors && errs.has_check_errors {
return;
}
}
}
+ fn add_diff(&mut self) {
+ self.internal.borrow_mut().1.has_diff = true;
+ }
+
+ fn add_macro_format_failure(&mut self) {
+ self.internal.borrow_mut().1.has_macro_format_failure = true;
+ }
+
+ fn add_parsing_error(&mut self) {
+ self.internal.borrow_mut().1.has_parsing_errors = true;
+ }
+
fn warning_count(&self) -> usize {
self.internal
.borrow()
/// Whether any warnings or errors are present in the report.
pub fn has_warnings(&self) -> bool {
- self.warning_count() > 0
+ self.internal.borrow().1.has_formatting_errors
}
/// Print the report to a terminal using colours and potentially other
{
let mut session = Session::new(config, Some(&mut out));
let result = session.format(input);
- let formatting_error = session.summary.has_macro_formatting_failure()
+ let formatting_error = session.errors.has_macro_format_failure
|| session.out.as_ref().unwrap().is_empty() && !snippet.is_empty();
if formatting_error || result.is_err() {
return None;
pub struct Session<'b, T: Write + 'b> {
pub config: Config,
pub out: Option<&'b mut T>,
- pub summary: Summary,
- filemap: FileMap,
+ pub(crate) errors: ReportedErrors,
+ source_file: SourceFile,
}
impl<'b, T: Write + 'b> Session<'b, T> {
Session {
config,
out,
- summary: Summary::default(),
- filemap: FileMap::new(),
+ errors: ReportedErrors::default(),
+ source_file: SourceFile::new(),
}
}
mem::swap(&mut config, &mut self.config);
result
}
+
+ pub fn add_operational_error(&mut self) {
+ self.errors.has_operational_errors = true;
+ }
+
+ pub fn has_operational_errors(&self) -> bool {
+ self.errors.has_operational_errors
+ }
+
+ pub fn has_parsing_errors(&self) -> bool {
+ self.errors.has_parsing_errors
+ }
+
+ pub fn has_formatting_errors(&self) -> bool {
+ self.errors.has_formatting_errors
+ }
+
+ pub fn has_check_errors(&self) -> bool {
+ self.errors.has_check_errors
+ }
+
+ pub fn has_diff(&self) -> bool {
+ self.errors.has_diff
+ }
+
+ pub fn has_no_errors(&self) -> bool {
+ !(self.has_operational_errors()
+ || self.has_parsing_errors()
+ || self.has_formatting_errors()
+ || self.has_check_errors()
+ || self.has_diff())
+ || self.errors.has_macro_format_failure
+ }
}
impl<'b, T: Write + 'b> Drop for Session<'b, T> {
Input::Text(_) => true,
}
}
+
+ fn file_name(&self) -> FileName {
+ match *self {
+ Input::File(ref file) => FileName::Real(file.clone()),
+ Input::Text(..) => FileName::Stdin,
+ }
+ }
}
#[cfg(test)]