about summary refs log tree commit diff
path: root/src/libsyntax/diagnostics
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-18 19:24:06 +0000
committerbors <bors@rust-lang.org>2015-04-18 19:24:06 +0000
commit49a94f29bbe49bd26d14cbf87b0955bd4befb8c1 (patch)
tree708d53e4b619fb227aefd191af1d7be2f4121d2a /src/libsyntax/diagnostics
parenta81ce5f991148b3c701c6b4276cdcafe366cd8f4 (diff)
parent88601f8d7d0784a2fe502193b9d98edd3e7d88ea (diff)
downloadrust-49a94f29bbe49bd26d14cbf87b0955bd4befb8c1.tar.gz
rust-49a94f29bbe49bd26d14cbf87b0955bd4befb8c1.zip
Auto merge of #24562 - Manishearth:rollup, r=Manishearth
- Successful merges: #24466, #24472, #24532, #24542, #24548
- Failed merges: #24552
Diffstat (limited to 'src/libsyntax/diagnostics')
-rw-r--r--src/libsyntax/diagnostics/plugin.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs
index 59fe3658437..6fcf39f0b17 100644
--- a/src/libsyntax/diagnostics/plugin.rs
+++ b/src/libsyntax/diagnostics/plugin.rs
@@ -20,6 +20,9 @@ use parse::token;
 use ptr::P;
 use util::small_vector::SmallVector;
 
+// Maximum width of any line in an extended error description (inclusive).
+const MAX_DESCRIPTION_WIDTH: usize = 80;
+
 thread_local! {
     static REGISTERED_DIAGNOSTICS: RefCell<BTreeMap<Name, Option<Name>>> = {
         RefCell::new(BTreeMap::new())
@@ -92,6 +95,24 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
         }
         _ => unreachable!()
     };
+    // Check that the description starts and ends with a newline and doesn't
+    // overflow the maximum line width.
+    description.map(|raw_msg| {
+        let msg = raw_msg.as_str();
+        if !msg.starts_with("\n") || !msg.ends_with("\n") {
+            ecx.span_err(span, &format!(
+                "description for error code {} doesn't start and end with a newline",
+                token::get_ident(*code)
+            ));
+        }
+        if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH) {
+            ecx.span_err(span, &format!(
+                "description for error code {} contains a line longer than {} characters",
+                token::get_ident(*code), MAX_DESCRIPTION_WIDTH
+            ));
+        }
+        raw_msg
+    });
     with_registered_diagnostics(|diagnostics| {
         if diagnostics.insert(code.name, description).is_some() {
             ecx.span_err(span, &format!(