@@ -466,10 +466,15 @@ impl Handler {
466466 /// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
467467 /// If the diagnostic with this `(span, key)` already exists, this will result in an ICE.
468468 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) {
470471 // 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) ;
473478 }
474479 }
475480
@@ -676,6 +681,11 @@ impl Handler {
676681 self . inner . borrow_mut ( ) . abort_if_errors_and_should_abort ( )
677682 }
678683
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`.
679689 pub fn must_teach ( & self , code : & DiagnosticId ) -> bool {
680690 self . inner . borrow_mut ( ) . must_teach ( code)
681691 }
@@ -698,11 +708,6 @@ impl Handler {
698708}
699709
700710impl 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`.
706711 fn must_teach ( & mut self , code : & DiagnosticId ) -> bool {
707712 self . taught_diagnostics . insert ( code. clone ( ) )
708713 }
@@ -833,7 +838,11 @@ impl HandlerInner {
833838 }
834839
835840 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) ;
837846 self . abort_if_errors_and_should_abort ( ) ;
838847 panic ! ( ExplicitBug ) ;
839848 }
0 commit comments