@@ -14,7 +14,7 @@ use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1414use rustc_middle:: ty:: TyCtxt ;
1515use rustc_session:: Session ;
1616use rustc_span:: edition:: Edition ;
17- use rustc_span:: { BytePos , FileName , Symbol } ;
17+ use rustc_span:: { BytePos , FileName , RemapPathScopeComponents , Symbol } ;
1818use tracing:: info;
1919
2020use super :: print_item:: { full_path, print_item, print_item_path} ;
@@ -365,7 +365,10 @@ impl<'tcx> Context<'tcx> {
365365
366366 // We can safely ignore synthetic `SourceFile`s.
367367 let file = match span. filename ( self . sess ( ) ) {
368- FileName :: Real ( ref path) => path. local_path ( ) ?. to_path_buf ( ) ,
368+ FileName :: Real ( ref path) => path
369+ . local_path ( )
370+ . unwrap_or ( path. path ( RemapPathScopeComponents :: MACRO ) )
371+ . to_path_buf ( ) ,
369372 _ => return None ,
370373 } ;
371374 let file = & file;
@@ -499,10 +502,12 @@ impl<'tcx> Context<'tcx> {
499502 } = options;
500503
501504 let src_root = match krate. src ( tcx) {
502- FileName :: Real ( ref p) => match p. local_path ( ) . map ( |p| p. parent ( ) ) . flatten ( ) {
503- Some ( p) => p. to_path_buf ( ) ,
504- None => PathBuf :: new ( ) ,
505- } ,
505+ FileName :: Real ( ref p) => {
506+ match p. local_path ( ) . unwrap_or ( p. path ( RemapPathScopeComponents :: MACRO ) ) . parent ( ) {
507+ Some ( p) => p. to_path_buf ( ) ,
508+ None => PathBuf :: new ( ) ,
509+ }
510+ }
506511 _ => PathBuf :: new ( ) ,
507512 } ;
508513 // If user passed in `--playground-url` arg, we fill in crate name here
0 commit comments