From a5fe176e9715f6e67a3ede3d204ba84b2f92ce7d Mon Sep 17 00:00:00 2001 From: Jakub Wieczorek Date: Fri, 11 Jul 2014 18:54:01 +0200 Subject: Convert a first batch of diagnostics to have error codes --- src/libsyntax/diagnostic.rs | 3 +++ src/libsyntax/diagnostics/macros.rs | 22 ++++++++++++++++++++++ src/libsyntax/diagnostics/plugin.rs | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 9bb5eae2ed2..0b26a641f8d 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -98,6 +98,9 @@ impl SpanHandler { pub fn span_warn(&self, sp: Span, msg: &str) { self.handler.emit(Some((&self.cm, sp)), msg, Warning); } + pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) { + self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Warning); + } pub fn span_note(&self, sp: Span, msg: &str) { self.handler.emit(Some((&self.cm, sp)), msg, Note); } diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index b0260e1180f..b4af7205c42 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -49,3 +49,25 @@ macro_rules! span_err( ($session).span_err_with_code($span, format!($($arg),*).as_slice(), stringify!($code)) }) ) + +#[macro_export] +macro_rules! span_warn( + ($session:expr, $span:expr, $code:ident, $($arg:expr),*) => ({ + __diagnostic_used!($code); + ($session).span_warn_with_code($span, format!($($arg),*).as_slice(), stringify!($code)) + }) +) + +#[macro_export] +macro_rules! span_note( + ($session:expr, $span:expr, $($arg:expr),*) => ({ + ($session).span_note($span, format!($($arg),*).as_slice()) + }) +) + +#[macro_export] +macro_rules! register_diagnostics( + ($($code:tt),*) => ( + $(register_diagnostic!($code))* + ) +) diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 6582d2e44c8..209296989fa 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -54,7 +54,8 @@ pub fn expand_diagnostic_used(ecx: &mut ExtCtxt, span: Span, with_registered_diagnostics(|diagnostics| { if !diagnostics.contains_key(&code.name) { ecx.span_err(span, format!( - "unknown diagnostic code {}", token::get_ident(code).get() + "unknown diagnostic code {}; add to librustc/diagnostics.rs", + token::get_ident(code).get() ).as_slice()); } () -- cgit 1.4.1-3-g733a5