@@ -326,10 +326,12 @@ pub enum StashKey {
326
326
ItemNoType ,
327
327
}
328
328
329
- fn default_track_diagnostic ( _: & Diagnostic ) { }
329
+ fn default_track_diagnostic ( d : Diagnostic ) -> Diagnostic {
330
+ d
331
+ }
330
332
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 ( _ ) -> _ ) ) ;
333
335
334
336
#[ derive( Copy , Clone , Default ) ]
335
337
pub struct HandlerFlags {
@@ -359,8 +361,8 @@ impl Drop for HandlerInner {
359
361
if !self . has_errors ( ) {
360
362
let bugs = std:: mem:: replace ( & mut self . delayed_span_bugs , Vec :: new ( ) ) ;
361
363
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) ;
364
366
}
365
367
if has_bugs {
366
368
panic ! ( "no errors encountered even though `delay_span_bug` issued" ) ;
@@ -691,13 +693,14 @@ impl Handler {
691
693
self . inner . borrow_mut ( ) . force_print_diagnostic ( db)
692
694
}
693
695
694
- pub fn emit_diagnostic ( & self , diagnostic : & Diagnostic ) {
696
+ pub fn emit_diagnostic ( & self , diagnostic : Diagnostic ) {
695
697
self . inner . borrow_mut ( ) . emit_diagnostic ( diagnostic)
696
698
}
697
699
698
700
fn emit_diag_at_span ( & self , mut diag : Diagnostic , sp : impl Into < MultiSpan > ) {
699
701
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) ;
701
704
}
702
705
703
706
pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
@@ -721,10 +724,10 @@ impl HandlerInner {
721
724
/// Emit all stashed diagnostics.
722
725
fn emit_stashed_diagnostics ( & mut self ) {
723
726
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) ) ;
725
728
}
726
729
727
- fn emit_diagnostic ( & mut self , diagnostic : & Diagnostic ) {
730
+ fn emit_diagnostic ( & mut self , diagnostic : Diagnostic ) {
728
731
if diagnostic. cancelled ( ) {
729
732
return ;
730
733
}
@@ -733,7 +736,7 @@ impl HandlerInner {
733
736
return ;
734
737
}
735
738
736
- ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
739
+ let diagnostic = ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
737
740
738
741
if let Some ( ref code) = diagnostic. code {
739
742
self . emitted_diagnostic_codes . insert ( code. clone ( ) ) ;
@@ -750,7 +753,7 @@ impl HandlerInner {
750
753
// Only emit the diagnostic if we've been asked to deduplicate and
751
754
// haven't already emitted an equivalent diagnostic.
752
755
if !( self . flags . deduplicate_diagnostics && already_emitted ( self ) ) {
753
- self . emitter . emit_diagnostic ( diagnostic) ;
756
+ self . emitter . emit_diagnostic ( & diagnostic) ;
754
757
if diagnostic. is_error ( ) {
755
758
self . deduplicated_err_count += 1 ;
756
759
} else if diagnostic. level == Warning {
@@ -789,7 +792,7 @@ impl HandlerInner {
789
792
790
793
match ( errors. len ( ) , warnings. len ( ) ) {
791
794
( 0 , 0 ) => return ,
792
- ( 0 , _) => self . emit_diagnostic ( & Diagnostic :: new ( Level :: Warning , & warnings) ) ,
795
+ ( 0 , _) => self . emit_diagnostic ( Diagnostic :: new ( Level :: Warning , & warnings) ) ,
793
796
( _, 0 ) => {
794
797
let _ = self . fatal ( & errors) ;
795
798
}
@@ -865,7 +868,8 @@ impl HandlerInner {
865
868
}
866
869
867
870
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) ;
869
873
}
870
874
871
875
fn delay_span_bug ( & mut self , sp : impl Into < MultiSpan > , msg : & str ) {
@@ -882,7 +886,7 @@ impl HandlerInner {
882
886
}
883
887
884
888
fn failure ( & mut self , msg : & str ) {
885
- self . emit_diagnostic ( & Diagnostic :: new ( FailureNote , msg) ) ;
889
+ self . emit_diagnostic ( Diagnostic :: new ( FailureNote , msg) ) ;
886
890
}
887
891
888
892
fn fatal ( & mut self , msg : & str ) -> FatalError {
@@ -899,17 +903,17 @@ impl HandlerInner {
899
903
if self . treat_err_as_bug ( ) {
900
904
self . bug ( msg) ;
901
905
}
902
- self . emit_diagnostic ( & Diagnostic :: new ( level, msg) ) ;
906
+ self . emit_diagnostic ( Diagnostic :: new ( level, msg) ) ;
903
907
}
904
908
905
909
fn bug ( & mut self , msg : & str ) -> ! {
906
- self . emit_diagnostic ( & Diagnostic :: new ( Bug , msg) ) ;
910
+ self . emit_diagnostic ( Diagnostic :: new ( Bug , msg) ) ;
907
911
panic ! ( ExplicitBug ) ;
908
912
}
909
913
910
914
fn delay_as_bug ( & mut self , diagnostic : Diagnostic ) {
911
915
if self . flags . report_delayed_bugs {
912
- self . emit_diagnostic ( & diagnostic) ;
916
+ self . emit_diagnostic ( diagnostic. clone ( ) ) ;
913
917
}
914
918
self . delayed_span_bugs . push ( diagnostic) ;
915
919
}
0 commit comments