@@ -326,10 +326,12 @@ pub enum StashKey {
326326 ItemNoType ,
327327}
328328
329- fn default_track_diagnostic ( _: & Diagnostic ) { }
329+ fn default_track_diagnostic ( d : Diagnostic ) -> Diagnostic {
330+ d
331+ }
330332
331- pub static TRACK_DIAGNOSTICS : AtomicRef < fn ( & Diagnostic ) > =
332- AtomicRef :: new ( & ( default_track_diagnostic as fn ( & _ ) ) ) ;
333+ pub static TRACK_DIAGNOSTICS : AtomicRef < fn ( Diagnostic ) -> Diagnostic > =
334+ AtomicRef :: new ( & ( default_track_diagnostic as fn ( _ ) -> _ ) ) ;
333335
334336#[ derive( Copy , Clone , Default ) ]
335337pub struct HandlerFlags {
@@ -359,8 +361,8 @@ impl Drop for HandlerInner {
359361 if !self . has_errors ( ) {
360362 let bugs = std:: mem:: replace ( & mut self . delayed_span_bugs , Vec :: new ( ) ) ;
361363 let has_bugs = !bugs. is_empty ( ) ;
362- for bug in bugs {
363- self . emit_diagnostic ( & bug) ;
364+ for bug in bugs. into_iter ( ) {
365+ self . emit_diagnostic ( bug) ;
364366 }
365367 if has_bugs {
366368 panic ! ( "no errors encountered even though `delay_span_bug` issued" ) ;
@@ -691,13 +693,14 @@ impl Handler {
691693 self . inner . borrow_mut ( ) . force_print_diagnostic ( db)
692694 }
693695
694- pub fn emit_diagnostic ( & self , diagnostic : & Diagnostic ) {
696+ pub fn emit_diagnostic ( & self , diagnostic : Diagnostic ) {
695697 self . inner . borrow_mut ( ) . emit_diagnostic ( diagnostic)
696698 }
697699
698700 fn emit_diag_at_span ( & self , mut diag : Diagnostic , sp : impl Into < MultiSpan > ) {
699701 let mut inner = self . inner . borrow_mut ( ) ;
700- inner. emit_diagnostic ( diag. set_span ( sp) ) ;
702+ diag. set_span ( sp) ;
703+ inner. emit_diagnostic ( diag) ;
701704 }
702705
703706 pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
@@ -721,10 +724,10 @@ impl HandlerInner {
721724 /// Emit all stashed diagnostics.
722725 fn emit_stashed_diagnostics ( & mut self ) {
723726 let diags = self . stashed_diagnostics . drain ( ..) . map ( |x| x. 1 ) . collect :: < Vec < _ > > ( ) ;
724- diags. iter ( ) . for_each ( |diag| self . emit_diagnostic ( diag) ) ;
727+ diags. into_iter ( ) . for_each ( |diag| self . emit_diagnostic ( diag) ) ;
725728 }
726729
727- fn emit_diagnostic ( & mut self , diagnostic : & Diagnostic ) {
730+ fn emit_diagnostic ( & mut self , diagnostic : Diagnostic ) {
728731 if diagnostic. cancelled ( ) {
729732 return ;
730733 }
@@ -733,7 +736,7 @@ impl HandlerInner {
733736 return ;
734737 }
735738
736- ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
739+ let diagnostic = ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
737740
738741 if let Some ( ref code) = diagnostic. code {
739742 self . emitted_diagnostic_codes . insert ( code. clone ( ) ) ;
@@ -750,7 +753,7 @@ impl HandlerInner {
750753 // Only emit the diagnostic if we've been asked to deduplicate and
751754 // haven't already emitted an equivalent diagnostic.
752755 if !( self . flags . deduplicate_diagnostics && already_emitted ( self ) ) {
753- self . emitter . emit_diagnostic ( diagnostic) ;
756+ self . emitter . emit_diagnostic ( & diagnostic) ;
754757 if diagnostic. is_error ( ) {
755758 self . deduplicated_err_count += 1 ;
756759 } else if diagnostic. level == Warning {
@@ -789,7 +792,7 @@ impl HandlerInner {
789792
790793 match ( errors. len ( ) , warnings. len ( ) ) {
791794 ( 0 , 0 ) => return ,
792- ( 0 , _) => self . emit_diagnostic ( & Diagnostic :: new ( Level :: Warning , & warnings) ) ,
795+ ( 0 , _) => self . emit_diagnostic ( Diagnostic :: new ( Level :: Warning , & warnings) ) ,
793796 ( _, 0 ) => {
794797 let _ = self . fatal ( & errors) ;
795798 }
@@ -865,7 +868,8 @@ impl HandlerInner {
865868 }
866869
867870 fn emit_diag_at_span ( & mut self , mut diag : Diagnostic , sp : impl Into < MultiSpan > ) {
868- self . emit_diagnostic ( diag. set_span ( sp) ) ;
871+ diag. set_span ( sp) ;
872+ self . emit_diagnostic ( diag) ;
869873 }
870874
871875 fn delay_span_bug ( & mut self , sp : impl Into < MultiSpan > , msg : & str ) {
@@ -882,7 +886,7 @@ impl HandlerInner {
882886 }
883887
884888 fn failure ( & mut self , msg : & str ) {
885- self . emit_diagnostic ( & Diagnostic :: new ( FailureNote , msg) ) ;
889+ self . emit_diagnostic ( Diagnostic :: new ( FailureNote , msg) ) ;
886890 }
887891
888892 fn fatal ( & mut self , msg : & str ) -> FatalError {
@@ -899,17 +903,17 @@ impl HandlerInner {
899903 if self . treat_err_as_bug ( ) {
900904 self . bug ( msg) ;
901905 }
902- self . emit_diagnostic ( & Diagnostic :: new ( level, msg) ) ;
906+ self . emit_diagnostic ( Diagnostic :: new ( level, msg) ) ;
903907 }
904908
905909 fn bug ( & mut self , msg : & str ) -> ! {
906- self . emit_diagnostic ( & Diagnostic :: new ( Bug , msg) ) ;
910+ self . emit_diagnostic ( Diagnostic :: new ( Bug , msg) ) ;
907911 panic ! ( ExplicitBug ) ;
908912 }
909913
910914 fn delay_as_bug ( & mut self , diagnostic : Diagnostic ) {
911915 if self . flags . report_delayed_bugs {
912- self . emit_diagnostic ( & diagnostic) ;
916+ self . emit_diagnostic ( diagnostic. clone ( ) ) ;
913917 }
914918 self . delayed_span_bugs . push ( diagnostic) ;
915919 }
0 commit comments