@@ -193,7 +193,7 @@ pub type DynEmitter = dyn Emitter + DynSend;
193193/// Emitter trait for emitting errors.
194194pub trait Emitter : Translate {
195195 /// Emit a structured diagnostic.
196- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) ;
196+ fn emit_diagnostic ( & mut self , diag : Diagnostic ) ;
197197
198198 /// Emit a notification that an artifact has been output.
199199 /// Currently only supported for the JSON format.
@@ -230,17 +230,17 @@ pub trait Emitter: Translate {
230230 ///
231231 /// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
232232 /// 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.
234235 ///
235236 /// * 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 (
238239 & mut self ,
239- diag : & ' a Diagnostic ,
240+ primary_span : & mut MultiSpan ,
241+ suggestions : & mut Vec < CodeSuggestion > ,
240242 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+ ) {
244244 if let Some ( ( sugg, rest) ) = suggestions. split_first ( ) {
245245 let msg = self . translate_message ( & sugg. msg , fluent_args) . map_err ( Report :: new) . unwrap ( ) ;
246246 if rest. is_empty ( ) &&
@@ -287,16 +287,15 @@ pub trait Emitter: Translate {
287287 primary_span. push_span_label ( sugg. substitutions [ 0 ] . parts [ 0 ] . span , msg) ;
288288
289289 // We return only the modified primary_span
290- ( primary_span , & [ ] )
290+ suggestions . clear ( ) ;
291291 } else {
292292 // if there are multiple suggestions, print them all in full
293293 // to be consistent. We could try to figure out if we can
294294 // make one (or the first one) inline, but that would give
295295 // undue importance to a semi-random suggestion
296- ( primary_span, suggestions)
297296 }
298297 } else {
299- ( primary_span , suggestions )
298+ // do nothing
300299 }
301300 }
302301
@@ -518,16 +517,15 @@ impl Emitter for HumanEmitter {
518517 self . sm . as_ref ( )
519518 }
520519
521- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) {
520+ fn emit_diagnostic ( & mut self , mut diag : Diagnostic ) {
522521 let fluent_args = to_fluent_args ( diag. args ( ) ) ;
523522
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) ;
527525
528526 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 ,
531529 & diag. level ,
532530 self . macro_backtrace ,
533531 ) ;
@@ -537,9 +535,9 @@ impl Emitter for HumanEmitter {
537535 & diag. messages ,
538536 & fluent_args,
539537 & diag. code ,
540- & primary_span ,
541- & children,
542- suggestions,
538+ & diag . span ,
539+ & diag . children ,
540+ & suggestions,
543541 self . track_diagnostics . then_some ( & diag. emitted_at ) ,
544542 ) ;
545543 }
@@ -576,9 +574,8 @@ impl Emitter for SilentEmitter {
576574 None
577575 }
578576
579- fn emit_diagnostic ( & mut self , diag : & Diagnostic ) {
577+ fn emit_diagnostic ( & mut self , mut diag : Diagnostic ) {
580578 if diag. level == Level :: Fatal {
581- let mut diag = diag. clone ( ) ;
582579 diag. note ( self . fatal_note . clone ( ) ) ;
583580 self . fatal_dcx . emit_diagnostic ( diag) ;
584581 }
0 commit comments