@@ -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. 
@@ -224,23 +224,24 @@ pub trait Emitter: Translate {
224224
225225    fn  source_map ( & self )  -> Option < & Lrc < SourceMap > > ; 
226226
227+     /// njn: update comment 
227228     /// Formats the substitutions of the primary_span 
228229     /// 
229230     /// There are a lot of conditions to this method, but in short: 
230231     /// 
231232     /// * If the current `Diagnostic` has only one visible `CodeSuggestion`, 
232233     ///   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. 
234236     /// 
235237     /// * 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 ( 
238240        & mut  self , 
239-         diag :  & ' a  Diagnostic , 
241+         primary_span :  & mut  MultiSpan , 
242+         suggestions :  & mut  Vec < CodeSuggestion > , 
240243        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+     )  { 
244245        if  let  Some ( ( sugg,  rest) )  = suggestions. split_first ( )  { 
245246            let  msg = self . translate_message ( & sugg. msg ,  fluent_args) . map_err ( Report :: new) . unwrap ( ) ; 
246247            if  rest. is_empty ( )  &&
@@ -287,16 +288,15 @@ pub trait Emitter: Translate {
287288                primary_span. push_span_label ( sugg. substitutions [ 0 ] . parts [ 0 ] . span ,  msg) ; 
288289
289290                // We return only the modified primary_span 
290-                 ( primary_span ,   & [ ] ) 
291+                 suggestions . clear ( ) ; 
291292            }  else  { 
292293                // if there are multiple suggestions, print them all in full 
293294                // to be consistent. We could try to figure out if we can 
294295                // make one (or the first one) inline, but that would give 
295296                // undue importance to a semi-random suggestion 
296-                 ( primary_span,  suggestions) 
297297            } 
298298        }  else  { 
299-             ( primary_span ,  suggestions ) 
299+             // do nothing 
300300        } 
301301    } 
302302
@@ -518,16 +518,15 @@ impl Emitter for HumanEmitter {
518518        self . sm . as_ref ( ) 
519519    } 
520520
521-     fn  emit_diagnostic ( & mut  self ,  diag :  & Diagnostic )  { 
521+     fn  emit_diagnostic ( & mut  self ,  mut   diag :  Diagnostic )  { 
522522        let  fluent_args = to_fluent_args ( diag. args ( ) ) ; 
523523
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) ; 
527526
528527        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 , 
531530            & diag. level , 
532531            self . macro_backtrace , 
533532        ) ; 
@@ -537,9 +536,9 @@ impl Emitter for HumanEmitter {
537536            & diag. messages , 
538537            & fluent_args, 
539538            & diag. code , 
540-             & primary_span , 
541-             & children, 
542-             suggestions, 
539+             & diag . span , 
540+             & diag . children , 
541+             & suggestions, 
543542            self . track_diagnostics . then_some ( & diag. emitted_at ) , 
544543        ) ; 
545544    } 
@@ -576,9 +575,8 @@ impl Emitter for SilentEmitter {
576575        None 
577576    } 
578577
579-     fn  emit_diagnostic ( & mut  self ,  d :  & Diagnostic )  { 
578+     fn  emit_diagnostic ( & mut  self ,  mut   d :  Diagnostic )  { 
580579        if  d. level  == Level :: Fatal  { 
581-             let  mut  d = d. clone ( ) ; 
582580            if  let  Some ( ref  note)  = self . fatal_note  { 
583581                d. note ( note. clone ( ) ) ; 
584582            } 
0 commit comments