config: &Config,
handler: &mut T,
) -> Result<FormatReport, ErrorKind> {
- let mut timer = Timer::Initialized(Instant::now());
+ let mut timer = Timer::start();
let main_file = input.file_name();
let input_is_stdin = main_file == FileName::Stdin;
fn handle_formatted_file(
&mut self,
path: FileName,
- mut result: String,
+ result: String,
report: &mut FormatReport,
) -> Result<(), ErrorKind> {
if let Some(ref mut out) = self.out {
- match source_file::write_file(&mut result, &path, out, &self.config) {
+ match source_file::write_file(&result, &path, out, &self.config) {
Ok(b) if b => report.add_diff(),
Err(e) => {
// Create a new error with path_str to help users see which files failed
impl FormattingError {
pub(crate) fn from_span(
- span: &Span,
+ span: Span,
source_map: &SourceMap,
kind: ErrorKind,
) -> FormattingError {
kind,
is_string: false,
line_buffer: source_map
- .span_to_lines(*span)
+ .span_to_lines(span)
.ok()
.and_then(|fl| {
fl.file
.get_line(fl.lines[0].line_index)
.map(|l| l.into_owned())
- }).unwrap_or_else(|| String::new()),
+ }).unwrap_or_else(String::new),
}
}
#[derive(Clone, Copy, Debug)]
enum Timer {
+ Disabled,
Initialized(Instant),
DoneParsing(Instant, Instant),
DoneFormatting(Instant, Instant, Instant),
}
impl Timer {
+ fn start() -> Timer {
+ if cfg!(target_arch = "wasm32") {
+ Timer::Disabled
+ } else {
+ Timer::Initialized(Instant::now())
+ }
+ }
fn done_parsing(self) -> Self {
match self {
+ Timer::Disabled => Timer::Disabled,
Timer::Initialized(init_time) => Timer::DoneParsing(init_time, Instant::now()),
_ => panic!("Timer can only transition to DoneParsing from Initialized state"),
}
fn done_formatting(self) -> Self {
match self {
+ Timer::Disabled => Timer::Disabled,
Timer::DoneParsing(init_time, parse_time) => {
Timer::DoneFormatting(init_time, parse_time, Instant::now())
}
/// Returns the time it took to parse the source files in seconds.
fn get_parse_time(&self) -> f32 {
match *self {
+ Timer::Disabled => panic!("this platform cannot time execution"),
Timer::DoneParsing(init, parse_time) | Timer::DoneFormatting(init, parse_time, _) => {
// This should never underflow since `Instant::now()` guarantees monotonicity.
Self::duration_to_f32(parse_time.duration_since(init))
/// not included.
fn get_format_time(&self) -> f32 {
match *self {
+ Timer::Disabled => panic!("this platform cannot time execution"),
Timer::DoneFormatting(_init, parse_time, format_time) => {
Self::duration_to_f32(format_time.duration_since(parse_time))
}