@@ -53,6 +53,9 @@ pub enum Subcommand {
5353 Fix {
5454 paths : Vec < PathBuf > ,
5555 } ,
56+ Format {
57+ check : bool ,
58+ } ,
5659 Doc {
5760 paths : Vec < PathBuf > ,
5861 } ,
@@ -102,6 +105,7 @@ Subcommands:
102105 check Compile either the compiler or libraries, using cargo check
103106 clippy Run clippy
104107 fix Run cargo fix
108+ fmt Run rustfmt
105109 test Build and run some test suites
106110 bench Build and run some benchmarks
107111 doc Build documentation
@@ -160,6 +164,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`"
160164 || ( s == "check" )
161165 || ( s == "clippy" )
162166 || ( s == "fix" )
167+ || ( s == "fmt" )
163168 || ( s == "test" )
164169 || ( s == "bench" )
165170 || ( s == "doc" )
@@ -222,6 +227,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`"
222227 "clean" => {
223228 opts. optflag ( "" , "all" , "clean all build artifacts" ) ;
224229 }
230+ "fmt" => {
231+ opts. optflag ( "" , "check" , "check formatting instead of applying." ) ;
232+ }
225233 _ => { }
226234 } ;
227235
@@ -323,6 +331,17 @@ Arguments:
323331 ./x.py fix src/libcore src/libproc_macro" ,
324332 ) ;
325333 }
334+ "fmt" => {
335+ subcommand_help. push_str (
336+ "\n
337+ Arguments:
338+ This subcommand optionally accepts a `--check` flag which succeeds if formatting is correct and
339+ fails if it is not. For example:
340+
341+ ./x.py fmt
342+ ./x.py fmt --check" ,
343+ ) ;
344+ }
326345 "test" => {
327346 subcommand_help. push_str (
328347 "\n
@@ -388,7 +407,7 @@ Arguments:
388407
389408 let maybe_rules_help = Builder :: get_help ( & build, subcommand. as_str ( ) ) ;
390409 extra_help. push_str ( maybe_rules_help. unwrap_or_default ( ) . as_str ( ) ) ;
391- } else if subcommand. as_str ( ) != "clean" {
410+ } else if ! ( subcommand. as_str ( ) == "clean" || subcommand . as_str ( ) == "fmt" ) {
392411 extra_help. push_str (
393412 format ! (
394413 "Run `./x.py {} -h -v` to see a list of available paths." ,
@@ -439,6 +458,11 @@ Arguments:
439458 all : matches. opt_present ( "all" ) ,
440459 }
441460 }
461+ "fmt" => {
462+ Subcommand :: Format {
463+ check : matches. opt_present ( "check" ) ,
464+ }
465+ }
442466 "dist" => Subcommand :: Dist { paths } ,
443467 "install" => Subcommand :: Install { paths } ,
444468 _ => {
0 commit comments