@@ -26,6 +26,7 @@ use std::task::TaskBuilder;
26
26
use syntax:: ast;
27
27
use syntax:: parse;
28
28
use syntax:: diagnostic:: Emitter ;
29
+ use syntax:: diagnostics;
29
30
30
31
use getopts;
31
32
@@ -49,8 +50,24 @@ fn run_compiler(args: &[String]) {
49
50
Some ( matches) => matches,
50
51
None => return
51
52
} ;
52
- let sopts = config:: build_session_options ( & matches) ;
53
53
54
+ let descriptions = diagnostics:: registry:: Registry :: new ( super :: DIAGNOSTICS ) ;
55
+ match matches. opt_str ( "explain" ) {
56
+ Some ( ref code) => {
57
+ match descriptions. find_description ( code. as_slice ( ) ) {
58
+ Some ( ref description) => {
59
+ println ! ( "{}" , description) ;
60
+ }
61
+ None => {
62
+ early_error ( format ! ( "no extended information for {}" , code) . as_slice ( ) ) ;
63
+ }
64
+ }
65
+ return ;
66
+ } ,
67
+ None => ( )
68
+ }
69
+
70
+ let sopts = config:: build_session_options ( & matches) ;
54
71
let ( input, input_file_path) = match matches. free . len ( ) {
55
72
0 u => {
56
73
if sopts. describe_lints {
@@ -75,7 +92,7 @@ fn run_compiler(args: &[String]) {
75
92
_ => early_error ( "multiple input filenames provided" )
76
93
} ;
77
94
78
- let sess = build_session ( sopts, input_file_path) ;
95
+ let sess = build_session ( sopts, input_file_path, descriptions ) ;
79
96
let cfg = config:: build_configuration ( & sess) ;
80
97
let odir = matches. opt_str ( "out-dir" ) . map ( |o| Path :: new ( o) ) ;
81
98
let ofile = matches. opt_str ( "o" ) . map ( |o| Path :: new ( o) ) ;
@@ -383,14 +400,14 @@ fn parse_crate_attrs(sess: &Session, input: &Input) ->
383
400
}
384
401
385
402
pub fn early_error ( msg : & str ) -> ! {
386
- let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto ) ;
387
- emitter. emit ( None , msg, diagnostic:: Fatal ) ;
403
+ let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto , None ) ;
404
+ emitter. emit ( None , msg, None , diagnostic:: Fatal ) ;
388
405
fail ! ( diagnostic:: FatalError ) ;
389
406
}
390
407
391
408
pub fn early_warn ( msg : & str ) {
392
- let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto ) ;
393
- emitter. emit ( None , msg, diagnostic:: Warning ) ;
409
+ let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto , None ) ;
410
+ emitter. emit ( None , msg, None , diagnostic:: Warning ) ;
394
411
}
395
412
396
413
pub fn list_metadata ( sess : & Session , path : & Path ,
@@ -429,14 +446,15 @@ fn monitor(f: proc():Send) {
429
446
Err ( value) => {
430
447
// Task failed without emitting a fatal diagnostic
431
448
if !value. is :: < diagnostic:: FatalError > ( ) {
432
- let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto ) ;
449
+ let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto , None ) ;
433
450
434
451
// a .span_bug or .bug call has already printed what
435
452
// it wants to print.
436
453
if !value. is :: < diagnostic:: ExplicitBug > ( ) {
437
454
emitter. emit (
438
455
None ,
439
456
"unexpected failure" ,
457
+ None ,
440
458
diagnostic:: Bug ) ;
441
459
}
442
460
@@ -447,7 +465,7 @@ fn monitor(f: proc():Send) {
447
465
"run with `RUST_BACKTRACE=1` for a backtrace" . to_string ( ) ,
448
466
] ;
449
467
for note in xs. iter ( ) {
450
- emitter. emit ( None , note. as_slice ( ) , diagnostic:: Note )
468
+ emitter. emit ( None , note. as_slice ( ) , None , diagnostic:: Note )
451
469
}
452
470
453
471
match r. read_to_string ( ) {
@@ -457,6 +475,7 @@ fn monitor(f: proc():Send) {
457
475
format ! ( "failed to read internal \
458
476
stderr: {}",
459
477
e) . as_slice ( ) ,
478
+ None ,
460
479
diagnostic:: Error )
461
480
}
462
481
}
0 commit comments