@@ -20,6 +20,9 @@ use parse::token;
2020use ptr:: P ;
2121use 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+
2326thread_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