@@ -193,7 +193,7 @@ pub type DynEmitter = dyn Emitter + DynSend;
193
193
/// Emitter trait for emitting errors.
194
194
pub trait Emitter : Translate {
195
195
/// Emit a structured diagnostic.
196
- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) ;
196
+ fn emit_diagnostic ( & mut self , diag : Diagnostic ) ;
197
197
198
198
/// Emit a notification that an artifact has been output.
199
199
/// Currently only supported for the JSON format.
@@ -224,23 +224,24 @@ pub trait Emitter: Translate {
224
224
225
225
fn source_map ( & self ) -> Option < & Lrc < SourceMap > > ;
226
226
227
+ /// njn: update comment
227
228
/// Formats the substitutions of the primary_span
228
229
///
229
230
/// There are a lot of conditions to this method, but in short:
230
231
///
231
232
/// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
232
233
/// we format the `help` suggestion depending on the content of the
233
- /// substitutions. In that case, we return the modified span only.
234
+ /// substitutions. In that case, we modify the span and clear the
235
+ /// suggestions.
234
236
///
235
237
/// * If the current `Diagnostic` has multiple suggestions,
236
- /// we return the original `primary_span` and the original suggestions.
237
- fn primary_span_formatted < ' a > (
238
+ /// we leave `primary_span` and the suggestions untouched .
239
+ fn primary_span_formatted (
238
240
& mut self ,
239
- diag : & ' a Diagnostic ,
241
+ primary_span : & mut MultiSpan ,
242
+ suggestions : & mut Vec < CodeSuggestion > ,
240
243
fluent_args : & FluentArgs < ' _ > ,
241
- ) -> ( MultiSpan , & ' a [ CodeSuggestion ] ) {
242
- let mut primary_span = diag. span . clone ( ) ;
243
- let suggestions = diag. suggestions . as_deref ( ) . unwrap_or ( & [ ] ) ;
244
+ ) {
244
245
if let Some ( ( sugg, rest) ) = suggestions. split_first ( ) {
245
246
let msg = self . translate_message ( & sugg. msg , fluent_args) . map_err ( Report :: new) . unwrap ( ) ;
246
247
if rest. is_empty ( ) &&
@@ -287,16 +288,15 @@ pub trait Emitter: Translate {
287
288
primary_span. push_span_label ( sugg. substitutions [ 0 ] . parts [ 0 ] . span , msg) ;
288
289
289
290
// We return only the modified primary_span
290
- ( primary_span , & [ ] )
291
+ suggestions . clear ( ) ;
291
292
} else {
292
293
// if there are multiple suggestions, print them all in full
293
294
// to be consistent. We could try to figure out if we can
294
295
// make one (or the first one) inline, but that would give
295
296
// undue importance to a semi-random suggestion
296
- ( primary_span, suggestions)
297
297
}
298
298
} else {
299
- ( primary_span , suggestions )
299
+ // do nothing
300
300
}
301
301
}
302
302
@@ -518,16 +518,15 @@ impl Emitter for HumanEmitter {
518
518
self . sm . as_ref ( )
519
519
}
520
520
521
- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) {
521
+ fn emit_diagnostic ( & mut self , mut diag : Diagnostic ) {
522
522
let fluent_args = to_fluent_args ( diag. args ( ) ) ;
523
523
524
- let mut children = diag. children . clone ( ) ;
525
- let ( mut primary_span, suggestions) = self . primary_span_formatted ( diag, & fluent_args) ;
526
- debug ! ( "emit_diagnostic: suggestions={:?}" , suggestions) ;
524
+ let mut suggestions = diag. suggestions . unwrap_or ( vec ! [ ] ) ;
525
+ self . primary_span_formatted ( & mut diag. span , & mut suggestions, & fluent_args) ;
527
526
528
527
self . fix_multispans_in_extern_macros_and_render_macro_backtrace (
529
- & mut primary_span ,
530
- & mut children,
528
+ & mut diag . span ,
529
+ & mut diag . children ,
531
530
& diag. level ,
532
531
self . macro_backtrace ,
533
532
) ;
@@ -537,9 +536,9 @@ impl Emitter for HumanEmitter {
537
536
& diag. messages ,
538
537
& fluent_args,
539
538
& diag. code ,
540
- & primary_span ,
541
- & children,
542
- suggestions,
539
+ & diag . span ,
540
+ & diag . children ,
541
+ & suggestions,
543
542
self . track_diagnostics . then_some ( & diag. emitted_at ) ,
544
543
) ;
545
544
}
@@ -576,9 +575,8 @@ impl Emitter for SilentEmitter {
576
575
None
577
576
}
578
577
579
- fn emit_diagnostic ( & mut self , d : & Diagnostic ) {
578
+ fn emit_diagnostic ( & mut self , mut d : Diagnostic ) {
580
579
if d. level == Level :: Fatal {
581
- let mut d = d. clone ( ) ;
582
580
if let Some ( ref note) = self . fatal_note {
583
581
d. note ( note. clone ( ) ) ;
584
582
}
0 commit comments