@@ -16,7 +16,7 @@ use rustc_session::config::{self, CrateType, ErrorOutputType};
16
16
use rustc_session:: parse:: ParseSess ;
17
17
use rustc_session:: { lint, Session } ;
18
18
use rustc_span:: edition:: Edition ;
19
- use rustc_span:: source_map:: SourceMap ;
19
+ use rustc_span:: source_map:: { FilePathMapping , SourceMap } ;
20
20
use rustc_span:: symbol:: sym;
21
21
use rustc_span:: { BytePos , FileName , Pos , Span , DUMMY_SP } ;
22
22
use rustc_target:: spec:: { Target , TargetTriple } ;
@@ -128,6 +128,7 @@ pub(crate) fn run(
128
128
edition : options. edition ,
129
129
target_triple : options. target . clone ( ) ,
130
130
crate_name : options. crate_name . clone ( ) ,
131
+ remap_path_prefix : options. remap_path_prefix . clone ( ) ,
131
132
..config:: Options :: default ( )
132
133
} ;
133
134
@@ -612,7 +613,6 @@ pub(crate) fn make_test(
612
613
use rustc_errors:: emitter:: { Emitter , HumanEmitter } ;
613
614
use rustc_errors:: DiagCtxt ;
614
615
use rustc_parse:: parser:: ForceCollect ;
615
- use rustc_span:: source_map:: FilePathMapping ;
616
616
617
617
let filename = FileName :: anon_source_code ( s) ;
618
618
let source = crates + everything_else;
@@ -803,7 +803,6 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
803
803
rustc_span:: create_session_if_not_set_then ( edition, |_| {
804
804
use rustc_errors:: emitter:: HumanEmitter ;
805
805
use rustc_errors:: DiagCtxt ;
806
- use rustc_span:: source_map:: FilePathMapping ;
807
806
808
807
let filename = FileName :: anon_source_code ( source) ;
809
808
// Any errors in parsing should also appear when the doctest is compiled for real, so just
@@ -1066,7 +1065,7 @@ impl Collector {
1066
1065
if !item_path. is_empty ( ) {
1067
1066
item_path. push ( ' ' ) ;
1068
1067
}
1069
- format ! ( "{} - {item_path}(line {line})" , filename. prefer_local ( ) )
1068
+ format ! ( "{} - {item_path}(line {line})" , filename. prefer_remapped_unconditionaly ( ) )
1070
1069
}
1071
1070
1072
1071
pub ( crate ) fn set_position ( & mut self , position : Span ) {
@@ -1076,11 +1075,15 @@ impl Collector {
1076
1075
fn get_filename ( & self ) -> FileName {
1077
1076
if let Some ( ref source_map) = self . source_map {
1078
1077
let filename = source_map. span_to_filename ( self . position ) ;
1079
- if let FileName :: Real ( ref filename) = filename
1080
- && let Ok ( cur_dir) = env:: current_dir ( )
1081
- && let Some ( local_path) = filename. local_path ( )
1082
- && let Ok ( path) = local_path. strip_prefix ( & cur_dir)
1083
- {
1078
+ if let FileName :: Real ( ref filename) = filename {
1079
+ let path = filename. remapped_path_if_available ( ) ;
1080
+
1081
+ // Strip the cwd prefix from the path. This will likely exist if
1082
+ // the path was not remapped.
1083
+ let path = env:: current_dir ( )
1084
+ . map ( |cur_dir| path. strip_prefix ( & cur_dir) . unwrap_or ( path) )
1085
+ . unwrap_or ( path) ;
1086
+
1084
1087
return path. to_owned ( ) . into ( ) ;
1085
1088
}
1086
1089
filename
@@ -1107,20 +1110,13 @@ impl Tester for Collector {
1107
1110
}
1108
1111
1109
1112
let path = match & filename {
1110
- FileName :: Real ( path) => {
1111
- if let Some ( local_path) = path. local_path ( ) {
1112
- local_path. to_path_buf ( )
1113
- } else {
1114
- // Somehow we got the filename from the metadata of another crate, should never happen
1115
- unreachable ! ( "doctest from a different crate" ) ;
1116
- }
1117
- }
1113
+ FileName :: Real ( path) => path. remapped_path_if_available ( ) . to_path_buf ( ) ,
1118
1114
_ => PathBuf :: from ( r"doctest.rs" ) ,
1119
1115
} ;
1120
1116
1121
1117
// For example `module/file.rs` would become `module_file_rs`
1122
1118
let file = filename
1123
- . prefer_local ( )
1119
+ . prefer_remapped_unconditionaly ( )
1124
1120
. to_string_lossy ( )
1125
1121
. chars ( )
1126
1122
. map ( |c| if c. is_ascii_alphanumeric ( ) { c } else { '_' } )
0 commit comments