@@ -8,7 +8,7 @@ use rustc::session::config::{build_configuration, build_session_options, to_crat
88use rustc:: session:: config:: { LtoCli , LinkerPluginLto , SwitchWithOptPath , ExternEntry } ;
99use rustc:: session:: config:: { Externs , OutputType , OutputTypes , SymbolManglingVersion } ;
1010use rustc:: session:: config:: { rustc_optgroups, Options , ErrorOutputType , Passes } ;
11- use rustc:: session:: build_session;
11+ use rustc:: session:: { build_session, Session } ;
1212use rustc:: session:: search_paths:: SearchPath ;
1313use std:: collections:: { BTreeMap , BTreeSet } ;
1414use std:: iter:: FromIterator ;
@@ -17,16 +17,23 @@ use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
1717use syntax:: symbol:: sym;
1818use syntax:: edition:: { Edition , DEFAULT_EDITION } ;
1919use syntax;
20+ use syntax_expand:: config:: process_configure_mod;
2021use rustc_data_structures:: fx:: FxHashSet ;
2122use rustc_errors:: { ColorConfig , emitter:: HumanReadableErrorType , registry} ;
2223
23- pub fn build_session_options_and_crate_config (
24- matches : & getopts:: Matches ,
25- ) -> ( Options , FxHashSet < ( String , Option < String > ) > ) {
26- (
27- build_session_options ( matches) ,
28- parse_cfgspecs ( matches. opt_strs ( "cfg" ) ) ,
29- )
24+ type CfgSpecs = FxHashSet < ( String , Option < String > ) > ;
25+
26+ fn build_session_options_and_crate_config ( matches : getopts:: Matches ) -> ( Options , CfgSpecs ) {
27+ let sessopts = build_session_options ( & matches) ;
28+ let cfg = parse_cfgspecs ( matches. opt_strs ( "cfg" ) ) ;
29+ ( sessopts, cfg)
30+ }
31+
32+ fn mk_session ( matches : getopts:: Matches ) -> ( Session , CfgSpecs ) {
33+ let registry = registry:: Registry :: new ( & [ ] ) ;
34+ let ( sessopts, cfg) = build_session_options_and_crate_config ( matches) ;
35+ let sess = build_session ( sessopts, None , registry, process_configure_mod) ;
36+ ( sess, cfg)
3037}
3138
3239fn new_public_extern_entry < S , I > ( locations : I ) -> ExternEntry
@@ -59,31 +66,19 @@ fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
5966#[ test]
6067fn test_switch_implies_cfg_test ( ) {
6168 syntax:: with_default_globals ( || {
62- let matches = & match optgroups ( ) . parse ( & [ "--test" . to_string ( ) ] ) {
63- Ok ( m) => m,
64- Err ( f) => panic ! ( "test_switch_implies_cfg_test: {}" , f) ,
65- } ;
66- let registry = registry:: Registry :: new ( & [ ] ) ;
67- let ( sessopts, cfg) = build_session_options_and_crate_config ( matches) ;
68- let sess = build_session ( sessopts, None , registry) ;
69+ let matches = optgroups ( ) . parse ( & [ "--test" . to_string ( ) ] ) . unwrap ( ) ;
70+ let ( sess, cfg) = mk_session ( matches) ;
6971 let cfg = build_configuration ( & sess, to_crate_config ( cfg) ) ;
7072 assert ! ( cfg. contains( & ( sym:: test, None ) ) ) ;
7173 } ) ;
7274}
7375
74- // When the user supplies --test and --cfg test, don't implicitly add
75- // another --cfg test
76+ // When the user supplies --test and --cfg test, don't implicitly add another --cfg test
7677#[ test]
7778fn test_switch_implies_cfg_test_unless_cfg_test ( ) {
7879 syntax:: with_default_globals ( || {
79- let matches = & match optgroups ( ) . parse ( & [ "--test" . to_string ( ) ,
80- "--cfg=test" . to_string ( ) ] ) {
81- Ok ( m) => m,
82- Err ( f) => panic ! ( "test_switch_implies_cfg_test_unless_cfg_test: {}" , f) ,
83- } ;
84- let registry = registry:: Registry :: new ( & [ ] ) ;
85- let ( sessopts, cfg) = build_session_options_and_crate_config ( matches) ;
86- let sess = build_session ( sessopts, None , registry) ;
80+ let matches = optgroups ( ) . parse ( & [ "--test" . to_string ( ) , "--cfg=test" . to_string ( ) ] ) . unwrap ( ) ;
81+ let ( sess, cfg) = mk_session ( matches) ;
8782 let cfg = build_configuration ( & sess, to_crate_config ( cfg) ) ;
8883 let mut test_items = cfg. iter ( ) . filter ( |& & ( name, _) | name == sym:: test) ;
8984 assert ! ( test_items. next( ) . is_some( ) ) ;
@@ -95,27 +90,21 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
9590fn test_can_print_warnings ( ) {
9691 syntax:: with_default_globals ( || {
9792 let matches = optgroups ( ) . parse ( & [ "-Awarnings" . to_string ( ) ] ) . unwrap ( ) ;
98- let registry = registry:: Registry :: new ( & [ ] ) ;
99- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
100- let sess = build_session ( sessopts, None , registry) ;
93+ let ( sess, _) = mk_session ( matches) ;
10194 assert ! ( !sess. diagnostic( ) . can_emit_warnings( ) ) ;
10295 } ) ;
10396
10497 syntax:: with_default_globals ( || {
10598 let matches = optgroups ( )
10699 . parse ( & [ "-Awarnings" . to_string ( ) , "-Dwarnings" . to_string ( ) ] )
107100 . unwrap ( ) ;
108- let registry = registry:: Registry :: new ( & [ ] ) ;
109- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
110- let sess = build_session ( sessopts, None , registry) ;
101+ let ( sess, _) = mk_session ( matches) ;
111102 assert ! ( sess. diagnostic( ) . can_emit_warnings( ) ) ;
112103 } ) ;
113104
114105 syntax:: with_default_globals ( || {
115106 let matches = optgroups ( ) . parse ( & [ "-Adead_code" . to_string ( ) ] ) . unwrap ( ) ;
116- let registry = registry:: Registry :: new ( & [ ] ) ;
117- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
118- let sess = build_session ( sessopts, None , registry) ;
107+ let ( sess, _) = mk_session ( matches) ;
119108 assert ! ( sess. diagnostic( ) . can_emit_warnings( ) ) ;
120109 } ) ;
121110}
@@ -704,6 +693,6 @@ fn test_edition_parsing() {
704693 let matches = optgroups ( )
705694 . parse ( & [ "--edition=2018" . to_string ( ) ] )
706695 . unwrap ( ) ;
707- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
696+ let ( sessopts, _) = build_session_options_and_crate_config ( matches) ;
708697 assert ! ( sessopts. edition == Edition :: Edition2018 )
709698}
0 commit comments