about summary refs log tree commit diff
path: root/src/libsyntax/diagnostics/plugin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/diagnostics/plugin.rs')
-rw-r--r--src/libsyntax/diagnostics/plugin.rs21
1 files changed, 14 insertions, 7 deletions
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, ()))
 }