@@ -157,10 +157,8 @@ impl AnnotateSnippetEmitterWriter {
157
157
{
158
158
annotated_files. swap ( 0 , pos) ;
159
159
}
160
- // owned: line source, line index, annotations
161
- type Owned = ( String , usize , Vec < crate :: snippet:: Annotation > ) ;
162
- let filename = source_map. filename_for_diagnostics ( & primary_lo. file . name ) ;
163
- let origin = filename. to_string_lossy ( ) ;
160
+ // owned: file name, line source, line index, annotations
161
+ type Owned = ( String , String , usize , Vec < crate :: snippet:: Annotation > ) ;
164
162
let annotated_files: Vec < Owned > = annotated_files
165
163
. into_iter ( )
166
164
. flat_map ( |annotated_file| {
@@ -169,7 +167,15 @@ impl AnnotateSnippetEmitterWriter {
169
167
. lines
170
168
. into_iter ( )
171
169
. map ( |line| {
172
- ( source_string ( file. clone ( ) , & line) , line. line_index , line. annotations )
170
+ // Ensure the source file is present before we try
171
+ // to load a string from it.
172
+ source_map. ensure_source_file_source_present ( file. clone ( ) ) ;
173
+ (
174
+ format ! ( "{}" , source_map. filename_for_diagnostics( & file. name) ) ,
175
+ source_string ( file. clone ( ) , & line) ,
176
+ line. line_index ,
177
+ line. annotations ,
178
+ )
173
179
} )
174
180
. collect :: < Vec < Owned > > ( )
175
181
} )
@@ -192,11 +198,11 @@ impl AnnotateSnippetEmitterWriter {
192
198
} ,
193
199
slices : annotated_files
194
200
. iter ( )
195
- . map ( |( source, line_index, annotations) | {
201
+ . map ( |( file_name , source, line_index, annotations) | {
196
202
Slice {
197
203
source,
198
204
line_start : * line_index,
199
- origin : Some ( & origin ) ,
205
+ origin : Some ( & file_name ) ,
200
206
// FIXME(#59346): Not really sure when `fold` should be true or false
201
207
fold : false ,
202
208
annotations : annotations
0 commit comments