@@ -16,10 +16,10 @@ use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Styl
1616use crate :: styled_buffer:: StyledBuffer ;
1717use crate :: translation:: { to_fluent_args, Translate } ;
1818use 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 ,
2122} ;
22-
2323use rustc_lint_defs:: pluralize;
2424
2525use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
@@ -64,6 +64,7 @@ impl HumanReadableErrorType {
6464 teach : bool ,
6565 diagnostic_width : Option < usize > ,
6666 macro_backtrace : bool ,
67+ track_diagnostics : bool ,
6768 ) -> EmitterWriter {
6869 let ( short, color_config) = self . unzip ( ) ;
6970 let color = color_config. suggests_using_colors ( ) ;
@@ -77,6 +78,7 @@ impl HumanReadableErrorType {
7778 color,
7879 diagnostic_width,
7980 macro_backtrace,
81+ track_diagnostics,
8082 )
8183 }
8284}
@@ -557,6 +559,7 @@ impl Emitter for EmitterWriter {
557559 & primary_span,
558560 & children,
559561 & suggestions,
562+ self . track_diagnostics . then_some ( & diag. emitted_at ) ,
560563 ) ;
561564 }
562565
@@ -650,6 +653,7 @@ pub struct EmitterWriter {
650653 diagnostic_width : Option < usize > ,
651654
652655 macro_backtrace : bool ,
656+ track_diagnostics : bool ,
653657}
654658
655659#[ derive( Debug ) ]
@@ -669,6 +673,7 @@ impl EmitterWriter {
669673 teach : bool ,
670674 diagnostic_width : Option < usize > ,
671675 macro_backtrace : bool ,
676+ track_diagnostics : bool ,
672677 ) -> EmitterWriter {
673678 let dst = Destination :: from_stderr ( color_config) ;
674679 EmitterWriter {
@@ -681,6 +686,7 @@ impl EmitterWriter {
681686 ui_testing : false ,
682687 diagnostic_width,
683688 macro_backtrace,
689+ track_diagnostics,
684690 }
685691 }
686692
@@ -694,6 +700,7 @@ impl EmitterWriter {
694700 colored : bool ,
695701 diagnostic_width : Option < usize > ,
696702 macro_backtrace : bool ,
703+ track_diagnostics : bool ,
697704 ) -> EmitterWriter {
698705 EmitterWriter {
699706 dst : Raw ( dst, colored) ,
@@ -705,6 +712,7 @@ impl EmitterWriter {
705712 ui_testing : false ,
706713 diagnostic_width,
707714 macro_backtrace,
715+ track_diagnostics,
708716 }
709717 }
710718
@@ -1327,6 +1335,7 @@ impl EmitterWriter {
13271335 level : & Level ,
13281336 max_line_num_len : usize ,
13291337 is_secondary : bool ,
1338+ emitted_at : Option < & DiagnosticLocation > ,
13301339 ) -> io:: Result < ( ) > {
13311340 let mut buffer = StyledBuffer :: new ( ) ;
13321341
@@ -1377,7 +1386,6 @@ impl EmitterWriter {
13771386 }
13781387 }
13791388 }
1380-
13811389 let mut annotated_files = FileWithAnnotatedLines :: collect_annotations ( self , args, msp) ;
13821390
13831391 // Make sure our primary file comes first
@@ -1653,6 +1661,12 @@ impl EmitterWriter {
16531661 }
16541662 }
16551663
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+
16561670 // final step: take our styled buffer, render it, then output it
16571671 emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
16581672
@@ -1977,6 +1991,7 @@ impl EmitterWriter {
19771991 span : & MultiSpan ,
19781992 children : & [ SubDiagnostic ] ,
19791993 suggestions : & [ CodeSuggestion ] ,
1994+ emitted_at : Option < & DiagnosticLocation > ,
19801995 ) {
19811996 let max_line_num_len = if self . ui_testing {
19821997 ANONYMIZED_LINE_NUM . len ( )
@@ -1985,7 +2000,16 @@ impl EmitterWriter {
19852000 num_decimal_digits ( n)
19862001 } ;
19872002
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+ ) {
19892013 Ok ( ( ) ) => {
19902014 if !children. is_empty ( )
19912015 || suggestions. iter ( ) . any ( |s| s. style != SuggestionStyle :: CompletelyHidden )
@@ -2014,6 +2038,7 @@ impl EmitterWriter {
20142038 & child. level ,
20152039 max_line_num_len,
20162040 true ,
2041+ None ,
20172042 ) {
20182043 panic ! ( "failed to emit error: {}" , err) ;
20192044 }
@@ -2030,6 +2055,7 @@ impl EmitterWriter {
20302055 & Level :: Help ,
20312056 max_line_num_len,
20322057 true ,
2058+ None ,
20332059 ) {
20342060 panic ! ( "failed to emit error: {}" , e) ;
20352061 }
0 commit comments