@@ -26,6 +26,7 @@ use std::task::TaskBuilder;
2626use syntax:: ast;
2727use syntax:: parse;
2828use syntax:: diagnostic:: Emitter ;
29+ use syntax:: diagnostics;
2930
3031use getopts;
3132
@@ -49,8 +50,24 @@ fn run_compiler(args: &[String]) {
4950 Some ( matches) => matches,
5051 None => return
5152 } ;
52- let sopts = config:: build_session_options ( & matches) ;
5353
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) ;
5471 let ( input, input_file_path) = match matches. free . len ( ) {
5572 0 u => {
5673 if sopts. describe_lints {
@@ -75,7 +92,7 @@ fn run_compiler(args: &[String]) {
7592 _ => early_error ( "multiple input filenames provided" )
7693 } ;
7794
78- let sess = build_session ( sopts, input_file_path) ;
95+ let sess = build_session ( sopts, input_file_path, descriptions ) ;
7996 let cfg = config:: build_configuration ( & sess) ;
8097 let odir = matches. opt_str ( "out-dir" ) . map ( |o| Path :: new ( o) ) ;
8198 let ofile = matches. opt_str ( "o" ) . map ( |o| Path :: new ( o) ) ;
@@ -383,14 +400,14 @@ fn parse_crate_attrs(sess: &Session, input: &Input) ->
383400}
384401
385402pub 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 ) ;
388405 fail ! ( diagnostic:: FatalError ) ;
389406}
390407
391408pub 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 ) ;
394411}
395412
396413pub fn list_metadata ( sess : & Session , path : & Path ,
@@ -429,14 +446,15 @@ fn monitor(f: proc():Send) {
429446 Err ( value) => {
430447 // Task failed without emitting a fatal diagnostic
431448 if !value. is :: < diagnostic:: FatalError > ( ) {
432- let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto ) ;
449+ let mut emitter = diagnostic:: EmitterWriter :: stderr ( diagnostic:: Auto , None ) ;
433450
434451 // a .span_bug or .bug call has already printed what
435452 // it wants to print.
436453 if !value. is :: < diagnostic:: ExplicitBug > ( ) {
437454 emitter. emit (
438455 None ,
439456 "unexpected failure" ,
457+ None ,
440458 diagnostic:: Bug ) ;
441459 }
442460
@@ -447,7 +465,7 @@ fn monitor(f: proc():Send) {
447465 "run with `RUST_BACKTRACE=1` for a backtrace" . to_string ( ) ,
448466 ] ;
449467 for note in xs. iter ( ) {
450- emitter. emit ( None , note. as_slice ( ) , diagnostic:: Note )
468+ emitter. emit ( None , note. as_slice ( ) , None , diagnostic:: Note )
451469 }
452470
453471 match r. read_to_string ( ) {
@@ -457,6 +475,7 @@ fn monitor(f: proc():Send) {
457475 format ! ( "failed to read internal \
458476 stderr: {}",
459477 e) . as_slice ( ) ,
478+ None ,
460479 diagnostic:: Error )
461480 }
462481 }
0 commit comments