@@ -20,6 +20,9 @@ use parse::token;
20
20
use ptr:: P ;
21
21
use util:: small_vector:: SmallVector ;
22
22
23
+ // Maximum width of any line in an extended error description (inclusive).
24
+ const MAX_DESCRIPTION_WIDTH : usize = 80 ;
25
+
23
26
thread_local ! {
24
27
static REGISTERED_DIAGNOSTICS : RefCell <BTreeMap <Name , Option <Name >>> = {
25
28
RefCell :: new( BTreeMap :: new( ) )
@@ -92,16 +95,22 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
92
95
}
93
96
_ => unreachable ! ( )
94
97
} ;
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.
96
100
description. map ( |raw_msg| {
97
101
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 " ) {
100
103
ecx. span_err ( span, & format ! (
101
104
"description for error code {} doesn't start and end with a newline" ,
102
105
token:: get_ident( * code)
103
106
) ) ;
104
107
}
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
+ }
105
114
raw_msg
106
115
} ) ;
107
116
with_registered_diagnostics ( |diagnostics| {
0 commit comments