about summary refs log tree commit diff
path: root/src/libsyntax/errors/mod.rs
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2015-12-31 18:47:14 +1300
committerNick Cameron <ncameron@mozilla.com>2016-01-15 10:24:12 +1300
commitb976d9e6660c16f4a1d5a28b11afa7ccb4f75da6 (patch)
tree7838d2d7d0bb08bf607bc4108c83e1822d58d33f /src/libsyntax/errors/mod.rs
parentfd46c78f8f5bc760a46c36fc03f97d43ac389db6 (diff)
downloadrust-b976d9e6660c16f4a1d5a28b11afa7ccb4f75da6.tar.gz
rust-b976d9e6660c16f4a1d5a28b11afa7ccb4f75da6.zip
Implement JSON error emission
[breaking-change]

syntax::errors::Handler::new has been renamed to with_tty_emitter

Many functions which used to take a syntax::errors::ColorConfig, now take a rustc::session::config::ErrorOutputType. If you previously used ColorConfig::Auto as a default, you should now use ErrorOutputType::default().
Diffstat (limited to 'src/libsyntax/errors/mod.rs')
-rw-r--r--src/libsyntax/errors/mod.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/libsyntax/errors/mod.rs b/src/libsyntax/errors/mod.rs
index 68f8caf755a..f269dee31d9 100644
--- a/src/libsyntax/errors/mod.rs
+++ b/src/libsyntax/errors/mod.rs
@@ -276,13 +276,12 @@ pub struct Handler {
 }
 
 impl Handler {
-    // TODO remove
-    pub fn new(color_config: ColorConfig,
-               registry: Option<diagnostics::registry::Registry>,
-               can_emit_warnings: bool,
-               treat_err_as_bug: bool,
-               cm: Rc<codemap::CodeMap>)
-               -> Handler {
+    pub fn with_tty_emitter(color_config: ColorConfig,
+                            registry: Option<diagnostics::registry::Registry>,
+                            can_emit_warnings: bool,
+                            treat_err_as_bug: bool,
+                            cm: Rc<codemap::CodeMap>)
+                            -> Handler {
         let emitter = Box::new(EmitterWriter::stderr(color_config, registry, cm));
         Handler::with_emitter(can_emit_warnings, treat_err_as_bug, emitter)
     }
@@ -549,14 +548,7 @@ impl fmt::Display for Level {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use std::fmt::Display;
 
-        match *self {
-            Bug => "error: internal compiler error".fmt(f),
-            Fatal | Error => "error".fmt(f),
-            Warning => "warning".fmt(f),
-            Note => "note".fmt(f),
-            Help => "help".fmt(f),
-            Cancelled => unreachable!(),
-        }
+        self.to_str().fmt(f)
     }
 }
 
@@ -570,6 +562,17 @@ impl Level {
             Cancelled => unreachable!(),
         }
     }
+
+    fn to_str(self) -> &'static str {
+        match self {
+            Bug => "error: internal compiler error",
+            Fatal | Error => "error",
+            Warning => "warning",
+            Note => "note",
+            Help => "help",
+            Cancelled => panic!("Shouldn't call on cancelled error"),
+        }
+    }
 }
 
 pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where