about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-04-17 18:14:22 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-04-17 18:32:26 +0530
commit9c4995f694ef38283d631fd4c242417360fc78ee (patch)
tree11a9a4945617f8025cbcad3c2532aa8bdedcac4c /src/libsyntax
parent3118cd7dad4736385fbefa4b07b1d339590fce6d (diff)
parent9891ea74d6f706cf38e91599f1e65816977cefdc (diff)
downloadrust-9c4995f694ef38283d631fd4c242417360fc78ee.tar.gz
rust-9c4995f694ef38283d631fd4c242417360fc78ee.zip
Rollup merge of #24454 - aochagavia:debug, r=alexcrichton
 Implement `Debug`, `Display` and `Error` for `FatalError` and `ExplicitBug`
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic.rs37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index f3715d765e3..e9af6c00995 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -13,17 +13,14 @@ pub use self::RenderSpan::*;
 pub use self::ColorConfig::*;
 use self::Destination::*;
 
-use codemap::{COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
-use codemap;
+use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
 use diagnostics;
 
 use std::cell::{RefCell, Cell};
-use std::cmp;
-use std::fmt;
+use std::{cmp, error, fmt};
 use std::io::prelude::*;
 use std::io;
-use term::WriterWrapper;
-use term;
+use term::{self, WriterWrapper};
 use libc;
 
 /// maximum number of lines we will print for each error; arbitrary.
@@ -83,15 +80,39 @@ pub trait Emitter {
 /// Used as a return value to signify a fatal error occurred. (It is also
 /// used as the argument to panic at the moment, but that will eventually
 /// not be true.)
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Debug)]
 #[must_use]
 pub struct FatalError;
 
+impl fmt::Display for FatalError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+        write!(f, "parser fatal error")
+    }
+}
+
+impl error::Error for FatalError {
+    fn description(&self) -> &str {
+        "The parser has encountered a fatal error"
+    }
+}
+
 /// Signifies that the compiler died with an explicit call to `.bug`
 /// or `.span_bug` rather than a failed assertion, etc.
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Debug)]
 pub struct ExplicitBug;
 
+impl fmt::Display for ExplicitBug {
+    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+        write!(f, "parser internal bug")
+    }
+}
+
+impl error::Error for ExplicitBug {
+    fn description(&self) -> &str {
+        "The parser has encountered an internal bug"
+    }
+}
+
 /// A span-handler is like a handler but also
 /// accepts span information for source-location
 /// reporting.