@@ -47,7 +47,8 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
4747
4848fn make_file_info ( source_file : & SourceFile , embed_source : bool ) -> Option < FileInfo > {
4949 let has_md5 = source_file. src_hash . kind == SourceFileHashAlgorithm :: Md5 ;
50- let has_source = embed_source && source_file. src . is_some ( ) ;
50+ let has_source = embed_source
51+ && ( source_file. src . is_some ( ) || source_file. external_src . read ( ) . get_source ( ) . is_some ( ) ) ;
5152
5253 if !has_md5 && !has_source {
5354 return None ;
@@ -62,6 +63,8 @@ fn make_file_info(source_file: &SourceFile, embed_source: bool) -> Option<FileIn
6263 if embed_source {
6364 if let Some ( src) = & source_file. src {
6465 info. source = Some ( LineString :: String ( src. as_bytes ( ) . to_vec ( ) ) ) ;
66+ } else if let Some ( src) = source_file. external_src . read ( ) . get_source ( ) {
67+ info. source = Some ( LineString :: String ( src. as_bytes ( ) . to_vec ( ) ) ) ;
6568 }
6669 }
6770
@@ -79,19 +82,22 @@ impl DebugContext {
7982 let span = hygiene:: walk_chain_collapsed ( span, function_span) ;
8083 match tcx. sess . source_map ( ) . lookup_line ( span. lo ( ) ) {
8184 Ok ( SourceFileAndLine { sf : file, line } ) => {
82- let file_id = self . add_source_file ( & file) ;
85+ let file_id = self . add_source_file ( tcx , & file) ;
8386 let line_pos = file. lines ( ) [ line] ;
8487 let col = file. relative_position ( span. lo ( ) ) - line_pos;
8588
8689 ( file_id, u64:: try_from ( line) . unwrap ( ) + 1 , u64:: from ( col. to_u32 ( ) ) + 1 )
8790 }
88- Err ( file) => ( self . add_source_file ( & file) , 0 , 0 ) ,
91+ Err ( file) => ( self . add_source_file ( tcx , & file) , 0 , 0 ) ,
8992 }
9093 }
9194
92- pub ( crate ) fn add_source_file ( & mut self , source_file : & SourceFile ) -> FileId {
95+ pub ( crate ) fn add_source_file ( & mut self , tcx : TyCtxt < ' _ > , source_file : & SourceFile ) -> FileId {
9396 let cache_key = ( source_file. stable_id , source_file. src_hash ) ;
9497 * self . created_files . entry ( cache_key) . or_insert_with ( || {
98+ if self . embed_source && source_file. src . is_none ( ) {
99+ tcx. sess . source_map ( ) . ensure_source_file_source_present ( source_file) ;
100+ }
95101 let line_program: & mut LineProgram = & mut self . dwarf . unit . line_program ;
96102 let line_strings: & mut LineStringTable = & mut self . dwarf . line_strings ;
97103
0 commit comments