@@ -539,19 +539,22 @@ impl Handler {
539
539
}
540
540
541
541
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 ( ) ;
543
544
FatalError
544
545
}
545
546
pub fn span_fatal_with_code < S : Into < MultiSpan > > ( & self ,
546
547
sp : S ,
547
548
msg : & str ,
548
549
code : DiagnosticId )
549
550
-> 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 ( ) ;
551
553
FatalError
552
554
}
553
555
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 ( ) ;
555
558
}
556
559
pub fn mut_span_err < S : Into < MultiSpan > > ( & self ,
557
560
sp : S ,
@@ -562,16 +565,20 @@ impl Handler {
562
565
result
563
566
}
564
567
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 ( ) ;
566
570
}
567
571
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 ( ) ;
569
574
}
570
575
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 ( ) ;
572
578
}
573
579
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 ( ) ;
575
582
panic ! ( ExplicitBug ) ;
576
583
}
577
584
pub fn delay_span_bug < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
@@ -590,10 +597,12 @@ impl Handler {
590
597
self . delayed_span_bugs . borrow_mut ( ) . push ( diagnostic) ;
591
598
}
592
599
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 ( ) ;
594
602
}
595
603
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 ( ) ;
597
606
}
598
607
pub fn span_note_diag ( & self ,
599
608
sp : Span ,
@@ -701,31 +710,15 @@ impl Handler {
701
710
}
702
711
}
703
712
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 ) {
706
715
FatalError . raise ( ) ;
707
716
}
708
717
}
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 ( ) ;
729
722
}
730
723
}
731
724
@@ -747,6 +740,10 @@ impl Handler {
747
740
return ;
748
741
}
749
742
743
+ if diagnostic. level == Warning && !self . flags . can_emit_warnings {
744
+ return ;
745
+ }
746
+
750
747
TRACK_DIAGNOSTICS . with ( |track_diagnostics| {
751
748
track_diagnostics. get ( ) ( diagnostic) ;
752
749
} ) ;
0 commit comments