Skip to content

Commit e3f5ad6

Browse files
committed
Validate format of extended error descriptions.
1 parent c773442 commit e3f5ad6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libsyntax/diagnostics/plugin.rs

+12
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
9292
}
9393
_ => unreachable!()
9494
};
95+
// Check that the description starts and ends with a newline.
96+
description.map(|raw_msg| {
97+
let msg = raw_msg.as_str();
98+
let last = msg.len() - 1;
99+
if &msg[0..1] != "\n" || &msg[last..] != "\n" {
100+
ecx.span_err(span, &format!(
101+
"description for error code {} doesn't start and end with a newline",
102+
token::get_ident(*code)
103+
));
104+
}
105+
raw_msg
106+
});
95107
with_registered_diagnostics(|diagnostics| {
96108
if diagnostics.insert(code.name, description).is_some() {
97109
ecx.span_err(span, &format!(

0 commit comments

Comments
 (0)