@@ -47,6 +47,7 @@ pub struct AnnotateSnippetEmitter {
4747 track_diagnostics : bool ,
4848 terminal_url : TerminalUrl ,
4949 theme : OutputTheme ,
50+ show_suggestions_with_unavailable_source : bool ,
5051}
5152
5253impl Debug for AnnotateSnippetEmitter {
@@ -63,6 +64,10 @@ impl Debug for AnnotateSnippetEmitter {
6364 . field ( "track_diagnostics" , & self . track_diagnostics )
6465 . field ( "terminal_url" , & self . terminal_url )
6566 . field ( "theme" , & self . theme )
67+ . field (
68+ "show_suggestions_with_unavailable_source" ,
69+ & self . show_suggestions_with_unavailable_source ,
70+ )
6671 . finish ( )
6772 }
6873}
@@ -136,6 +141,7 @@ impl AnnotateSnippetEmitter {
136141 track_diagnostics : false ,
137142 terminal_url : TerminalUrl :: No ,
138143 theme : OutputTheme :: Ascii ,
144+ show_suggestions_with_unavailable_source : false ,
139145 }
140146 }
141147
@@ -307,6 +313,11 @@ impl AnnotateSnippetEmitter {
307313 SuggestionStyle :: HideCodeInline
308314 | SuggestionStyle :: ShowCode
309315 | SuggestionStyle :: ShowAlways => {
316+ let unavailable_source_span = if self . show_suggestions_with_unavailable_source {
317+ self . suggestion_span_with_unavailable_source ( sm, & suggestion)
318+ } else {
319+ None
320+ } ;
310321 let substitutions = suggestion
311322 . substitutions
312323 . into_iter ( )
@@ -356,6 +367,30 @@ impl AnnotateSnippetEmitter {
356367 . collect :: < Vec < _ > > ( ) ;
357368
358369 if substitutions. is_empty ( ) {
370+ if let Some ( span) = unavailable_source_span {
371+ let msg = format_diag_message ( & suggestion. msg , args) . to_string ( ) ;
372+ report. push ( std:: mem:: replace (
373+ & mut group,
374+ Group :: with_title (
375+ annotate_snippets:: Level :: HELP . secondary_title ( msg) ,
376+ ) ,
377+ ) ) ;
378+
379+ let file_ann = collect_annotations ( args, & span, sm) ;
380+ let level = annotate_snippets:: Level :: HELP ;
381+ for ( file_idx, ( file, annotations) ) in file_ann. into_iter ( ) . enumerate ( )
382+ {
383+ group = self . unannotated_messages (
384+ annotations,
385+ & file. name ,
386+ sm,
387+ file_idx,
388+ & mut report,
389+ group,
390+ & level,
391+ ) ;
392+ }
393+ }
359394 continue ;
360395 }
361396 let mut msg = format_diag_message ( & suggestion. msg , args) . to_string ( ) ;
@@ -645,6 +680,36 @@ impl AnnotateSnippetEmitter {
645680 }
646681 group
647682 }
683+
684+ fn suggestion_span_with_unavailable_source (
685+ & self ,
686+ sm : & Arc < SourceMap > ,
687+ suggestion : & CodeSuggestion ,
688+ ) -> Option < MultiSpan > {
689+ let spans = suggestion
690+ . substitutions
691+ . iter ( )
692+ . flat_map ( |subst| & subst. parts )
693+ . filter_map ( |part| {
694+ if sm. is_valid_span ( part. span ) . is_err ( ) {
695+ debug ! ( "suggestion contains an invalid span: {:?}" , part) ;
696+ return None ;
697+ }
698+ let lines = sm. span_to_lines ( part. span ) . ok ( ) ?;
699+ if should_show_source_code (
700+ & self . ignored_directories_in_source_blocks ,
701+ sm,
702+ & lines. file ,
703+ ) {
704+ None
705+ } else {
706+ Some ( part. span )
707+ }
708+ } )
709+ . collect :: < Vec < _ > > ( ) ;
710+
711+ if spans. is_empty ( ) { None } else { Some ( MultiSpan :: from_spans ( spans) ) }
712+ }
648713}
649714
650715fn emit_to_destination (
0 commit comments