@@ -526,37 +526,27 @@ impl Command {
526526 }
527527
528528 fn fmt ( flags : Vec < OsString > ) -> Result < ( ) > {
529+ use itertools:: Itertools ;
530+
529531 let e = MiriEnv :: new ( ) ?;
530- let toolchain = & e. toolchain ;
531532 let config_path = path ! ( e. miri_dir / "rustfmt.toml" ) ;
532533
533- let mut cmd = cmd ! (
534- e. sh,
535- "rustfmt +{toolchain} --edition=2021 --config-path {config_path} --unstable-features --skip-children {flags...}"
536- ) ;
537- eprintln ! ( "$ {cmd} ..." ) ;
538-
539- // Add all the filenames to the command.
540- // FIXME: `rustfmt` will follow the `mod` statements in these files, so we get a bunch of
541- // duplicate diffs.
542- for item in WalkDir :: new ( & e. miri_dir ) . into_iter ( ) . filter_entry ( |entry| {
543- let name = entry. file_name ( ) . to_string_lossy ( ) ;
544- let ty = entry. file_type ( ) ;
545- if ty. is_file ( ) {
546- name. ends_with ( ".rs" )
547- } else {
548- // dir or symlink. skip `target` and `.git`.
549- & name != "target" && & name != ".git"
550- }
551- } ) {
552- let item = item?;
553- if item. file_type ( ) . is_file ( ) {
554- cmd = cmd. arg ( item. into_path ( ) ) ;
555- }
556- }
534+ // Collect each rust file in the miri repo.
535+ let files = WalkDir :: new ( & e. miri_dir )
536+ . into_iter ( )
537+ . filter_entry ( |entry| {
538+ let name = entry. file_name ( ) . to_string_lossy ( ) ;
539+ let ty = entry. file_type ( ) ;
540+ if ty. is_file ( ) {
541+ name. ends_with ( ".rs" )
542+ } else {
543+ // dir or symlink. skip `target` and `.git`.
544+ & name != "target" && & name != ".git"
545+ }
546+ } )
547+ . filter_ok ( |item| item. file_type ( ) . is_file ( ) )
548+ . map_ok ( |item| item. into_path ( ) ) ;
557549
558- // We want our own error message, repeating the command is too much.
559- cmd. quiet ( ) . run ( ) . map_err ( |_| anyhow ! ( "`rustfmt` failed" ) ) ?;
560- Ok ( ( ) )
550+ e. format_files ( files, & e. toolchain [ ..] , & config_path, & flags[ ..] )
561551 }
562552}
0 commit comments