@@ -64,9 +64,11 @@ create_config! {
6464 // Imports
6565 imports_indent: IndentStyle , IndentStyle :: Block , false , "Indent of imports" ;
6666 imports_layout: ListTactic , ListTactic :: Mixed , false , "Item layout inside a import block" ;
67- merge_imports: bool , false , false , "Merge imports" ;
67+ imports_granularity: ImportGranularity , ImportGranularity :: Preserve , false ,
68+ "Merge or split imports to the provided granularity" ;
6869 group_imports: GroupImportsTactic , GroupImportsTactic :: Preserve , false ,
6970 "Controls the strategy for how imports are grouped together" ;
71+ merge_imports: bool , false , false , "(deprecated: use imports_granularity instead)" ;
7072
7173 // Ordering
7274 reorder_imports: bool , true , true , "Reorder import and extern crate statements alphabetically" ;
@@ -174,6 +176,7 @@ impl PartialConfig {
174176 cloned. verbose = None ;
175177 cloned. width_heuristics = None ;
176178 cloned. print_misformatted_file_names = None ;
179+ cloned. merge_imports = None ;
177180
178181 :: toml:: to_string ( & cloned) . map_err ( ToTomlError )
179182 }
@@ -407,6 +410,10 @@ mod test {
407410 via the --file-lines option";
408411 width_heuristics: WidthHeuristics , WidthHeuristics :: scaled( 100 ) , false ,
409412 "'small' heuristic values" ;
413+ // merge_imports deprecation
414+ imports_granularity: ImportGranularity , ImportGranularity :: Preserve , false ,
415+ "Merge imports" ;
416+ merge_imports: bool , false , false , "(deprecated: use imports_granularity instead)" ;
410417
411418 // Options that are used by the tests
412419 stable_option: bool , false , true , "A stable option" ;
@@ -529,7 +536,7 @@ fn_single_line = false
529536where_single_line = false
530537imports_indent = "Block"
531538imports_layout = "Mixed"
532- merge_imports = false
539+ imports_granularity = "Preserve"
533540group_imports = "Preserve"
534541reorder_imports = true
535542reorder_modules = true
@@ -615,4 +622,53 @@ make_backup = false
615622 // assert_eq!(config.unstable_features(), true);
616623 // ::std::env::set_var("CFG_RELEASE_CHANNEL", v);
617624 // }
625+
626+ #[ cfg( test) ]
627+ mod deprecated_option_merge_imports {
628+ use super :: * ;
629+
630+ #[ test]
631+ fn test_old_option_set ( ) {
632+ let toml = r#"
633+ unstable_features = true
634+ merge_imports = true
635+ "# ;
636+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
637+ assert_eq ! ( config. imports_granularity( ) , ImportGranularity :: Crate ) ;
638+ }
639+
640+ #[ test]
641+ fn test_both_set ( ) {
642+ let toml = r#"
643+ unstable_features = true
644+ merge_imports = true
645+ imports_granularity = "Preserve"
646+ "# ;
647+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
648+ assert_eq ! ( config. imports_granularity( ) , ImportGranularity :: Preserve ) ;
649+ }
650+
651+ #[ test]
652+ fn test_new_overridden ( ) {
653+ let toml = r#"
654+ unstable_features = true
655+ merge_imports = true
656+ "# ;
657+ let mut config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
658+ config. override_value ( "imports_granularity" , "Preserve" ) ;
659+ assert_eq ! ( config. imports_granularity( ) , ImportGranularity :: Preserve ) ;
660+ }
661+
662+ #[ test]
663+ fn test_old_overridden ( ) {
664+ let toml = r#"
665+ unstable_features = true
666+ imports_granularity = "Module"
667+ "# ;
668+ let mut config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
669+ config. override_value ( "merge_imports" , "true" ) ;
670+ // no effect: the new option always takes precedence
671+ assert_eq ! ( config. imports_granularity( ) , ImportGranularity :: Module ) ;
672+ }
673+ }
618674}
0 commit comments