@@ -8,7 +8,7 @@ use rustc::session::config::{build_configuration, build_session_options, to_crat
8
8
use rustc:: session:: config:: { LtoCli , LinkerPluginLto , SwitchWithOptPath , ExternEntry } ;
9
9
use rustc:: session:: config:: { Externs , OutputType , OutputTypes , SymbolManglingVersion } ;
10
10
use rustc:: session:: config:: { rustc_optgroups, Options , ErrorOutputType , Passes } ;
11
- use rustc:: session:: build_session;
11
+ use rustc:: session:: { build_session, Session } ;
12
12
use rustc:: session:: search_paths:: SearchPath ;
13
13
use std:: collections:: { BTreeMap , BTreeSet } ;
14
14
use std:: iter:: FromIterator ;
@@ -17,16 +17,23 @@ use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
17
17
use syntax:: symbol:: sym;
18
18
use syntax:: edition:: { Edition , DEFAULT_EDITION } ;
19
19
use syntax;
20
+ use syntax_expand:: config:: process_configure_mod;
20
21
use rustc_data_structures:: fx:: FxHashSet ;
21
22
use rustc_errors:: { ColorConfig , emitter:: HumanReadableErrorType , registry} ;
22
23
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)
30
37
}
31
38
32
39
fn 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> {
59
66
#[ test]
60
67
fn test_switch_implies_cfg_test ( ) {
61
68
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) ;
69
71
let cfg = build_configuration ( & sess, to_crate_config ( cfg) ) ;
70
72
assert ! ( cfg. contains( & ( sym:: test, None ) ) ) ;
71
73
} ) ;
72
74
}
73
75
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
76
77
#[ test]
77
78
fn test_switch_implies_cfg_test_unless_cfg_test ( ) {
78
79
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) ;
87
82
let cfg = build_configuration ( & sess, to_crate_config ( cfg) ) ;
88
83
let mut test_items = cfg. iter ( ) . filter ( |& & ( name, _) | name == sym:: test) ;
89
84
assert ! ( test_items. next( ) . is_some( ) ) ;
@@ -95,27 +90,21 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
95
90
fn test_can_print_warnings ( ) {
96
91
syntax:: with_default_globals ( || {
97
92
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) ;
101
94
assert ! ( !sess. diagnostic( ) . can_emit_warnings( ) ) ;
102
95
} ) ;
103
96
104
97
syntax:: with_default_globals ( || {
105
98
let matches = optgroups ( )
106
99
. parse ( & [ "-Awarnings" . to_string ( ) , "-Dwarnings" . to_string ( ) ] )
107
100
. 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) ;
111
102
assert ! ( sess. diagnostic( ) . can_emit_warnings( ) ) ;
112
103
} ) ;
113
104
114
105
syntax:: with_default_globals ( || {
115
106
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) ;
119
108
assert ! ( sess. diagnostic( ) . can_emit_warnings( ) ) ;
120
109
} ) ;
121
110
}
@@ -704,6 +693,6 @@ fn test_edition_parsing() {
704
693
let matches = optgroups ( )
705
694
. parse ( & [ "--edition=2018" . to_string ( ) ] )
706
695
. unwrap ( ) ;
707
- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
696
+ let ( sessopts, _) = build_session_options_and_crate_config ( matches) ;
708
697
assert ! ( sessopts. edition == Edition :: Edition2018 )
709
698
}
0 commit comments