about summary refs log tree commit diff
path: root/src/libsyntax/diagnostics
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2015-01-24 09:15:42 -0800
committerBrian Anderson <banderson@mozilla.com>2015-01-25 01:20:55 -0800
commit63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70 (patch)
treec732033c0822f25f2aebcdf193de1b257bac1855 /src/libsyntax/diagnostics
parentb44ee371b8beea77aa1364460acbba14a8516559 (diff)
parent0430a43d635841db44978bb648e9cf7e7cfa1bba (diff)
downloadrust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.tar.gz
rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.zip
Merge remote-tracking branch 'rust-lang/master'
Conflicts:
	mk/tests.mk
	src/liballoc/arc.rs
	src/liballoc/boxed.rs
	src/liballoc/rc.rs
	src/libcollections/bit.rs
	src/libcollections/btree/map.rs
	src/libcollections/btree/set.rs
	src/libcollections/dlist.rs
	src/libcollections/ring_buf.rs
	src/libcollections/slice.rs
	src/libcollections/str.rs
	src/libcollections/string.rs
	src/libcollections/vec.rs
	src/libcollections/vec_map.rs
	src/libcore/any.rs
	src/libcore/array.rs
	src/libcore/borrow.rs
	src/libcore/error.rs
	src/libcore/fmt/mod.rs
	src/libcore/iter.rs
	src/libcore/marker.rs
	src/libcore/ops.rs
	src/libcore/result.rs
	src/libcore/slice.rs
	src/libcore/str/mod.rs
	src/libregex/lib.rs
	src/libregex/re.rs
	src/librustc/lint/builtin.rs
	src/libstd/collections/hash/map.rs
	src/libstd/collections/hash/set.rs
	src/libstd/sync/mpsc/mod.rs
	src/libstd/sync/mutex.rs
	src/libstd/sync/poison.rs
	src/libstd/sync/rwlock.rs
	src/libsyntax/feature_gate.rs
	src/libsyntax/test.rs
Diffstat (limited to 'src/libsyntax/diagnostics')
-rw-r--r--src/libsyntax/diagnostics/macros.rs14
-rw-r--r--src/libsyntax/diagnostics/plugin.rs21
2 files changed, 28 insertions, 7 deletions
diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs
index 34a193dffd3..9321d3ca3df 100644
--- a/src/libsyntax/diagnostics/macros.rs
+++ b/src/libsyntax/diagnostics/macros.rs
@@ -15,6 +15,14 @@ macro_rules! register_diagnostic {
 }
 
 #[macro_export]
+macro_rules! span_fatal {
+    ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
+        __diagnostic_used!($code);
+        $session.span_fatal_with_code($span, format!($($message)*).as_slice(), stringify!($code))
+    })
+}
+
+#[macro_export]
 macro_rules! span_err {
     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
         __diagnostic_used!($code);
@@ -51,3 +59,9 @@ macro_rules! register_diagnostics {
     )
 }
 
+#[macro_export]
+macro_rules! register_long_diagnostics {
+    ($($code:tt: $description:tt),*) => (
+        $(register_diagnostic! { $code, $description })*
+    )
+}
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs
index 1469c50061c..bd5247bbad6 100644
--- a/src/libsyntax/diagnostics/plugin.rs
+++ b/src/libsyntax/diagnostics/plugin.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use std::cell::RefCell;
-use std::collections::HashMap;
+use std::collections::BTreeMap;
 use ast;
 use ast::{Ident, Name, TokenTree};
 use codemap::Span;
@@ -19,18 +19,18 @@ use parse::token;
 use ptr::P;
 
 thread_local! {
-    static REGISTERED_DIAGNOSTICS: RefCell<HashMap<Name, Option<Name>>> = {
-        RefCell::new(HashMap::new())
+    static REGISTERED_DIAGNOSTICS: RefCell<BTreeMap<Name, Option<Name>>> = {
+        RefCell::new(BTreeMap::new())
     }
 }
 thread_local! {
-    static USED_DIAGNOSTICS: RefCell<HashMap<Name, Span>> = {
-        RefCell::new(HashMap::new())
+    static USED_DIAGNOSTICS: RefCell<BTreeMap<Name, Span>> = {
+        RefCell::new(BTreeMap::new())
     }
 }
 
 fn with_registered_diagnostics<T, F>(f: F) -> T where
-    F: FnOnce(&mut HashMap<Name, Option<Name>>) -> T,
+    F: FnOnce(&mut BTreeMap<Name, Option<Name>>) -> T,
 {
     REGISTERED_DIAGNOSTICS.with(move |slot| {
         f(&mut *slot.borrow_mut())
@@ -38,7 +38,7 @@ fn with_registered_diagnostics<T, F>(f: F) -> T where
 }
 
 fn with_used_diagnostics<T, F>(f: F) -> T where
-    F: FnOnce(&mut HashMap<Name, Span>) -> T,
+    F: FnOnce(&mut BTreeMap<Name, Span>) -> T,
 {
     USED_DIAGNOSTICS.with(move |slot| {
         f(&mut *slot.borrow_mut())
@@ -65,6 +65,13 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
         }
         ()
     });
+    with_registered_diagnostics(|diagnostics| {
+        if !diagnostics.contains_key(&code.name) {
+            ecx.span_err(span, &format!(
+                "used diagnostic code {} not registered", token::get_ident(code).get()
+            )[]);
+        }
+    });
     MacExpr::new(quote_expr!(ecx, ()))
 }