@@ -466,10 +466,15 @@ impl Handler {
466
466
/// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
467
467
/// If the diagnostic with this `(span, key)` already exists, this will result in an ICE.
468
468
pub fn stash_diagnostic ( & self , span : Span , key : StashKey , diag : Diagnostic ) {
469
- if let Some ( old) = self . inner . borrow_mut ( ) . stashed_diagnostics . insert ( ( span, key) , diag) {
469
+ let mut inner = self . inner . borrow_mut ( ) ;
470
+ if let Some ( mut old_diag) = inner. stashed_diagnostics . insert ( ( span, key) , diag) {
470
471
// We are removing a previously stashed diagnostic which should not happen.
471
- // Create a builder and drop it on the floor to get an ICE.
472
- drop ( DiagnosticBuilder :: new_diagnostic ( self , old) ) ;
472
+ old_diag. level = Bug ;
473
+ old_diag. note ( & format ! (
474
+ "{}:{}: already existing stashed diagnostic with (span = {:?}, key = {:?})" ,
475
+ file!( ) , line!( ) , span, key
476
+ ) ) ;
477
+ inner. emit_explicit_bug ( & old_diag) ;
473
478
}
474
479
}
475
480
@@ -676,6 +681,11 @@ impl Handler {
676
681
self . inner . borrow_mut ( ) . abort_if_errors_and_should_abort ( )
677
682
}
678
683
684
+ /// `true` if we haven't taught a diagnostic with this code already.
685
+ /// The caller must then teach the user about such a diagnostic.
686
+ ///
687
+ /// Used to suppress emitting the same error multiple times with extended explanation when
688
+ /// calling `-Zteach`.
679
689
pub fn must_teach ( & self , code : & DiagnosticId ) -> bool {
680
690
self . inner . borrow_mut ( ) . must_teach ( code)
681
691
}
@@ -698,11 +708,6 @@ impl Handler {
698
708
}
699
709
700
710
impl HandlerInner {
701
- /// `true` if we haven't taught a diagnostic with this code already.
702
- /// The caller must then teach the user about such a diagnostic.
703
- ///
704
- /// Used to suppress emitting the same error multiple times with extended explanation when
705
- /// calling `-Zteach`.
706
711
fn must_teach ( & mut self , code : & DiagnosticId ) -> bool {
707
712
self . taught_diagnostics . insert ( code. clone ( ) )
708
713
}
@@ -833,7 +838,11 @@ impl HandlerInner {
833
838
}
834
839
835
840
fn span_bug < S : Into < MultiSpan > > ( & mut self , sp : S , msg : & str ) -> ! {
836
- self . emit_diagnostic ( Diagnostic :: new ( Bug , msg) . set_span ( sp) ) ;
841
+ self . emit_explicit_bug ( Diagnostic :: new ( Bug , msg) . set_span ( sp) ) ;
842
+ }
843
+
844
+ fn emit_explicit_bug ( & mut self , diag : & Diagnostic ) -> ! {
845
+ self . emit_diagnostic ( diag) ;
837
846
self . abort_if_errors_and_should_abort ( ) ;
838
847
panic ! ( ExplicitBug ) ;
839
848
}
0 commit comments