diff options
| author | P1start <rewi-github@whanau.org> | 2014-08-29 18:55:35 +1200 |
|---|---|---|
| committer | P1start <rewi-github@whanau.org> | 2014-09-14 17:48:47 +1200 |
| commit | 06d9cc1d7a8582ff844c21a3fafe09dc97f22895 (patch) | |
| tree | 2c4a1b90c58202708d0ee9f95d1ea932b1f3c4bf /src/libsyntax/diagnostic.rs | |
| parent | 19311b6103b49232709d301af4036dbc0021082c (diff) | |
| download | rust-06d9cc1d7a8582ff844c21a3fafe09dc97f22895.tar.gz rust-06d9cc1d7a8582ff844c21a3fafe09dc97f22895.zip | |
Add help diagnostic messages
This adds ‘help’ diagnostic messages to rustc. This is used for anything that provides help to the user, particularly the `--explain` messages that were previously integrated into the relevant error message.
Diffstat (limited to 'src/libsyntax/diagnostic.rs')
| -rw-r--r-- | src/libsyntax/diagnostic.rs | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index faa3946b74d..3b7ee5b28e0 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -105,6 +105,9 @@ impl SpanHandler { pub fn span_end_note(&self, sp: Span, msg: &str) { self.handler.custom_emit(&self.cm, FullSpan(sp), msg, Note); } + pub fn span_help(&self, sp: Span, msg: &str) { + self.handler.emit(Some((&self.cm, sp)), msg, Help); + } pub fn fileline_note(&self, sp: Span, msg: &str) { self.handler.custom_emit(&self.cm, FileLine(sp), msg, Note); } @@ -164,6 +167,9 @@ impl Handler { pub fn note(&self, msg: &str) { self.emit.borrow_mut().emit(None, msg, None, Note); } + pub fn help(&self, msg: &str) { + self.emit.borrow_mut().emit(None, msg, None, Help); + } pub fn bug(&self, msg: &str) -> ! { self.emit.borrow_mut().emit(None, msg, None, Bug); fail!(ExplicitBug); @@ -216,6 +222,7 @@ pub enum Level { Error, Warning, Note, + Help, } impl fmt::Show for Level { @@ -227,6 +234,7 @@ impl fmt::Show for Level { Fatal | Error => "error".fmt(f), Warning => "warning".fmt(f), Note => "note".fmt(f), + Help => "help".fmt(f), } } } @@ -236,7 +244,8 @@ impl Level { match self { Bug | Fatal | Error => term::color::BRIGHT_RED, Warning => term::color::BRIGHT_YELLOW, - Note => term::color::BRIGHT_GREEN + Note => term::color::BRIGHT_GREEN, + Help => term::color::BRIGHT_CYAN, } } } @@ -293,15 +302,6 @@ fn print_diagnostic(dst: &mut EmitterWriter, topic: &str, lvl: Level, Some(code) => { let style = term::attr::ForegroundColor(term::color::BRIGHT_MAGENTA); try!(print_maybe_styled(dst, format!(" [{}]", code.clone()).as_slice(), style)); - match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) { - Some(_) => { - try!(write!(&mut dst.dst, - " (pass `--explain {}` to see a detailed explanation)", - code - )); - } - None => () - } } None => () } @@ -401,7 +401,20 @@ fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan, try!(highlight_lines(dst, cm, sp, lvl, lines)); } } - print_macro_backtrace(dst, cm, sp) + try!(print_macro_backtrace(dst, cm, sp)); + match code { + Some(code) => + match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) { + Some(_) => { + try!(print_diagnostic(dst, ss.as_slice(), Help, + format!("pass `--explain {}` to see a detailed \ + explanation", code).as_slice(), None)); + } + None => () + }, + None => (), + } + Ok(()) } fn highlight_lines(err: &mut EmitterWriter, |
