11use crate :: clippy_project_root;
2+ use itertools:: Itertools ;
23use shell_escape:: escape;
3- use std:: ffi:: OsStr ;
4+ use std:: ffi:: { OsStr , OsString } ;
45use std:: path:: Path ;
56use std:: process:: { self , Command } ;
67use std:: { fs, io} ;
@@ -56,15 +57,22 @@ pub fn run(check: bool, verbose: bool) {
5657 success &= cargo_fmt ( context, & project_root. join ( "rustc_tools_util" ) ) ?;
5758 success &= cargo_fmt ( context, & project_root. join ( "lintcheck" ) ) ?;
5859
59- for entry in WalkDir :: new ( project_root. join ( "tests" ) ) {
60- let entry = entry?;
61- let path = entry. path ( ) ;
62-
63- if path. extension ( ) != Some ( "rs" . as_ref ( ) ) || entry. file_name ( ) == "ice-3891.rs" {
64- continue ;
65- }
66-
67- success &= rustfmt ( context, path) ?;
60+ let chunks = WalkDir :: new ( project_root. join ( "tests" ) )
61+ . into_iter ( )
62+ . filter_map ( |entry| {
63+ let entry = entry. expect ( "failed to find tests" ) ;
64+ let path = entry. path ( ) ;
65+
66+ if path. extension ( ) != Some ( "rs" . as_ref ( ) ) || entry. file_name ( ) == "ice-3891.rs" {
67+ None
68+ } else {
69+ Some ( entry. into_path ( ) . into_os_string ( ) )
70+ }
71+ } )
72+ . chunks ( 250 ) ;
73+
74+ for chunk in & chunks {
75+ success &= rustfmt ( context, chunk) ?;
6876 }
6977
7078 Ok ( success)
@@ -149,7 +157,7 @@ fn exec(
149157}
150158
151159fn cargo_fmt ( context : & FmtContext , path : & Path ) -> Result < bool , CliError > {
152- let mut args = vec ! [ "+nightly" , " fmt", "--all" ] ;
160+ let mut args = vec ! [ "fmt" , "--all" ] ;
153161 if context. check {
154162 args. push ( "--" ) ;
155163 args. push ( "--check" ) ;
@@ -162,7 +170,7 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
162170fn rustfmt_test ( context : & FmtContext ) -> Result < ( ) , CliError > {
163171 let program = "rustfmt" ;
164172 let dir = std:: env:: current_dir ( ) ?;
165- let args = & [ "+nightly" , " --version"] ;
173+ let args = & [ "--version" ] ;
166174
167175 if context. verbose {
168176 println ! ( "{}" , format_command( & program, & dir, args) ) ;
@@ -185,14 +193,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
185193 }
186194}
187195
188- fn rustfmt ( context : & FmtContext , path : & Path ) -> Result < bool , CliError > {
189- let mut args = vec ! [ "+nightly" . as_ref ( ) , path . as_os_str ( ) ] ;
196+ fn rustfmt ( context : & FmtContext , paths : impl Iterator < Item = OsString > ) -> Result < bool , CliError > {
197+ let mut args = Vec :: new ( ) ;
190198 if context. check {
191- args. push ( "--check" . as_ref ( ) ) ;
199+ args. push ( OsString :: from ( "--check" ) ) ;
192200 }
201+ args. extend ( paths) ;
202+
193203 let success = exec ( context, "rustfmt" , std:: env:: current_dir ( ) ?, & args) ?;
194- if !success {
195- eprintln ! ( "rustfmt failed on {}" , path. display( ) ) ;
196- }
204+
197205 Ok ( success)
198206}
0 commit comments