Skip to content

Commit

Permalink
diagnostics: Allow long URLs in error explanations.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Jun 14, 2015
1 parent 6e7fcc4 commit 328df8e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libsyntax/diagnostics/plugin.rs
Expand Up @@ -99,6 +99,7 @@ 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| {
Expand All @@ -109,9 +110,15 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
token::get_ident(*code)
));
}
if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH) {

// URLs can be unavoidably longer than the line limit, so we allow them.
// Allowed format is: `[name]: http://rust-lang.org/`
let is_url = |l: &str| l.starts_with('[') && l.contains("]:") && l.contains("http");

if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH && !is_url(line)) {
ecx.span_err(span, &format!(
"description for error code {} contains a line longer than {} characters",
"description for error code {} contains a line longer than {} characters.\n\
if you're inserting a long URL use the footnote style to bypass this check.",
token::get_ident(*code), MAX_DESCRIPTION_WIDTH
));
}
Expand Down

0 comments on commit 328df8e

Please sign in to comment.