@@ -164,7 +164,11 @@ pub fn run_compiler<'a>(args: &[String],
164164
165165 let descriptions = diagnostics_registry ( ) ;
166166
167- do_or_return ! ( callbacks. early_callback( & matches, & descriptions, sopts. error_format) , None ) ;
167+ do_or_return ! ( callbacks. early_callback( & matches,
168+ & sopts,
169+ & descriptions,
170+ sopts. error_format) ,
171+ None ) ;
168172
169173 let ( odir, ofile) = make_output ( & matches) ;
170174 let ( input, input_file_path) = match make_input ( & matches. free ) {
@@ -251,6 +255,7 @@ pub trait CompilerCalls<'a> {
251255 // else (e.g., selecting input and output).
252256 fn early_callback ( & mut self ,
253257 _: & getopts:: Matches ,
258+ _: & config:: Options ,
254259 _: & diagnostics:: registry:: Registry ,
255260 _: ErrorOutputType )
256261 -> Compilation {
@@ -324,34 +329,68 @@ pub trait CompilerCalls<'a> {
324329#[ derive( Copy , Clone ) ]
325330pub struct RustcDefaultCalls ;
326331
332+ fn handle_explain ( code : & str ,
333+ descriptions : & diagnostics:: registry:: Registry ,
334+ output : ErrorOutputType ) {
335+ let normalised = if !code. starts_with ( "E" ) {
336+ format ! ( "E{0:0>4}" , code)
337+ } else {
338+ code. to_string ( )
339+ } ;
340+ match descriptions. find_description ( & normalised) {
341+ Some ( ref description) => {
342+ // Slice off the leading newline and print.
343+ print ! ( "{}" , & description[ 1 ..] ) ;
344+ }
345+ None => {
346+ early_error ( output, & format ! ( "no extended information for {}" , code) ) ;
347+ }
348+ }
349+ }
350+
351+ fn check_cfg ( sopts : & config:: Options ,
352+ output : ErrorOutputType ) {
353+ let mut emitter: Box < Emitter > = match output {
354+ config:: ErrorOutputType :: HumanReadable ( color_config) => {
355+ Box :: new ( errors:: emitter:: BasicEmitter :: stderr ( color_config) )
356+ }
357+ config:: ErrorOutputType :: Json => Box :: new ( errors:: json:: JsonEmitter :: basic ( ) ) ,
358+ } ;
359+
360+ let mut saw_invalid_predicate = false ;
361+ for item in sopts. cfg . iter ( ) {
362+ match item. node {
363+ ast:: MetaList ( ref pred, _) => {
364+ saw_invalid_predicate = true ;
365+ emitter. emit ( None ,
366+ & format ! ( "invalid predicate in --cfg command line argument: `{}`" ,
367+ pred) ,
368+ None ,
369+ errors:: Level :: Fatal ) ;
370+ }
371+ _ => { } ,
372+ }
373+ }
374+
375+ if saw_invalid_predicate {
376+ panic ! ( errors:: FatalError ) ;
377+ }
378+ }
379+
327380impl < ' a > CompilerCalls < ' a > for RustcDefaultCalls {
328381 fn early_callback ( & mut self ,
329382 matches : & getopts:: Matches ,
383+ sopts : & config:: Options ,
330384 descriptions : & diagnostics:: registry:: Registry ,
331385 output : ErrorOutputType )
332386 -> Compilation {
333- match matches. opt_str ( "explain" ) {
334- Some ( ref code) => {
335- let normalised = if !code. starts_with ( "E" ) {
336- format ! ( "E{0:0>4}" , code)
337- } else {
338- code. to_string ( )
339- } ;
340- match descriptions. find_description ( & normalised) {
341- Some ( ref description) => {
342- // Slice off the leading newline and print.
343- print ! ( "{}" , & description[ 1 ..] ) ;
344- }
345- None => {
346- early_error ( output, & format ! ( "no extended information for {}" , code) ) ;
347- }
348- }
349- return Compilation :: Stop ;
350- }
351- None => ( ) ,
387+ if let Some ( ref code) = matches. opt_str ( "explain" ) {
388+ handle_explain ( code, descriptions, output) ;
389+ return Compilation :: Stop ;
352390 }
353391
354- return Compilation :: Continue ;
392+ check_cfg ( sopts, output) ;
393+ Compilation :: Continue
355394 }
356395
357396 fn no_input ( & mut self ,
0 commit comments