@@ -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.
@@ -230,17 +230,17 @@ pub trait Emitter: Translate {
230
230
///
231
231
/// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
232
232
/// we format the `help` suggestion depending on the content of the
233
- /// substitutions. In that case, we return the modified span only.
233
+ /// substitutions. In that case, we modify the span and clear the
234
+ /// suggestions.
234
235
///
235
236
/// * If the current `Diagnostic` has multiple suggestions,
236
- /// we return the original `primary_span` and the original suggestions.
237
- fn primary_span_formatted < ' a > (
237
+ /// we leave `primary_span` and the suggestions untouched .
238
+ fn primary_span_formatted (
238
239
& mut self ,
239
- diag : & ' a Diagnostic ,
240
+ primary_span : & mut MultiSpan ,
241
+ suggestions : & mut Vec < CodeSuggestion > ,
240
242
fluent_args : & FluentArgs < ' _ > ,
241
- ) -> ( MultiSpan , & ' a [ CodeSuggestion ] ) {
242
- let mut primary_span = diag. span . clone ( ) ;
243
- let suggestions = diag. suggestions . as_deref ( ) . unwrap_or ( & [ ] ) ;
243
+ ) {
244
244
if let Some ( ( sugg, rest) ) = suggestions. split_first ( ) {
245
245
let msg = self . translate_message ( & sugg. msg , fluent_args) . map_err ( Report :: new) . unwrap ( ) ;
246
246
if rest. is_empty ( ) &&
@@ -287,16 +287,15 @@ pub trait Emitter: Translate {
287
287
primary_span. push_span_label ( sugg. substitutions [ 0 ] . parts [ 0 ] . span , msg) ;
288
288
289
289
// We return only the modified primary_span
290
- ( primary_span , & [ ] )
290
+ suggestions . clear ( ) ;
291
291
} else {
292
292
// if there are multiple suggestions, print them all in full
293
293
// to be consistent. We could try to figure out if we can
294
294
// make one (or the first one) inline, but that would give
295
295
// undue importance to a semi-random suggestion
296
- ( primary_span, suggestions)
297
296
}
298
297
} else {
299
- ( primary_span , suggestions )
298
+ // do nothing
300
299
}
301
300
}
302
301
@@ -518,16 +517,15 @@ impl Emitter for HumanEmitter {
518
517
self . sm . as_ref ( )
519
518
}
520
519
521
- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) {
520
+ fn emit_diagnostic ( & mut self , mut diag : Diagnostic ) {
522
521
let fluent_args = to_fluent_args ( diag. args ( ) ) ;
523
522
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) ;
523
+ let mut suggestions = diag. suggestions . unwrap_or ( vec ! [ ] ) ;
524
+ self . primary_span_formatted ( & mut diag. span , & mut suggestions, & fluent_args) ;
527
525
528
526
self . fix_multispans_in_extern_macros_and_render_macro_backtrace (
529
- & mut primary_span ,
530
- & mut children,
527
+ & mut diag . span ,
528
+ & mut diag . children ,
531
529
& diag. level ,
532
530
self . macro_backtrace ,
533
531
) ;
@@ -537,9 +535,9 @@ impl Emitter for HumanEmitter {
537
535
& diag. messages ,
538
536
& fluent_args,
539
537
& diag. code ,
540
- & primary_span ,
541
- & children,
542
- suggestions,
538
+ & diag . span ,
539
+ & diag . children ,
540
+ & suggestions,
543
541
self . track_diagnostics . then_some ( & diag. emitted_at ) ,
544
542
) ;
545
543
}
@@ -576,9 +574,8 @@ impl Emitter for SilentEmitter {
576
574
None
577
575
}
578
576
579
- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) {
577
+ fn emit_diagnostic ( & mut self , mut diag : Diagnostic ) {
580
578
if diag. level == Level :: Fatal {
581
- let mut diag = diag. clone ( ) ;
582
579
diag. note ( self . fatal_note . clone ( ) ) ;
583
580
self . fatal_dcx . emit_diagnostic ( diag) ;
584
581
}
0 commit comments