From dd5eed4b8136849537d1b2c8655bd29dc976d89a Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Sat, 11 Apr 2015 08:14:38 +1000 Subject: Validate format of extended error descriptions. --- src/libsyntax/diagnostics/plugin.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 59fe3658437..de7964c9230 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -92,6 +92,18 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, } _ => unreachable!() }; + // Check that the description starts and ends with a newline. + description.map(|raw_msg| { + let msg = raw_msg.as_str(); + let last = msg.len() - 1; + if &msg[0..1] != "\n" || &msg[last..] != "\n" { + ecx.span_err(span, &format!( + "description for error code {} doesn't start and end with a newline", + token::get_ident(*code) + )); + } + raw_msg + }); with_registered_diagnostics(|diagnostics| { if diagnostics.insert(code.name, description).is_some() { ecx.span_err(span, &format!( -- cgit 1.4.1-3-g733a5