@@ -312,6 +312,9 @@ struct HandlerInner {
312312 /// The stashed diagnostics count towards the total error count.
313313 /// When `.abort_if_errors()` is called, these are also emitted.
314314 stashed_diagnostics : FxIndexMap < ( Span , StashKey ) , Diagnostic > ,
315+
316+ /// The warning count, used for a recap upon finishing
317+ deduplicated_warn_count : usize ,
315318}
316319
317320/// A key denoting where from a diagnostic was stashed.
@@ -414,6 +417,7 @@ impl Handler {
414417 flags,
415418 err_count : 0 ,
416419 deduplicated_err_count : 0 ,
420+ deduplicated_warn_count : 0 ,
417421 emitter,
418422 delayed_span_bugs : Vec :: new ( ) ,
419423 taught_diagnostics : Default :: default ( ) ,
@@ -439,6 +443,7 @@ impl Handler {
439443 let mut inner = self . inner . borrow_mut ( ) ;
440444 inner. err_count = 0 ;
441445 inner. deduplicated_err_count = 0 ;
446+ inner. deduplicated_warn_count = 0 ;
442447
443448 // actually free the underlying memory (which `clear` would not do)
444449 inner. delayed_span_bugs = Default :: default ( ) ;
@@ -745,6 +750,8 @@ impl HandlerInner {
745750 self . emitter . emit_diagnostic ( diagnostic) ;
746751 if diagnostic. is_error ( ) {
747752 self . deduplicated_err_count += 1 ;
753+ } else if diagnostic. level == Warning {
754+ self . deduplicated_warn_count += 1 ;
748755 }
749756 }
750757 if diagnostic. is_error ( ) {
@@ -763,16 +770,30 @@ impl HandlerInner {
763770 fn print_error_count ( & mut self , registry : & Registry ) {
764771 self . emit_stashed_diagnostics ( ) ;
765772
766- let s = match self . deduplicated_err_count {
767- 0 => return ,
773+ let warnings = match self . deduplicated_warn_count {
774+ 0 => String :: new ( ) ,
775+ 1 => "1 warning emitted" . to_string ( ) ,
776+ count => format ! ( "{} warnings emitted" , count) ,
777+ } ;
778+ let errors = match self . deduplicated_err_count {
779+ 0 => String :: new ( ) ,
768780 1 => "aborting due to previous error" . to_string ( ) ,
769781 count => format ! ( "aborting due to {} previous errors" , count) ,
770782 } ;
771783 if self . treat_err_as_bug ( ) {
772784 return ;
773785 }
774786
775- let _ = self . fatal ( & s) ;
787+ match ( errors. len ( ) , warnings. len ( ) ) {
788+ ( 0 , 0 ) => return ,
789+ ( 0 , _) => self . emit_diagnostic ( & Diagnostic :: new ( Level :: Warning , & warnings) ) ,
790+ ( _, 0 ) => {
791+ let _ = self . fatal ( & errors) ;
792+ }
793+ ( _, _) => {
794+ let _ = self . fatal ( & format ! ( "{}; {}" , & errors, & warnings) ) ;
795+ }
796+ }
776797
777798 let can_show_explain = self . emitter . should_show_explain ( ) ;
778799 let are_there_diagnostics = !self . emitted_diagnostic_codes . is_empty ( ) ;
0 commit comments