- should_emit_verbose(main_file != FileName::Stdin, config, || {
- println!("Formatting {}", path)
- });
- let filemap = parse_session
+ should_emit_verbose(!input_is_stdin, config, || println!("Formatting {}", path));
+ let is_root = path == main_file;
+ context.format_file(path, module, is_root)?;
+ }
+ timer = timer.done_formatting();
+
+ should_emit_verbose(!input_is_stdin, config, || {
+ println!(
+ "Spent {0:.3} secs in the parsing phase, and {1:.3} secs in the formatting phase",
+ timer.get_parse_time(),
+ timer.get_format_time(),
+ )
+ });
+
+ if context.report.has_warnings() {
+ context.summary.add_formatting_error();
+ }
+ {
+ let report_errs = &context.report.internal.borrow().1;
+ if report_errs.has_check_errors {
+ context.summary.add_check_error();
+ }
+ if report_errs.has_operational_errors {
+ context.summary.add_operational_error();
+ }
+ }
+
+ Ok((context.report, context.summary))
+}
+
+// Used for formatting files.
+#[derive(new)]
+struct FormatContext<'a, T: FormatHandler + 'a> {
+ krate: &'a ast::Crate,
+ report: FormatReport,
+ summary: Summary,
+ parse_session: ParseSess,
+ config: &'a Config,
+ handler: &'a mut T,
+}
+
+impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
+ // Formats a single file/module.
+ fn format_file(
+ &mut self,
+ path: FileName,
+ module: &ast::Mod,
+ is_root: bool,
+ ) -> Result<(), ErrorKind> {
+ let filemap = self
+ .parse_session