@@ -113,9 +113,9 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
113113 }
114114 let rustfmt_config = t ! ( std:: fs:: read_to_string( & rustfmt_config) ) ;
115115 let rustfmt_config: RustfmtConfig = t ! ( toml:: from_str( & rustfmt_config) ) ;
116- let mut ignore_fmt = ignore:: overrides:: OverrideBuilder :: new ( & build. src ) ;
116+ let mut fmt_override = ignore:: overrides:: OverrideBuilder :: new ( & build. src ) ;
117117 for ignore in rustfmt_config. ignore {
118- ignore_fmt . add ( & format ! ( "!{ignore}" ) ) . expect ( & ignore) ;
118+ fmt_override . add ( & format ! ( "!{ignore}" ) ) . expect ( & ignore) ;
119119 }
120120 let git_available = match Command :: new ( "git" )
121121 . arg ( "--version" )
@@ -152,14 +152,16 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
152152 . map ( |entry| {
153153 entry. split ( ' ' ) . nth ( 1 ) . expect ( "every git status entry should list a path" )
154154 } ) ;
155+ let mut untracked_count = 0 ;
155156 for untracked_path in untracked_paths {
156157 println ! ( "skip untracked path {untracked_path} during rustfmt invocations" ) ;
157158 // The leading `/` makes it an exact match against the
158159 // repository root, rather than a glob. Without that, if you
159160 // have `foo.rs` in the repository root it will also match
160161 // against anything like `compiler/rustc_foo/src/foo.rs`,
161162 // preventing the latter from being formatted.
162- ignore_fmt. add ( & format ! ( "!/{untracked_path}" ) ) . expect ( & untracked_path) ;
163+ untracked_count += 1 ;
164+ fmt_override. add ( & format ! ( "!/{untracked_path}" ) ) . expect ( & untracked_path) ;
163165 }
164166 // Only check modified files locally to speed up runtime.
165167 // We still check all files in CI to avoid bugs in `get_modified_rs_files` letting regressions slip through;
@@ -172,10 +174,25 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
172174 println ! ( "formatting modified file {file}" ) ;
173175 }
174176 } else {
175- println ! ( "formatting {} modified files" , files. len( ) ) ;
177+ let pluralized = |count| if count > 1 { "files" } else { "file" } ;
178+ let untracked_msg = if untracked_count == 0 {
179+ "" . to_string ( )
180+ } else {
181+ format ! (
182+ ", skipped {} untracked {}" ,
183+ untracked_count,
184+ pluralized( untracked_count) ,
185+ )
186+ } ;
187+ println ! (
188+ "formatting {} modified {}{}" ,
189+ files. len( ) ,
190+ pluralized( files. len( ) ) ,
191+ untracked_msg
192+ ) ;
176193 }
177194 for file in files {
178- ignore_fmt . add ( & format ! ( "/{file}" ) ) . expect ( & file) ;
195+ fmt_override . add ( & format ! ( "/{file}" ) ) . expect ( & file) ;
179196 }
180197 }
181198 Ok ( None ) => { }
@@ -196,7 +213,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
196213 println ! ( "Could not find usable git. Skipping git-aware format checks" ) ;
197214 }
198215
199- let ignore_fmt = ignore_fmt . build ( ) . unwrap ( ) ;
216+ let fmt_override = fmt_override . build ( ) . unwrap ( ) ;
200217
201218 let rustfmt_path = build. initial_rustfmt ( ) . unwrap_or_else ( || {
202219 eprintln ! ( "./x.py fmt is not supported on this channel" ) ;
@@ -252,7 +269,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
252269 None => WalkBuilder :: new ( src. clone ( ) ) ,
253270 }
254271 . types ( matcher)
255- . overrides ( ignore_fmt )
272+ . overrides ( fmt_override )
256273 . build_parallel ( ) ;
257274
258275 // there is a lot of blocking involved in spawning a child process and reading files to format.
0 commit comments