1
Fork 0

Enforce 80 char lines in extended errors.

This commit is contained in:
Michael Sproul 2015-04-15 21:54:01 +10:00
parent c54f43a5d1
commit 6d2b6d5a19
2 changed files with 20 additions and 9 deletions

View file

@ -55,15 +55,17 @@ underscore `_` wildcard pattern can be added after all other patterns to match
// FIXME: Remove duplication here? // FIXME: Remove duplication here?
E0005: r##" E0005: r##"
Patterns used to bind names must be irrefutable, that is, they must guarantee that a Patterns used to bind names must be irrefutable, that is, they must guarantee
name will be extracted in all cases. If you encounter this error you probably need that a name will be extracted in all cases. If you encounter this error you
to use a `match` or `if let` to deal with the possibility of failure. probably need to use a `match` or `if let` to deal with the possibility of
failure.
"##, "##,
E0006: r##" E0006: r##"
Patterns used to bind names must be irrefutable, that is, they must guarantee that a Patterns used to bind names must be irrefutable, that is, they must guarantee
name will be extracted in all cases. If you encounter this error you probably need that a name will be extracted in all cases. If you encounter this error you
to use a `match` or `if let` to deal with the possibility of failure. probably need to use a `match` or `if let` to deal with the possibility of
failure.
"##, "##,
E0007: r##" E0007: r##"

View file

@ -20,6 +20,9 @@ use parse::token;
use ptr::P; use ptr::P;
use util::small_vector::SmallVector; use util::small_vector::SmallVector;
// Maximum width of any line in an extended error description (inclusive).
const MAX_DESCRIPTION_WIDTH: usize = 80;
thread_local! { thread_local! {
static REGISTERED_DIAGNOSTICS: RefCell<BTreeMap<Name, Option<Name>>> = { static REGISTERED_DIAGNOSTICS: RefCell<BTreeMap<Name, Option<Name>>> = {
RefCell::new(BTreeMap::new()) RefCell::new(BTreeMap::new())
@ -92,16 +95,22 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
} }
_ => unreachable!() _ => 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| { description.map(|raw_msg| {
let msg = raw_msg.as_str(); let msg = raw_msg.as_str();
let last = msg.len() - 1; if !msg.starts_with("\n") || !msg.ends_with("\n") {
if &msg[0..1] != "\n" || &msg[last..] != "\n" {
ecx.span_err(span, &format!( ecx.span_err(span, &format!(
"description for error code {} doesn't start and end with a newline", "description for error code {} doesn't start and end with a newline",
token::get_ident(*code) 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 raw_msg
}); });
with_registered_diagnostics(|diagnostics| { with_registered_diagnostics(|diagnostics| {