@@ -19,7 +19,7 @@ use getopts::{Matches, Options};
19
19
20
20
use crate :: rustfmt:: {
21
21
load_config, CliOptions , Color , Config , Edition , EmitMode , FileLines , FileName ,
22
- FormatReportFormatterBuilder , Input , Session , Verbosity ,
22
+ FormatReportFormatterBuilder , Input , Session , StyleEdition , Verbosity ,
23
23
} ;
24
24
25
25
const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug" ;
@@ -129,7 +129,12 @@ fn make_opts() -> Options {
129
129
found reverts to the input file path",
130
130
"[Path for the configuration file]" ,
131
131
) ;
132
- opts. optopt ( "" , "edition" , "Rust edition to use" , "[2015|2018|2021]" ) ;
132
+ opts. optopt (
133
+ "" ,
134
+ "edition" ,
135
+ "Rust edition to use" ,
136
+ "[2015|2018|2021|2024]" ,
137
+ ) ;
133
138
opts. optopt (
134
139
"" ,
135
140
"color" ,
@@ -181,6 +186,12 @@ fn make_opts() -> Options {
181
186
"skip-children" ,
182
187
"Don't reformat child modules (unstable)." ,
183
188
) ;
189
+ opts. optopt (
190
+ "" ,
191
+ "style-edition" ,
192
+ "The edition of the Style Guide (unstable)." ,
193
+ "[2015|2018|2021|2024]" ,
194
+ ) ;
184
195
}
185
196
186
197
opts. optflag ( "v" , "verbose" , "Print verbose output" ) ;
@@ -525,6 +536,7 @@ struct GetOptsOptions {
525
536
backup : bool ,
526
537
check : bool ,
527
538
edition : Option < Edition > ,
539
+ style_edition : Option < StyleEdition > ,
528
540
color : Option < Color > ,
529
541
file_lines : FileLines , // Default is all lines in all files.
530
542
unstable_features : bool ,
@@ -556,6 +568,10 @@ impl GetOptsOptions {
556
568
if let Some ( ref file_lines) = matches. opt_str ( "file-lines" ) {
557
569
options. file_lines = file_lines. parse ( ) ?;
558
570
}
571
+ if let Some ( ref edition_str) = matches. opt_str ( "style-edition" ) {
572
+ options. style_edition =
573
+ Some ( style_edition_from_style_edition_str ( edition_str) ?) ;
574
+ }
559
575
} else {
560
576
let mut unstable_options = vec ! [ ] ;
561
577
if matches. opt_present ( "skip-children" ) {
@@ -567,6 +583,9 @@ impl GetOptsOptions {
567
583
if matches. opt_present ( "file-lines" ) {
568
584
unstable_options. push ( "`--file-lines`" ) ;
569
585
}
586
+ if matches. opt_present ( "style-edition" ) {
587
+ unstable_options. push ( "`--style-edition`" ) ;
588
+ }
570
589
if !unstable_options. is_empty ( ) {
571
590
let s = if unstable_options. len ( ) == 1 { "" } else { "s" } ;
572
591
return Err ( format_err ! (
@@ -688,6 +707,9 @@ impl CliOptions for GetOptsOptions {
688
707
if let Some ( edition) = self . edition {
689
708
config. set_cli ( ) . edition ( edition) ;
690
709
}
710
+ if let Some ( edition) = self . style_edition {
711
+ config. set ( ) . style_edition ( edition) ;
712
+ }
691
713
if self . check {
692
714
config. set_cli ( ) . emit_mode ( EmitMode :: Diff ) ;
693
715
} else if let Some ( emit_mode) = self . emit_mode {
@@ -723,6 +745,16 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
723
745
}
724
746
}
725
747
748
+ fn style_edition_from_style_edition_str ( edition_str : & str ) -> Result < StyleEdition > {
749
+ match edition_str {
750
+ "2015" => Ok ( StyleEdition :: Edition2015 ) ,
751
+ "2018" => Ok ( StyleEdition :: Edition2018 ) ,
752
+ "2021" => Ok ( StyleEdition :: Edition2021 ) ,
753
+ "2024" => Ok ( StyleEdition :: Edition2024 ) ,
754
+ _ => Err ( format_err ! ( "Invalid value for `--style-edition`" ) ) ,
755
+ }
756
+ }
757
+
726
758
fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode > {
727
759
match emit_str {
728
760
"files" => Ok ( EmitMode :: Files ) ,
0 commit comments