Skip to content

Commit c17e78c

Browse files
committed
Enforce 80 char lines in extended errors.
1 parent c514dc6 commit c17e78c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/librustc/diagnostics.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ underscore `_` wildcard pattern can be added after all other patterns to match
5555

5656
// FIXME: Remove duplication here?
5757
E0005: r##"
58-
Patterns used to bind names must be irrefutable, that is, they must guarantee that a
59-
name will be extracted in all cases. If you encounter this error you probably need
60-
to use a `match` or `if let` to deal with the possibility of failure.
58+
Patterns used to bind names must be irrefutable, that is, they must guarantee
59+
that a name will be extracted in all cases. If you encounter this error you
60+
probably need to use a `match` or `if let` to deal with the possibility of
61+
failure.
6162
"##,
6263

6364
E0006: r##"
64-
Patterns used to bind names must be irrefutable, that is, they must guarantee that a
65-
name will be extracted in all cases. If you encounter this error you probably need
66-
to use a `match` or `if let` to deal with the possibility of failure.
65+
Patterns used to bind names must be irrefutable, that is, they must guarantee
66+
that a name will be extracted in all cases. If you encounter this error you
67+
probably need to use a `match` or `if let` to deal with the possibility of
68+
failure.
6769
"##,
6870

6971
E0007: r##"

src/libsyntax/diagnostics/plugin.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use parse::token;
2020
use ptr::P;
2121
use util::small_vector::SmallVector;
2222

23+
// Maximum width of any line in an extended error description (inclusive).
24+
const MAX_DESCRIPTION_WIDTH: usize = 80;
25+
2326
thread_local! {
2427
static REGISTERED_DIAGNOSTICS: RefCell<BTreeMap<Name, Option<Name>>> = {
2528
RefCell::new(BTreeMap::new())
@@ -92,16 +95,22 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
9295
}
9396
_ => unreachable!()
9497
};
95-
// Check that the description starts and ends with a newline.
98+
// Check that the description starts and ends with a newline and doesn't
99+
// overflow the maximum line width.
96100
description.map(|raw_msg| {
97101
let msg = raw_msg.as_str();
98-
let last = msg.len() - 1;
99-
if &msg[0..1] != "\n" || &msg[last..] != "\n" {
102+
if !msg.starts_with("\n") || !msg.ends_with("\n") {
100103
ecx.span_err(span, &format!(
101104
"description for error code {} doesn't start and end with a newline",
102105
token::get_ident(*code)
103106
));
104107
}
108+
if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH) {
109+
ecx.span_err(span, &format!(
110+
"description for error code {} contains a line longer than {} characters",
111+
token::get_ident(*code), MAX_DESCRIPTION_WIDTH
112+
));
113+
}
105114
raw_msg
106115
});
107116
with_registered_diagnostics(|diagnostics| {

0 commit comments

Comments
 (0)