about summary refs log tree commit diff
path: root/src/libsyntax/diagnostics/plugin.rs
diff options
context:
space:
mode:
authorMichael Sproul <micsproul@gmail.com>2015-04-15 21:54:01 +1000
committerMichael Sproul <micsproul@gmail.com>2015-04-17 21:35:24 +1000
commit6d2b6d5a19224eee279c44e8ff2bb37ba331d1df (patch)
tree0106105e8f7bd7aadb15454bd247f205258c4899 /src/libsyntax/diagnostics/plugin.rs
parentc54f43a5d18c89f65f22a179e8e6d05ce9c1d36c (diff)
downloadrust-6d2b6d5a19224eee279c44e8ff2bb37ba331d1df.tar.gz
rust-6d2b6d5a19224eee279c44e8ff2bb37ba331d1df.zip
Enforce 80 char lines in extended errors.
Diffstat (limited to 'src/libsyntax/diagnostics/plugin.rs')
-rw-r--r--src/libsyntax/diagnostics/plugin.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs
index de7964c9230..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,16 +95,22 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
         }
         _ => unreachable!()
     };
-    // Check that the description starts and ends with a newline.
+    // 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();
-        let last = msg.len() - 1;
-        if &msg[0..1] != "\n" || &msg[last..] != "\n" {
+        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| {