@@ -126,20 +126,14 @@ impl Session {
126
126
sp : S ,
127
127
msg : & str )
128
128
-> DiagnosticBuilder < ' a > {
129
- match split_msg_into_multilines ( msg) {
130
- Some ( ref msg) => self . diagnostic ( ) . struct_span_err ( sp, msg) ,
131
- None => self . diagnostic ( ) . struct_span_err ( sp, msg) ,
132
- }
129
+ self . diagnostic ( ) . struct_span_err ( sp, msg)
133
130
}
134
131
pub fn struct_span_err_with_code < ' a , S : Into < MultiSpan > > ( & ' a self ,
135
132
sp : S ,
136
133
msg : & str ,
137
134
code : & str )
138
135
-> DiagnosticBuilder < ' a > {
139
- match split_msg_into_multilines ( msg) {
140
- Some ( ref msg) => self . diagnostic ( ) . struct_span_err_with_code ( sp, msg, code) ,
141
- None => self . diagnostic ( ) . struct_span_err_with_code ( sp, msg, code) ,
142
- }
136
+ self . diagnostic ( ) . struct_span_err_with_code ( sp, msg, code)
143
137
}
144
138
pub fn struct_err < ' a > ( & ' a self , msg : & str ) -> DiagnosticBuilder < ' a > {
145
139
self . diagnostic ( ) . struct_err ( msg)
@@ -178,16 +172,10 @@ impl Session {
178
172
}
179
173
}
180
174
pub fn span_err < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
181
- match split_msg_into_multilines ( msg) {
182
- Some ( msg) => self . diagnostic ( ) . span_err ( sp, & msg) ,
183
- None => self . diagnostic ( ) . span_err ( sp, msg)
184
- }
175
+ self . diagnostic ( ) . span_err ( sp, msg)
185
176
}
186
177
pub fn span_err_with_code < S : Into < MultiSpan > > ( & self , sp : S , msg : & str , code : & str ) {
187
- match split_msg_into_multilines ( msg) {
188
- Some ( msg) => self . diagnostic ( ) . span_err_with_code ( sp, & msg, code) ,
189
- None => self . diagnostic ( ) . span_err_with_code ( sp, msg, code)
190
- }
178
+ self . diagnostic ( ) . span_err_with_code ( sp, & msg, code)
191
179
}
192
180
pub fn err ( & self , msg : & str ) {
193
181
self . diagnostic ( ) . err ( msg)
@@ -343,67 +331,6 @@ impl Session {
343
331
}
344
332
}
345
333
346
- fn split_msg_into_multilines ( msg : & str ) -> Option < String > {
347
- // Conditions for enabling multi-line errors:
348
- if !msg. contains ( "mismatched types" ) &&
349
- !msg. contains ( "type mismatch resolving" ) &&
350
- !msg. contains ( "if and else have incompatible types" ) &&
351
- !msg. contains ( "if may be missing an else clause" ) &&
352
- !msg. contains ( "match arms have incompatible types" ) &&
353
- !msg. contains ( "structure constructor specifies a structure of type" ) &&
354
- !msg. contains ( "has an incompatible type for trait" ) {
355
- return None
356
- }
357
- let first = msg. match_indices ( "expected" ) . filter ( |s| {
358
- let last = msg[ ..s. 0 ] . chars ( ) . rev ( ) . next ( ) ;
359
- last == Some ( ' ' ) || last == Some ( '(' )
360
- } ) . map ( |( a, b) | ( a - 1 , a + b. len ( ) ) ) ;
361
- let second = msg. match_indices ( "found" ) . filter ( |s| {
362
- msg[ ..s. 0 ] . chars ( ) . rev ( ) . next ( ) == Some ( ' ' )
363
- } ) . map ( |( a, b) | ( a - 1 , a + b. len ( ) ) ) ;
364
-
365
- let mut new_msg = String :: new ( ) ;
366
- let mut head = 0 ;
367
-
368
- // Insert `\n` before expected and found.
369
- for ( pos1, pos2) in first. zip ( second) {
370
- new_msg = new_msg +
371
- // A `(` may be preceded by a space and it should be trimmed
372
- msg[ head..pos1. 0 ] . trim_right ( ) + // prefix
373
- "\n " + // insert before first
374
- & msg[ pos1. 0 ..pos1. 1 ] + // insert what first matched
375
- & msg[ pos1. 1 ..pos2. 0 ] + // between matches
376
- "\n " + // insert before second
377
- // 123
378
- // `expected` is 3 char longer than `found`. To align the types,
379
- // `found` gets 3 spaces prepended.
380
- & msg[ pos2. 0 ..pos2. 1 ] ; // insert what second matched
381
-
382
- head = pos2. 1 ;
383
- }
384
-
385
- let mut tail = & msg[ head..] ;
386
- let third = tail. find ( "(values differ" )
387
- . or ( tail. find ( "(lifetime" ) )
388
- . or ( tail. find ( "(cyclic type of infinite size" ) ) ;
389
- // Insert `\n` before any remaining messages which match.
390
- if let Some ( pos) = third {
391
- // The end of the message may just be wrapped in `()` without
392
- // `expected`/`found`. Push this also to a new line and add the
393
- // final tail after.
394
- new_msg = new_msg +
395
- // `(` is usually preceded by a space and should be trimmed.
396
- tail[ ..pos] . trim_right ( ) + // prefix
397
- "\n " + // insert before paren
398
- & tail[ pos..] ; // append the tail
399
-
400
- tail = "" ;
401
- }
402
-
403
- new_msg. push_str ( tail) ;
404
- return Some ( new_msg) ;
405
- }
406
-
407
334
pub fn build_session ( sopts : config:: Options ,
408
335
dep_graph : & DepGraph ,
409
336
local_crate_source_file : Option < PathBuf > ,
0 commit comments