@@ -164,7 +164,11 @@ pub fn run_compiler<'a>(args: &[String],
164
164
165
165
let descriptions = diagnostics_registry ( ) ;
166
166
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 ) ;
168
172
169
173
let ( odir, ofile) = make_output ( & matches) ;
170
174
let ( input, input_file_path) = match make_input ( & matches. free ) {
@@ -251,6 +255,7 @@ pub trait CompilerCalls<'a> {
251
255
// else (e.g., selecting input and output).
252
256
fn early_callback ( & mut self ,
253
257
_: & getopts:: Matches ,
258
+ _: & config:: Options ,
254
259
_: & diagnostics:: registry:: Registry ,
255
260
_: ErrorOutputType )
256
261
-> Compilation {
@@ -324,34 +329,68 @@ pub trait CompilerCalls<'a> {
324
329
#[ derive( Copy , Clone ) ]
325
330
pub struct RustcDefaultCalls ;
326
331
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
+
327
380
impl < ' a > CompilerCalls < ' a > for RustcDefaultCalls {
328
381
fn early_callback ( & mut self ,
329
382
matches : & getopts:: Matches ,
383
+ sopts : & config:: Options ,
330
384
descriptions : & diagnostics:: registry:: Registry ,
331
385
output : ErrorOutputType )
332
386
-> 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 ;
352
390
}
353
391
354
- return Compilation :: Continue ;
392
+ check_cfg ( sopts, output) ;
393
+ Compilation :: Continue
355
394
}
356
395
357
396
fn no_input ( & mut self ,
0 commit comments