@@ -33,7 +33,7 @@ use syntax::parse;
3333use syntax:: symbol:: Symbol ;
3434use syntax:: feature_gate:: UnstableFeatures ;
3535
36- use errors:: { ColorConfig , FatalError , Handler } ;
36+ use errors:: { self , ColorConfig , FatalError , Handler , ErrorFormat } ;
3737
3838use getopts;
3939use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -1540,14 +1540,15 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
15401540 } ) . collect :: < ast:: CrateConfig > ( )
15411541}
15421542
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 )
15441545 -> ( Options , ast:: CrateConfig ) {
15451546 let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
15461547 Some ( "auto" ) => ColorConfig :: Auto ,
15471548 Some ( "always" ) => ColorConfig :: Always ,
15481549 Some ( "never" ) => ColorConfig :: Never ,
15491550
1550- None => ColorConfig :: Auto ,
1551+ None => defaults . color ,
15511552
15521553 Some ( arg) => {
15531554 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)
15741575 enable the short error message option") ) ;
15751576 }
15761577 }
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+ } ,
15791582 Some ( arg) => {
15801583 early_error ( ErrorOutputType :: HumanReadable ( color) ,
15811584 & 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)
15841587 }
15851588 }
15861589 } 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+ }
15881594 } ;
15891595
15901596 let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
@@ -2156,9 +2162,9 @@ mod dep_tracking {
21562162
21572163#[ cfg( test) ]
21582164mod tests {
2159- use errors;
21602165 use getopts;
21612166 use lint;
2167+ use errors:: { self , EnvDefaults , ColorConfig , ErrorFormat } ;
21622168 use middle:: cstore;
21632169 use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
21642170 use session:: build_session;
@@ -2194,7 +2200,11 @@ mod tests {
21942200 Err ( f) => panic ! ( "test_switch_implies_cfg_test: {}" , f)
21952201 } ;
21962202 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) ;
21982208 let sess = build_session ( sessopts, None , registry) ;
21992209 let cfg = build_configuration ( & sess, cfg) ;
22002210 assert ! ( cfg. contains( & ( Symbol :: intern( "test" ) , None ) ) ) ;
@@ -2212,7 +2222,11 @@ mod tests {
22122222 }
22132223 } ;
22142224 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) ;
22162230 let sess = build_session ( sessopts, None , registry) ;
22172231 let cfg = build_configuration ( & sess, cfg) ;
22182232 let mut test_items = cfg. iter ( ) . filter ( |& & ( name, _) | name == "test" ) ;
@@ -2227,7 +2241,11 @@ mod tests {
22272241 "-Awarnings" . to_string ( )
22282242 ] ) . unwrap ( ) ;
22292243 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) ;
22312249 let sess = build_session ( sessopts, None , registry) ;
22322250 assert ! ( !sess. diagnostic( ) . flags. can_emit_warnings) ;
22332251 }
@@ -2238,7 +2256,11 @@ mod tests {
22382256 "-Dwarnings" . to_string ( )
22392257 ] ) . unwrap ( ) ;
22402258 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) ;
22422264 let sess = build_session ( sessopts, None , registry) ;
22432265 assert ! ( sess. diagnostic( ) . flags. can_emit_warnings) ;
22442266 }
@@ -2248,7 +2270,11 @@ mod tests {
22482270 "-Adead_code" . to_string ( )
22492271 ] ) . unwrap ( ) ;
22502272 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) ;
22522278 let sess = build_session ( sessopts, None , registry) ;
22532279 assert ! ( sess. diagnostic( ) . flags. can_emit_warnings) ;
22542280 }
0 commit comments