@@ -16,10 +16,10 @@ use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Styl
16
16
use crate :: styled_buffer:: StyledBuffer ;
17
17
use crate :: translation:: { to_fluent_args, Translate } ;
18
18
use crate :: {
19
- CodeSuggestion , Diagnostic , DiagnosticId , DiagnosticMessage , FluentBundle , Handler ,
20
- LazyFallbackBundle , Level , MultiSpan , SubDiagnostic , SubstitutionHighlight , SuggestionStyle ,
19
+ diagnostic:: DiagnosticLocation , CodeSuggestion , Diagnostic , DiagnosticId , DiagnosticMessage ,
20
+ FluentBundle , Handler , LazyFallbackBundle , Level , MultiSpan , SubDiagnostic ,
21
+ SubstitutionHighlight , SuggestionStyle ,
21
22
} ;
22
-
23
23
use rustc_lint_defs:: pluralize;
24
24
25
25
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
@@ -64,6 +64,7 @@ impl HumanReadableErrorType {
64
64
teach : bool ,
65
65
diagnostic_width : Option < usize > ,
66
66
macro_backtrace : bool ,
67
+ track_diagnostics : bool ,
67
68
) -> EmitterWriter {
68
69
let ( short, color_config) = self . unzip ( ) ;
69
70
let color = color_config. suggests_using_colors ( ) ;
@@ -77,6 +78,7 @@ impl HumanReadableErrorType {
77
78
color,
78
79
diagnostic_width,
79
80
macro_backtrace,
81
+ track_diagnostics,
80
82
)
81
83
}
82
84
}
@@ -557,6 +559,7 @@ impl Emitter for EmitterWriter {
557
559
& primary_span,
558
560
& children,
559
561
& suggestions,
562
+ self . track_diagnostics . then_some ( & diag. emitted_at ) ,
560
563
) ;
561
564
}
562
565
@@ -650,6 +653,7 @@ pub struct EmitterWriter {
650
653
diagnostic_width : Option < usize > ,
651
654
652
655
macro_backtrace : bool ,
656
+ track_diagnostics : bool ,
653
657
}
654
658
655
659
#[ derive( Debug ) ]
@@ -669,6 +673,7 @@ impl EmitterWriter {
669
673
teach : bool ,
670
674
diagnostic_width : Option < usize > ,
671
675
macro_backtrace : bool ,
676
+ track_diagnostics : bool ,
672
677
) -> EmitterWriter {
673
678
let dst = Destination :: from_stderr ( color_config) ;
674
679
EmitterWriter {
@@ -681,6 +686,7 @@ impl EmitterWriter {
681
686
ui_testing : false ,
682
687
diagnostic_width,
683
688
macro_backtrace,
689
+ track_diagnostics,
684
690
}
685
691
}
686
692
@@ -694,6 +700,7 @@ impl EmitterWriter {
694
700
colored : bool ,
695
701
diagnostic_width : Option < usize > ,
696
702
macro_backtrace : bool ,
703
+ track_diagnostics : bool ,
697
704
) -> EmitterWriter {
698
705
EmitterWriter {
699
706
dst : Raw ( dst, colored) ,
@@ -705,6 +712,7 @@ impl EmitterWriter {
705
712
ui_testing : false ,
706
713
diagnostic_width,
707
714
macro_backtrace,
715
+ track_diagnostics,
708
716
}
709
717
}
710
718
@@ -1327,6 +1335,7 @@ impl EmitterWriter {
1327
1335
level : & Level ,
1328
1336
max_line_num_len : usize ,
1329
1337
is_secondary : bool ,
1338
+ emitted_at : Option < & DiagnosticLocation > ,
1330
1339
) -> io:: Result < ( ) > {
1331
1340
let mut buffer = StyledBuffer :: new ( ) ;
1332
1341
@@ -1377,7 +1386,6 @@ impl EmitterWriter {
1377
1386
}
1378
1387
}
1379
1388
}
1380
-
1381
1389
let mut annotated_files = FileWithAnnotatedLines :: collect_annotations ( self , args, msp) ;
1382
1390
1383
1391
// Make sure our primary file comes first
@@ -1653,6 +1661,12 @@ impl EmitterWriter {
1653
1661
}
1654
1662
}
1655
1663
1664
+ if let Some ( tracked) = emitted_at {
1665
+ let track = format ! ( "-Ztrack-diagnostics: created at {tracked}" ) ;
1666
+ let len = buffer. num_lines ( ) ;
1667
+ buffer. append ( len, & track, Style :: NoStyle ) ;
1668
+ }
1669
+
1656
1670
// final step: take our styled buffer, render it, then output it
1657
1671
emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
1658
1672
@@ -1977,6 +1991,7 @@ impl EmitterWriter {
1977
1991
span : & MultiSpan ,
1978
1992
children : & [ SubDiagnostic ] ,
1979
1993
suggestions : & [ CodeSuggestion ] ,
1994
+ emitted_at : Option < & DiagnosticLocation > ,
1980
1995
) {
1981
1996
let max_line_num_len = if self . ui_testing {
1982
1997
ANONYMIZED_LINE_NUM . len ( )
@@ -1985,7 +2000,16 @@ impl EmitterWriter {
1985
2000
num_decimal_digits ( n)
1986
2001
} ;
1987
2002
1988
- match self . emit_message_default ( span, message, args, code, level, max_line_num_len, false ) {
2003
+ match self . emit_message_default (
2004
+ span,
2005
+ message,
2006
+ args,
2007
+ code,
2008
+ level,
2009
+ max_line_num_len,
2010
+ false ,
2011
+ emitted_at,
2012
+ ) {
1989
2013
Ok ( ( ) ) => {
1990
2014
if !children. is_empty ( )
1991
2015
|| suggestions. iter ( ) . any ( |s| s. style != SuggestionStyle :: CompletelyHidden )
@@ -2014,6 +2038,7 @@ impl EmitterWriter {
2014
2038
& child. level ,
2015
2039
max_line_num_len,
2016
2040
true ,
2041
+ None ,
2017
2042
) {
2018
2043
panic ! ( "failed to emit error: {}" , err) ;
2019
2044
}
@@ -2030,6 +2055,7 @@ impl EmitterWriter {
2030
2055
& Level :: Help ,
2031
2056
max_line_num_len,
2032
2057
true ,
2058
+ None ,
2033
2059
) {
2034
2060
panic ! ( "failed to emit error: {}" , e) ;
2035
2061
}
0 commit comments