@@ -539,19 +539,22 @@ impl Handler {
539539 }
540540
541541 pub fn span_fatal < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) -> FatalError {
542- self . emit ( & sp. into ( ) , msg, Fatal ) ;
542+ self . emit_diagnostic ( Diagnostic :: new ( Fatal , msg) . set_span ( sp) ) ;
543+ self . abort_if_errors_and_should_abort ( ) ;
543544 FatalError
544545 }
545546 pub fn span_fatal_with_code < S : Into < MultiSpan > > ( & self ,
546547 sp : S ,
547548 msg : & str ,
548549 code : DiagnosticId )
549550 -> FatalError {
550- self . emit_with_code ( & sp. into ( ) , msg, code, Fatal ) ;
551+ self . emit_diagnostic ( Diagnostic :: new_with_code ( Fatal , Some ( code) , msg) . set_span ( sp) ) ;
552+ self . abort_if_errors_and_should_abort ( ) ;
551553 FatalError
552554 }
553555 pub fn span_err < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
554- self . emit ( & sp. into ( ) , msg, Error ) ;
556+ self . emit_diagnostic ( Diagnostic :: new ( Error , msg) . set_span ( sp) ) ;
557+ self . abort_if_errors_and_should_abort ( ) ;
555558 }
556559 pub fn mut_span_err < S : Into < MultiSpan > > ( & self ,
557560 sp : S ,
@@ -562,16 +565,20 @@ impl Handler {
562565 result
563566 }
564567 pub fn span_err_with_code < S : Into < MultiSpan > > ( & self , sp : S , msg : & str , code : DiagnosticId ) {
565- self . emit_with_code ( & sp. into ( ) , msg, code, Error ) ;
568+ self . emit_diagnostic ( Diagnostic :: new_with_code ( Error , Some ( code) , msg) . set_span ( sp) ) ;
569+ self . abort_if_errors_and_should_abort ( ) ;
566570 }
567571 pub fn span_warn < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
568- self . emit ( & sp. into ( ) , msg, Warning ) ;
572+ self . emit_diagnostic ( Diagnostic :: new ( Warning , msg) . set_span ( sp) ) ;
573+ self . abort_if_errors_and_should_abort ( ) ;
569574 }
570575 pub fn span_warn_with_code < S : Into < MultiSpan > > ( & self , sp : S , msg : & str , code : DiagnosticId ) {
571- self . emit_with_code ( & sp. into ( ) , msg, code, Warning ) ;
576+ self . emit_diagnostic ( Diagnostic :: new_with_code ( Warning , Some ( code) , msg) . set_span ( sp) ) ;
577+ self . abort_if_errors_and_should_abort ( ) ;
572578 }
573579 pub fn span_bug < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) -> ! {
574- self . emit ( & sp. into ( ) , msg, Bug ) ;
580+ self . emit_diagnostic ( Diagnostic :: new ( Bug , msg) . set_span ( sp) ) ;
581+ self . abort_if_errors_and_should_abort ( ) ;
575582 panic ! ( ExplicitBug ) ;
576583 }
577584 pub fn delay_span_bug < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
@@ -590,10 +597,12 @@ impl Handler {
590597 self . delayed_span_bugs . borrow_mut ( ) . push ( diagnostic) ;
591598 }
592599 pub fn span_bug_no_panic < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
593- self . emit ( & sp. into ( ) , msg, Bug ) ;
600+ self . emit_diagnostic ( Diagnostic :: new ( Bug , msg) . set_span ( sp) ) ;
601+ self . abort_if_errors_and_should_abort ( ) ;
594602 }
595603 pub fn span_note_without_error < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
596- self . emit ( & sp. into ( ) , msg, Note ) ;
604+ self . emit_diagnostic ( Diagnostic :: new ( Note , msg) . set_span ( sp) ) ;
605+ self . abort_if_errors_and_should_abort ( ) ;
597606 }
598607 pub fn span_note_diag ( & self ,
599608 sp : Span ,
@@ -701,31 +710,15 @@ impl Handler {
701710 }
702711 }
703712
704- pub fn abort_if_errors ( & self ) {
705- if self . has_errors ( ) {
713+ pub fn abort_if_errors_and_should_abort ( & self ) {
714+ if self . has_errors ( ) && ! self . continue_after_error . load ( SeqCst ) {
706715 FatalError . raise ( ) ;
707716 }
708717 }
709- pub fn emit ( & self , msp : & MultiSpan , msg : & str , lvl : Level ) {
710- if lvl == Warning && !self . flags . can_emit_warnings {
711- return ;
712- }
713- let mut db = DiagnosticBuilder :: new ( self , lvl, msg) ;
714- db. set_span ( msp. clone ( ) ) ;
715- db. emit ( ) ;
716- if !self . continue_after_error . load ( SeqCst ) {
717- self . abort_if_errors ( ) ;
718- }
719- }
720- pub fn emit_with_code ( & self , msp : & MultiSpan , msg : & str , code : DiagnosticId , lvl : Level ) {
721- if lvl == Warning && !self . flags . can_emit_warnings {
722- return ;
723- }
724- let mut db = DiagnosticBuilder :: new_with_code ( self , lvl, Some ( code) , msg) ;
725- db. set_span ( msp. clone ( ) ) ;
726- db. emit ( ) ;
727- if !self . continue_after_error . load ( SeqCst ) {
728- self . abort_if_errors ( ) ;
718+
719+ pub fn abort_if_errors ( & self ) {
720+ if self . has_errors ( ) {
721+ FatalError . raise ( ) ;
729722 }
730723 }
731724
@@ -747,6 +740,10 @@ impl Handler {
747740 return ;
748741 }
749742
743+ if diagnostic. level == Warning && !self . flags . can_emit_warnings {
744+ return ;
745+ }
746+
750747 TRACK_DIAGNOSTICS . with ( |track_diagnostics| {
751748 track_diagnostics. get ( ) ( diagnostic) ;
752749 } ) ;
0 commit comments