@@ -64,7 +64,7 @@ fn format_project<T: FormatHandler>(
64
64
config : & Config ,
65
65
handler : & mut T ,
66
66
) -> Result < FormatReport , ErrorKind > {
67
- let mut timer = Timer :: Initialized ( Instant :: now ( ) ) ;
67
+ let mut timer = Timer :: start ( ) ;
68
68
69
69
let main_file = input. file_name ( ) ;
70
70
let input_is_stdin = main_file == FileName :: Stdin ;
@@ -344,21 +344,31 @@ pub(crate) struct ModifiedLines {
344
344
345
345
#[ derive( Clone , Copy , Debug ) ]
346
346
enum Timer {
347
+ Disabled ,
347
348
Initialized ( Instant ) ,
348
349
DoneParsing ( Instant , Instant ) ,
349
350
DoneFormatting ( Instant , Instant , Instant ) ,
350
351
}
351
352
352
353
impl Timer {
354
+ fn start ( ) -> Timer {
355
+ if cfg ! ( target_arch = "wasm32" ) {
356
+ Timer :: Disabled
357
+ } else {
358
+ Timer :: Initialized ( Instant :: now ( ) )
359
+ }
360
+ }
353
361
fn done_parsing ( self ) -> Self {
354
362
match self {
363
+ Timer :: Disabled => Timer :: Disabled ,
355
364
Timer :: Initialized ( init_time) => Timer :: DoneParsing ( init_time, Instant :: now ( ) ) ,
356
365
_ => panic ! ( "Timer can only transition to DoneParsing from Initialized state" ) ,
357
366
}
358
367
}
359
368
360
369
fn done_formatting ( self ) -> Self {
361
370
match self {
371
+ Timer :: Disabled => Timer :: Disabled ,
362
372
Timer :: DoneParsing ( init_time, parse_time) => {
363
373
Timer :: DoneFormatting ( init_time, parse_time, Instant :: now ( ) )
364
374
}
@@ -369,6 +379,7 @@ impl Timer {
369
379
/// Returns the time it took to parse the source files in seconds.
370
380
fn get_parse_time ( & self ) -> f32 {
371
381
match * self {
382
+ Timer :: Disabled => panic ! ( "this platform cannot time execution" ) ,
372
383
Timer :: DoneParsing ( init, parse_time) | Timer :: DoneFormatting ( init, parse_time, _) => {
373
384
// This should never underflow since `Instant::now()` guarantees monotonicity.
374
385
Self :: duration_to_f32 ( parse_time. duration_since ( init) )
@@ -381,6 +392,7 @@ impl Timer {
381
392
/// not included.
382
393
fn get_format_time ( & self ) -> f32 {
383
394
match * self {
395
+ Timer :: Disabled => panic ! ( "this platform cannot time execution" ) ,
384
396
Timer :: DoneFormatting ( _init, parse_time, format_time) => {
385
397
Self :: duration_to_f32 ( format_time. duration_since ( parse_time) )
386
398
}
0 commit comments