@@ -33,7 +33,7 @@ use syntax::parse;
33
33
use syntax:: symbol:: Symbol ;
34
34
use syntax:: feature_gate:: UnstableFeatures ;
35
35
36
- use errors:: { ColorConfig , FatalError , Handler } ;
36
+ use errors:: { self , ColorConfig , FatalError , Handler , ErrorFormat } ;
37
37
38
38
use getopts;
39
39
use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -1540,14 +1540,15 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
1540
1540
} ) . collect :: < ast:: CrateConfig > ( )
1541
1541
}
1542
1542
1543
- pub fn build_session_options_and_crate_config ( matches : & getopts:: Matches )
1543
+ pub fn build_session_options_and_crate_config ( matches : & getopts:: Matches ,
1544
+ defaults : errors:: EnvDefaults )
1544
1545
-> ( Options , ast:: CrateConfig ) {
1545
1546
let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
1546
1547
Some ( "auto" ) => ColorConfig :: Auto ,
1547
1548
Some ( "always" ) => ColorConfig :: Always ,
1548
1549
Some ( "never" ) => ColorConfig :: Never ,
1549
1550
1550
- None => ColorConfig :: Auto ,
1551
+ None => defaults . color ,
1551
1552
1552
1553
Some ( arg) => {
1553
1554
early_error ( ErrorOutputType :: default ( ) , & format ! ( "argument for --color must be auto, \
@@ -1574,8 +1575,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1574
1575
enable the short error message option") ) ;
1575
1576
}
1576
1577
}
1577
- None => ErrorOutputType :: HumanReadable ( color) ,
1578
-
1578
+ None => match ( defaults. error_format , nightly_options:: is_nightly_build ( ) ) {
1579
+ ( ErrorFormat :: Short , true ) => ErrorOutputType :: Short ( color) ,
1580
+ _ => ErrorOutputType :: HumanReadable ( color) ,
1581
+ } ,
1579
1582
Some ( arg) => {
1580
1583
early_error ( ErrorOutputType :: HumanReadable ( color) ,
1581
1584
& format ! ( "argument for --error-format must be `human`, `json` or \
@@ -1584,7 +1587,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1584
1587
}
1585
1588
}
1586
1589
} else {
1587
- ErrorOutputType :: HumanReadable ( color)
1590
+ match ( defaults. error_format , nightly_options:: is_nightly_build ( ) ) {
1591
+ ( ErrorFormat :: Short , true ) => ErrorOutputType :: Short ( color) ,
1592
+ _ => ErrorOutputType :: HumanReadable ( color) ,
1593
+ }
1588
1594
} ;
1589
1595
1590
1596
let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
@@ -2156,9 +2162,9 @@ mod dep_tracking {
2156
2162
2157
2163
#[ cfg( test) ]
2158
2164
mod tests {
2159
- use errors;
2160
2165
use getopts;
2161
2166
use lint;
2167
+ use errors:: { self , EnvDefaults , ColorConfig , ErrorFormat } ;
2162
2168
use middle:: cstore;
2163
2169
use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
2164
2170
use session:: build_session;
@@ -2194,7 +2200,11 @@ mod tests {
2194
2200
Err ( f) => panic ! ( "test_switch_implies_cfg_test: {}" , f)
2195
2201
} ;
2196
2202
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
2197
- let ( sessopts, cfg) = build_session_options_and_crate_config ( matches) ;
2203
+ let defaults = EnvDefaults {
2204
+ error_format : ErrorFormat :: Regular ,
2205
+ color : ColorConfig :: Auto ,
2206
+ } ;
2207
+ let ( sessopts, cfg) = build_session_options_and_crate_config ( & matches, defaults) ;
2198
2208
let sess = build_session ( sessopts, None , registry) ;
2199
2209
let cfg = build_configuration ( & sess, cfg) ;
2200
2210
assert ! ( cfg. contains( & ( Symbol :: intern( "test" ) , None ) ) ) ;
@@ -2212,7 +2222,11 @@ mod tests {
2212
2222
}
2213
2223
} ;
2214
2224
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
2215
- let ( sessopts, cfg) = build_session_options_and_crate_config ( matches) ;
2225
+ let defaults = EnvDefaults {
2226
+ error_format : ErrorFormat :: Regular ,
2227
+ color : ColorConfig :: Auto ,
2228
+ } ;
2229
+ let ( sessopts, cfg) = build_session_options_and_crate_config ( & matches, defaults) ;
2216
2230
let sess = build_session ( sessopts, None , registry) ;
2217
2231
let cfg = build_configuration ( & sess, cfg) ;
2218
2232
let mut test_items = cfg. iter ( ) . filter ( |& & ( name, _) | name == "test" ) ;
@@ -2227,7 +2241,11 @@ mod tests {
2227
2241
"-Awarnings" . to_string ( )
2228
2242
] ) . unwrap ( ) ;
2229
2243
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
2230
- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
2244
+ let defaults = EnvDefaults {
2245
+ error_format : ErrorFormat :: Regular ,
2246
+ color : ColorConfig :: Auto ,
2247
+ } ;
2248
+ let ( sessopts, _) = build_session_options_and_crate_config ( & matches, defaults) ;
2231
2249
let sess = build_session ( sessopts, None , registry) ;
2232
2250
assert ! ( !sess. diagnostic( ) . flags. can_emit_warnings) ;
2233
2251
}
@@ -2238,7 +2256,11 @@ mod tests {
2238
2256
"-Dwarnings" . to_string ( )
2239
2257
] ) . unwrap ( ) ;
2240
2258
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
2241
- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
2259
+ let defaults = EnvDefaults {
2260
+ error_format : ErrorFormat :: Regular ,
2261
+ color : ColorConfig :: Auto ,
2262
+ } ;
2263
+ let ( sessopts, _) = build_session_options_and_crate_config ( & matches, defaults) ;
2242
2264
let sess = build_session ( sessopts, None , registry) ;
2243
2265
assert ! ( sess. diagnostic( ) . flags. can_emit_warnings) ;
2244
2266
}
@@ -2248,7 +2270,11 @@ mod tests {
2248
2270
"-Adead_code" . to_string ( )
2249
2271
] ) . unwrap ( ) ;
2250
2272
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
2251
- let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
2273
+ let defaults = EnvDefaults {
2274
+ error_format : ErrorFormat :: Regular ,
2275
+ color : ColorConfig :: Auto ,
2276
+ } ;
2277
+ let ( sessopts, _) = build_session_options_and_crate_config ( & matches, defaults) ;
2252
2278
let sess = build_session ( sessopts, None , registry) ;
2253
2279
assert ! ( sess. diagnostic( ) . flags. can_emit_warnings) ;
2254
2280
}
0 commit comments