@@ -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" ) ;
@@ -514,6 +525,7 @@ struct GetOptsOptions {
514
525
backup : bool ,
515
526
check : bool ,
516
527
edition : Option < Edition > ,
528
+ style_edition : Option < StyleEdition > ,
517
529
color : Option < Color > ,
518
530
file_lines : FileLines , // Default is all lines in all files.
519
531
unstable_features : bool ,
@@ -545,6 +557,10 @@ impl GetOptsOptions {
545
557
if let Some ( ref file_lines) = matches. opt_str ( "file-lines" ) {
546
558
options. file_lines = file_lines. parse ( ) ?;
547
559
}
560
+ if let Some ( ref edition_str) = matches. opt_str ( "style-edition" ) {
561
+ options. style_edition =
562
+ Some ( style_edition_from_style_edition_str ( edition_str) ?) ;
563
+ }
548
564
} else {
549
565
let mut unstable_options = vec ! [ ] ;
550
566
if matches. opt_present ( "skip-children" ) {
@@ -556,6 +572,9 @@ impl GetOptsOptions {
556
572
if matches. opt_present ( "file-lines" ) {
557
573
unstable_options. push ( "`--file-lines`" ) ;
558
574
}
575
+ if matches. opt_present ( "style-edition" ) {
576
+ unstable_options. push ( "`--style-edition`" ) ;
577
+ }
559
578
if !unstable_options. is_empty ( ) {
560
579
let s = if unstable_options. len ( ) == 1 { "" } else { "s" } ;
561
580
return Err ( format_err ! (
@@ -667,6 +686,9 @@ impl CliOptions for GetOptsOptions {
667
686
if let Some ( edition) = self . edition {
668
687
config. set ( ) . edition ( edition) ;
669
688
}
689
+ if let Some ( edition) = self . style_edition {
690
+ config. set ( ) . style_edition ( edition) ;
691
+ }
670
692
if self . check {
671
693
config. set ( ) . emit_mode ( EmitMode :: Diff ) ;
672
694
} else if let Some ( emit_mode) = self . emit_mode {
@@ -702,6 +724,16 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
702
724
}
703
725
}
704
726
727
+ fn style_edition_from_style_edition_str ( edition_str : & str ) -> Result < StyleEdition > {
728
+ match edition_str {
729
+ "2015" => Ok ( StyleEdition :: Edition2015 ) ,
730
+ "2018" => Ok ( StyleEdition :: Edition2018 ) ,
731
+ "2021" => Ok ( StyleEdition :: Edition2021 ) ,
732
+ "2024" => Ok ( StyleEdition :: Edition2024 ) ,
733
+ _ => Err ( format_err ! ( "Invalid value for `--style-edition`" ) ) ,
734
+ }
735
+ }
736
+
705
737
fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode > {
706
738
match emit_str {
707
739
"files" => Ok ( EmitMode :: Files ) ,
0 commit comments