@@ -19,7 +19,7 @@ use getopts::{Matches, Options};
19
19
20
20
use crate :: rustfmt:: {
21
21
CliOptions , Color , Config , Edition , EmitMode , FileLines , FileName ,
22
- FormatReportFormatterBuilder , Input , Session , StyleEdition , Verbosity , Version , load_config,
22
+ FormatReportFormatterBuilder , Input , Session , Verbosity , Version , load_config,
23
23
} ;
24
24
25
25
const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug" ;
@@ -536,7 +536,6 @@ struct GetOptsOptions {
536
536
backup : bool ,
537
537
check : bool ,
538
538
edition : Option < Edition > ,
539
- style_edition : Option < StyleEdition > ,
540
539
color : Option < Color > ,
541
540
file_lines : FileLines , // Default is all lines in all files.
542
541
unstable_features : bool ,
@@ -628,8 +627,8 @@ impl GetOptsOptions {
628
627
options. edition = Some ( edition_from_edition_str ( edition_str) ?) ;
629
628
}
630
629
631
- if let Some ( ref edition_str ) = matches. opt_str ( "style-edition" ) {
632
- options . style_edition = Some ( style_edition_from_style_edition_str ( edition_str ) ? ) ;
630
+ if let Some ( ref _edition_str ) = matches. opt_str ( "style-edition" ) {
631
+ // FIXME(new): removed
633
632
}
634
633
635
634
if matches. opt_present ( "backup" ) {
@@ -704,9 +703,6 @@ impl CliOptions for GetOptsOptions {
704
703
if let Some ( edition) = self . edition {
705
704
config. set_cli ( ) . edition ( edition) ;
706
705
}
707
- if let Some ( edition) = self . style_edition {
708
- config. set_cli ( ) . style_edition ( edition) ;
709
- }
710
706
if self . check {
711
707
config. set_cli ( ) . emit_mode ( EmitMode :: Diff ) ;
712
708
} else if let Some ( emit_mode) = self . emit_mode {
@@ -737,12 +733,6 @@ impl CliOptions for GetOptsOptions {
737
733
. map_or ( self . edition , |e| Edition :: from_str ( e) . ok ( ) )
738
734
}
739
735
740
- fn style_edition ( & self ) -> Option < StyleEdition > {
741
- self . inline_config
742
- . get ( "style_edition" )
743
- . map_or ( self . style_edition , |se| StyleEdition :: from_str ( se) . ok ( ) )
744
- }
745
-
746
736
fn version ( & self ) -> Option < Version > {
747
737
self . inline_config
748
738
. get ( "version" )
@@ -761,17 +751,6 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
761
751
}
762
752
}
763
753
764
- fn style_edition_from_style_edition_str ( edition_str : & str ) -> Result < StyleEdition > {
765
- match edition_str {
766
- "2015" => Ok ( StyleEdition :: Edition2015 ) ,
767
- "2018" => Ok ( StyleEdition :: Edition2018 ) ,
768
- "2021" => Ok ( StyleEdition :: Edition2021 ) ,
769
- "2024" => Ok ( StyleEdition :: Edition2024 ) ,
770
- "2027" => Ok ( StyleEdition :: Edition2027 ) ,
771
- _ => Err ( format_err ! ( "Invalid value for `--style-edition`" ) ) ,
772
- }
773
- }
774
-
775
754
fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode > {
776
755
match emit_str {
777
756
"files" => Ok ( EmitMode :: Files ) ,
@@ -782,185 +761,3 @@ fn emit_mode_from_emit_str(emit_str: &str) -> Result<EmitMode> {
782
761
_ => Err ( format_err ! ( "Invalid value for `--emit`" ) ) ,
783
762
}
784
763
}
785
-
786
- #[ cfg( test) ]
787
- #[ allow( dead_code) ]
788
- mod test {
789
- use super :: * ;
790
- use rustfmt_config_proc_macro:: nightly_only_test;
791
-
792
- fn get_config < O : CliOptions > ( path : Option < & Path > , options : Option < O > ) -> Config {
793
- load_config ( path, options) . unwrap ( ) . 0
794
- }
795
-
796
- #[ nightly_only_test]
797
- #[ test]
798
- fn flag_sets_style_edition_override_correctly ( ) {
799
- let mut options = GetOptsOptions :: default ( ) ;
800
- options. style_edition = Some ( StyleEdition :: Edition2024 ) ;
801
- let config = get_config ( None , Some ( options) ) ;
802
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
803
- }
804
-
805
- #[ nightly_only_test]
806
- #[ test]
807
- fn edition_sets_style_edition_override_correctly ( ) {
808
- let mut options = GetOptsOptions :: default ( ) ;
809
- options. edition = Some ( Edition :: Edition2024 ) ;
810
- let config = get_config ( None , Some ( options) ) ;
811
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
812
- }
813
-
814
- #[ nightly_only_test]
815
- #[ test]
816
- fn version_sets_style_edition_override_correctly ( ) {
817
- let mut options = GetOptsOptions :: default ( ) ;
818
- options. inline_config = HashMap :: from ( [ ( "version" . to_owned ( ) , "Two" . to_owned ( ) ) ] ) ;
819
- let config = get_config ( None , Some ( options) ) ;
820
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
821
- assert_eq ! ( config. overflow_delimited_expr( ) , true ) ;
822
- }
823
-
824
- #[ nightly_only_test]
825
- #[ test]
826
- fn version_config_file_sets_style_edition_override_correctly ( ) {
827
- let options = GetOptsOptions :: default ( ) ;
828
- let config_file = Some ( Path :: new ( "tests/config/style-edition/just-version" ) ) ;
829
- let config = get_config ( config_file, Some ( options) ) ;
830
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
831
- assert_eq ! ( config. overflow_delimited_expr( ) , true ) ;
832
- }
833
-
834
- #[ nightly_only_test]
835
- #[ test]
836
- fn style_edition_flag_has_correct_precedence_over_edition ( ) {
837
- let mut options = GetOptsOptions :: default ( ) ;
838
- options. style_edition = Some ( StyleEdition :: Edition2021 ) ;
839
- options. edition = Some ( Edition :: Edition2024 ) ;
840
- let config = get_config ( None , Some ( options) ) ;
841
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2021 ) ;
842
- }
843
-
844
- #[ nightly_only_test]
845
- #[ test]
846
- fn style_edition_flag_has_correct_precedence_over_version ( ) {
847
- let mut options = GetOptsOptions :: default ( ) ;
848
- options. style_edition = Some ( StyleEdition :: Edition2018 ) ;
849
- options. inline_config = HashMap :: from ( [ ( "version" . to_owned ( ) , "Two" . to_owned ( ) ) ] ) ;
850
- let config = get_config ( None , Some ( options) ) ;
851
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2018 ) ;
852
- }
853
-
854
- #[ nightly_only_test]
855
- #[ test]
856
- fn style_edition_flag_has_correct_precedence_over_edition_version ( ) {
857
- let mut options = GetOptsOptions :: default ( ) ;
858
- options. style_edition = Some ( StyleEdition :: Edition2021 ) ;
859
- options. edition = Some ( Edition :: Edition2018 ) ;
860
- options. inline_config = HashMap :: from ( [ ( "version" . to_owned ( ) , "Two" . to_owned ( ) ) ] ) ;
861
- let config = get_config ( None , Some ( options) ) ;
862
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2021 ) ;
863
- }
864
-
865
- #[ nightly_only_test]
866
- #[ test]
867
- fn style_edition_inline_has_correct_precedence_over_edition_version ( ) {
868
- let mut options = GetOptsOptions :: default ( ) ;
869
- options. edition = Some ( Edition :: Edition2018 ) ;
870
- options. inline_config = HashMap :: from ( [
871
- ( "version" . to_owned ( ) , "One" . to_owned ( ) ) ,
872
- ( "style_edition" . to_owned ( ) , "2024" . to_owned ( ) ) ,
873
- ] ) ;
874
- let config = get_config ( None , Some ( options) ) ;
875
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
876
- assert_eq ! ( config. overflow_delimited_expr( ) , true ) ;
877
- }
878
-
879
- #[ nightly_only_test]
880
- #[ test]
881
- fn style_edition_config_file_trumps_edition_flag_version_inline ( ) {
882
- let mut options = GetOptsOptions :: default ( ) ;
883
- let config_file = Some ( Path :: new ( "tests/config/style-edition/just-style-edition" ) ) ;
884
- options. edition = Some ( Edition :: Edition2018 ) ;
885
- options. inline_config = HashMap :: from ( [ ( "version" . to_owned ( ) , "One" . to_owned ( ) ) ] ) ;
886
- let config = get_config ( config_file, Some ( options) ) ;
887
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
888
- }
889
-
890
- #[ nightly_only_test]
891
- #[ test]
892
- fn style_edition_config_file_trumps_edition_config_and_version_inline ( ) {
893
- let mut options = GetOptsOptions :: default ( ) ;
894
- let config_file = Some ( Path :: new (
895
- "tests/config/style-edition/style-edition-and-edition" ,
896
- ) ) ;
897
- options. inline_config = HashMap :: from ( [ ( "version" . to_owned ( ) , "Two" . to_owned ( ) ) ] ) ;
898
- let config = get_config ( config_file, Some ( options) ) ;
899
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2021 ) ;
900
- assert_eq ! ( config. edition( ) , Edition :: Edition2024 ) ;
901
- }
902
-
903
- #[ nightly_only_test]
904
- #[ test]
905
- fn version_config_trumps_edition_config_and_flag ( ) {
906
- let mut options = GetOptsOptions :: default ( ) ;
907
- let config_file = Some ( Path :: new ( "tests/config/style-edition/version-edition" ) ) ;
908
- options. edition = Some ( Edition :: Edition2018 ) ;
909
- let config = get_config ( config_file, Some ( options) ) ;
910
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
911
- }
912
-
913
- #[ nightly_only_test]
914
- #[ test]
915
- fn style_edition_config_file_trumps_version_config ( ) {
916
- let options = GetOptsOptions :: default ( ) ;
917
- let config_file = Some ( Path :: new (
918
- "tests/config/style-edition/version-style-edition" ,
919
- ) ) ;
920
- let config = get_config ( config_file, Some ( options) ) ;
921
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2021 ) ;
922
- }
923
-
924
- #[ nightly_only_test]
925
- #[ test]
926
- fn style_edition_config_file_trumps_edition_version_config ( ) {
927
- let options = GetOptsOptions :: default ( ) ;
928
- let config_file = Some ( Path :: new (
929
- "tests/config/style-edition/version-style-edition-and-edition" ,
930
- ) ) ;
931
- let config = get_config ( config_file, Some ( options) ) ;
932
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2021 ) ;
933
- }
934
-
935
- #[ nightly_only_test]
936
- #[ test]
937
- fn correct_defaults_for_style_edition_loaded ( ) {
938
- let mut options = GetOptsOptions :: default ( ) ;
939
- options. style_edition = Some ( StyleEdition :: Edition2024 ) ;
940
- let config = get_config ( None , Some ( options) ) ;
941
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
942
- assert_eq ! ( config. overflow_delimited_expr( ) , true ) ;
943
- }
944
-
945
- #[ nightly_only_test]
946
- #[ test]
947
- fn style_edition_defaults_overridden_from_config ( ) {
948
- let options = GetOptsOptions :: default ( ) ;
949
- let config_file = Some ( Path :: new ( "tests/config/style-edition/overrides" ) ) ;
950
- let config = get_config ( config_file, Some ( options) ) ;
951
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
952
- assert_eq ! ( config. overflow_delimited_expr( ) , false ) ;
953
- }
954
-
955
- #[ nightly_only_test]
956
- #[ test]
957
- fn style_edition_defaults_overridden_from_cli ( ) {
958
- let mut options = GetOptsOptions :: default ( ) ;
959
- let config_file = Some ( Path :: new ( "tests/config/style-edition/just-style-edition" ) ) ;
960
- options. inline_config =
961
- HashMap :: from ( [ ( "overflow_delimited_expr" . to_owned ( ) , "false" . to_owned ( ) ) ] ) ;
962
- let config = get_config ( config_file, Some ( options) ) ;
963
- assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
964
- assert_eq ! ( config. overflow_delimited_expr( ) , false ) ;
965
- }
966
- }
0 commit comments