@@ -142,43 +142,34 @@ pub fn extract_rendered(output: &str) -> String {
142
142
}
143
143
144
144
pub fn parse_output ( file_name : & str , output : & str , proc_res : & ProcRes ) -> Vec < Error > {
145
- output. lines ( ) . flat_map ( |line| parse_line ( file_name, line, output, proc_res) ) . collect ( )
146
- }
147
-
148
- fn parse_line ( file_name : & str , line : & str , output : & str , proc_res : & ProcRes ) -> Vec < Error > {
149
- // The compiler sometimes intermingles non-JSON stuff into the
150
- // output. This hack just skips over such lines. Yuck.
151
- if line. starts_with ( '{' ) {
152
- match serde_json:: from_str :: < Diagnostic > ( line) {
153
- Ok ( diagnostic) => {
154
- let mut expected_errors = vec ! [ ] ;
155
- push_expected_errors ( & mut expected_errors, & diagnostic, & [ ] , file_name) ;
156
- expected_errors
157
- }
158
- Err ( error) => {
159
- // Ignore the future compat report message - this is handled
160
- // by `extract_rendered`
161
- if serde_json:: from_str :: < FutureIncompatReport > ( line) . is_ok ( ) {
162
- vec ! [ ]
163
- } else {
164
- proc_res. fatal (
145
+ let mut errors = Vec :: new ( ) ;
146
+ for line in output. lines ( ) {
147
+ // The compiler sometimes intermingles non-JSON stuff into the
148
+ // output. This hack just skips over such lines. Yuck.
149
+ if line. starts_with ( '{' ) {
150
+ match serde_json:: from_str :: < Diagnostic > ( line) {
151
+ Ok ( diagnostic) => push_actual_errors ( & mut errors, & diagnostic, & [ ] , file_name) ,
152
+ Err ( error) => {
153
+ // Ignore the future compat report message - this is handled
154
+ // by `extract_rendered`
155
+ if serde_json:: from_str :: < FutureIncompatReport > ( line) . is_err ( ) {
156
+ proc_res. fatal (
165
157
Some ( & format ! (
166
- "failed to decode compiler output as json: \
167
- `{}`\n line: {}\n output: {}",
158
+ "failed to decode compiler output as json: `{}`\n line: {}\n output: {}" ,
168
159
error, line, output
169
160
) ) ,
170
161
|| ( ) ,
171
162
) ;
163
+ }
172
164
}
173
165
}
174
166
}
175
- } else {
176
- vec ! [ ]
177
167
}
168
+ errors
178
169
}
179
170
180
- fn push_expected_errors (
181
- expected_errors : & mut Vec < Error > ,
171
+ fn push_actual_errors (
172
+ errors : & mut Vec < Error > ,
182
173
diagnostic : & Diagnostic ,
183
174
default_spans : & [ & DiagnosticSpan ] ,
184
175
file_name : & str ,
@@ -236,10 +227,10 @@ fn push_expected_errors(
236
227
}
237
228
} ;
238
229
239
- // Convert multi-line messages into multiple expected
240
- // errors. We expect to replace these with something
241
- // more structured shortly anyhow.
230
+ // Convert multi-line messages into multiple errors.
231
+ // We expect to replace these with something more structured anyhow.
242
232
let mut message_lines = diagnostic. message . lines ( ) ;
233
+ let kind = ErrorKind :: from_str ( & diagnostic. level ) . ok ( ) ;
243
234
if let Some ( first_line) = message_lines. next ( ) {
244
235
let ignore = |s| {
245
236
static RE : OnceLock < Regex > = OnceLock :: new ( ) ;
@@ -250,27 +241,23 @@ fn push_expected_errors(
250
241
} ;
251
242
252
243
if primary_spans. is_empty ( ) && !ignore ( first_line) {
253
- let msg = with_code ( None , first_line) ;
254
- let kind = ErrorKind :: from_str ( & diagnostic. level ) . ok ( ) ;
255
- expected_errors. push ( Error { line_num : None , kind, msg } ) ;
244
+ errors. push ( Error { line_num : None , kind, msg : with_code ( None , first_line) } ) ;
256
245
} else {
257
246
for span in primary_spans {
258
- let msg = with_code ( Some ( span) , first_line) ;
259
- let kind = ErrorKind :: from_str ( & diagnostic. level ) . ok ( ) ;
260
- expected_errors. push ( Error { line_num : Some ( span. line_start ) , kind, msg } ) ;
247
+ errors. push ( Error {
248
+ line_num : Some ( span. line_start ) ,
249
+ kind,
250
+ msg : with_code ( Some ( span) , first_line) ,
251
+ } ) ;
261
252
}
262
253
}
263
254
}
264
255
for next_line in message_lines {
265
256
if primary_spans. is_empty ( ) {
266
- expected_errors. push ( Error {
267
- line_num : None ,
268
- kind : None ,
269
- msg : with_code ( None , next_line) ,
270
- } ) ;
257
+ errors. push ( Error { line_num : None , kind : None , msg : with_code ( None , next_line) } ) ;
271
258
} else {
272
259
for span in primary_spans {
273
- expected_errors . push ( Error {
260
+ errors . push ( Error {
274
261
line_num : Some ( span. line_start ) ,
275
262
kind : None ,
276
263
msg : with_code ( Some ( span) , next_line) ,
@@ -283,7 +270,7 @@ fn push_expected_errors(
283
270
for span in primary_spans {
284
271
if let Some ( ref suggested_replacement) = span. suggested_replacement {
285
272
for ( index, line) in suggested_replacement. lines ( ) . enumerate ( ) {
286
- expected_errors . push ( Error {
273
+ errors . push ( Error {
287
274
line_num : Some ( span. line_start + index) ,
288
275
kind : Some ( ErrorKind :: Suggestion ) ,
289
276
msg : line. to_string ( ) ,
@@ -295,13 +282,13 @@ fn push_expected_errors(
295
282
// Add notes for the backtrace
296
283
for span in primary_spans {
297
284
if let Some ( frame) = & span. expansion {
298
- push_backtrace ( expected_errors , frame, file_name) ;
285
+ push_backtrace ( errors , frame, file_name) ;
299
286
}
300
287
}
301
288
302
289
// Add notes for any labels that appear in the message.
303
290
for span in spans_in_this_file. iter ( ) . filter ( |span| span. label . is_some ( ) ) {
304
- expected_errors . push ( Error {
291
+ errors . push ( Error {
305
292
line_num : Some ( span. line_start ) ,
306
293
kind : Some ( ErrorKind :: Note ) ,
307
294
msg : span. label . clone ( ) . unwrap ( ) ,
@@ -310,24 +297,24 @@ fn push_expected_errors(
310
297
311
298
// Flatten out the children.
312
299
for child in & diagnostic. children {
313
- push_expected_errors ( expected_errors , child, primary_spans, file_name) ;
300
+ push_actual_errors ( errors , child, primary_spans, file_name) ;
314
301
}
315
302
}
316
303
317
304
fn push_backtrace (
318
- expected_errors : & mut Vec < Error > ,
305
+ errors : & mut Vec < Error > ,
319
306
expansion : & DiagnosticSpanMacroExpansion ,
320
307
file_name : & str ,
321
308
) {
322
309
if Path :: new ( & expansion. span . file_name ) == Path :: new ( & file_name) {
323
- expected_errors . push ( Error {
310
+ errors . push ( Error {
324
311
line_num : Some ( expansion. span . line_start ) ,
325
312
kind : Some ( ErrorKind :: Note ) ,
326
313
msg : format ! ( "in this expansion of {}" , expansion. macro_decl_name) ,
327
314
} ) ;
328
315
}
329
316
330
317
if let Some ( previous_expansion) = & expansion. span . expansion {
331
- push_backtrace ( expected_errors , previous_expansion, file_name) ;
318
+ push_backtrace ( errors , previous_expansion, file_name) ;
332
319
}
333
320
}
0 commit comments