@@ -294,6 +294,7 @@ impl error::Error for ExplicitBug {}
294
294
295
295
pub use diagnostic:: { Diagnostic , DiagnosticId , DiagnosticStyledString , SubDiagnostic } ;
296
296
pub use diagnostic_builder:: DiagnosticBuilder ;
297
+ use std:: backtrace:: Backtrace ;
297
298
298
299
/// A handler deals with errors and other compiler output.
299
300
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
@@ -317,7 +318,7 @@ struct HandlerInner {
317
318
deduplicated_err_count : usize ,
318
319
emitter : Box < dyn Emitter + sync:: Send > ,
319
320
delayed_span_bugs : Vec < Diagnostic > ,
320
- delayed_good_path_bugs : Vec < Diagnostic > ,
321
+ delayed_good_path_bugs : Vec < DelayedDiagnostic > ,
321
322
322
323
/// This set contains the `DiagnosticId` of all emitted diagnostics to avoid
323
324
/// emitting the same diagnostic with extended help (`--teach`) twice, which
@@ -388,7 +389,7 @@ impl Drop for HandlerInner {
388
389
if !self . has_any_message ( ) {
389
390
let bugs = std:: mem:: replace ( & mut self . delayed_good_path_bugs , Vec :: new ( ) ) ;
390
391
self . flush_delayed (
391
- bugs,
392
+ bugs. into_iter ( ) . map ( DelayedDiagnostic :: decorate ) . collect ( ) ,
392
393
"no warnings or errors encountered even though `delayed_good_path_bugs` issued" ,
393
394
) ;
394
395
}
@@ -968,12 +969,12 @@ impl HandlerInner {
968
969
}
969
970
970
971
fn delay_good_path_bug ( & mut self , msg : & str ) {
971
- let mut diagnostic = Diagnostic :: new ( Level :: Bug , msg) ;
972
+ let diagnostic = Diagnostic :: new ( Level :: Bug , msg) ;
972
973
if self . flags . report_delayed_bugs {
973
974
self . emit_diagnostic ( & diagnostic) ;
974
975
}
975
- diagnostic . note ( & format ! ( "delayed at {}" , std:: backtrace:: Backtrace :: force_capture( ) ) ) ;
976
- self . delayed_good_path_bugs . push ( diagnostic) ;
976
+ let backtrace = std:: backtrace:: Backtrace :: force_capture ( ) ;
977
+ self . delayed_good_path_bugs . push ( DelayedDiagnostic :: with_backtrace ( diagnostic, backtrace ) ) ;
977
978
}
978
979
979
980
fn failure ( & mut self , msg : & str ) {
@@ -1042,6 +1043,22 @@ impl HandlerInner {
1042
1043
}
1043
1044
}
1044
1045
1046
+ struct DelayedDiagnostic {
1047
+ inner : Diagnostic ,
1048
+ note : Backtrace ,
1049
+ }
1050
+
1051
+ impl DelayedDiagnostic {
1052
+ fn with_backtrace ( diagnostic : Diagnostic , backtrace : Backtrace ) -> Self {
1053
+ DelayedDiagnostic { inner : diagnostic, note : backtrace }
1054
+ }
1055
+
1056
+ fn decorate ( mut self ) -> Diagnostic {
1057
+ self . inner . note ( & format ! ( "delayed at {}" , self . note) ) ;
1058
+ self . inner
1059
+ }
1060
+ }
1061
+
1045
1062
#[ derive( Copy , PartialEq , Clone , Hash , Debug , Encodable , Decodable ) ]
1046
1063
pub enum Level {
1047
1064
Bug ,
0 commit comments