@@ -1138,7 +1138,8 @@ impl FilePathMapping {
11381138 /// Applies any path prefix substitution as defined by the mapping.
11391139 /// The return value is the remapped path and a boolean indicating whether
11401140 /// the path was affected by the mapping.
1141- pub fn map_prefix ( & self , path : PathBuf ) -> ( PathBuf , bool ) {
1141+ pub fn map_prefix < ' a > ( & ' a self , path : impl Into < Cow < ' a , Path > > ) -> ( Cow < ' a , Path > , bool ) {
1142+ let path = path. into ( ) ;
11421143 if path. as_os_str ( ) . is_empty ( ) {
11431144 // Exit early if the path is empty and therefore there's nothing to remap.
11441145 // This is mostly to reduce spam for `RUSTC_LOG=[remap_path_prefix]`.
@@ -1148,7 +1149,10 @@ impl FilePathMapping {
11481149 return remap_path_prefix ( & self . mapping , path) ;
11491150
11501151 #[ instrument( level = "debug" , skip( mapping) , ret) ]
1151- fn remap_path_prefix ( mapping : & [ ( PathBuf , PathBuf ) ] , path : PathBuf ) -> ( PathBuf , bool ) {
1152+ fn remap_path_prefix < ' a > (
1153+ mapping : & ' a [ ( PathBuf , PathBuf ) ] ,
1154+ path : Cow < ' a , Path > ,
1155+ ) -> ( Cow < ' a , Path > , bool ) {
11521156 // NOTE: We are iterating over the mapping entries from last to first
11531157 // because entries specified later on the command line should
11541158 // take precedence.
@@ -1163,9 +1167,9 @@ impl FilePathMapping {
11631167 // in remapped paths down the line.
11641168 // So, if we have an exact match, we just return that without a call
11651169 // to `Path::join()`.
1166- to. clone ( )
1170+ to. into ( )
11671171 } else {
1168- to. join ( rest)
1172+ to. join ( rest) . into ( )
11691173 } ;
11701174 debug ! ( "Match - remapped" ) ;
11711175
@@ -1183,11 +1187,11 @@ impl FilePathMapping {
11831187 fn map_filename_prefix ( & self , file : & FileName ) -> ( FileName , bool ) {
11841188 match file {
11851189 FileName :: Real ( realfile) if let RealFileName :: LocalPath ( local_path) = realfile => {
1186- let ( mapped_path, mapped) = self . map_prefix ( local_path. to_path_buf ( ) ) ;
1190+ let ( mapped_path, mapped) = self . map_prefix ( local_path) ;
11871191 let realfile = if mapped {
11881192 RealFileName :: Remapped {
11891193 local_path : Some ( local_path. clone ( ) ) ,
1190- virtual_name : mapped_path,
1194+ virtual_name : mapped_path. into_owned ( ) ,
11911195 }
11921196 } else {
11931197 realfile. clone ( )
@@ -1228,14 +1232,17 @@ impl FilePathMapping {
12281232 let ( new_path, was_remapped) = self . map_prefix ( unmapped_file_path) ;
12291233 if was_remapped {
12301234 // It was remapped, so don't modify further
1231- return RealFileName :: Remapped { local_path : None , virtual_name : new_path } ;
1235+ return RealFileName :: Remapped {
1236+ local_path : None ,
1237+ virtual_name : new_path. into_owned ( ) ,
1238+ } ;
12321239 }
12331240
12341241 if new_path. is_absolute ( ) {
12351242 // No remapping has applied to this path and it is absolute,
12361243 // so the working directory cannot influence it either, so
12371244 // we are done.
1238- return RealFileName :: LocalPath ( new_path) ;
1245+ return RealFileName :: LocalPath ( new_path. into_owned ( ) ) ;
12391246 }
12401247
12411248 debug_assert ! ( new_path. is_relative( ) ) ;
@@ -1253,12 +1260,12 @@ impl FilePathMapping {
12531260 RealFileName :: Remapped {
12541261 // Erase the actual path
12551262 local_path : None ,
1256- virtual_name : file_path_abs,
1263+ virtual_name : file_path_abs. into_owned ( ) ,
12571264 }
12581265 } else {
12591266 // No kind of remapping applied to this path, so
12601267 // we leave it as it is.
1261- RealFileName :: LocalPath ( file_path_abs)
1268+ RealFileName :: LocalPath ( file_path_abs. into_owned ( ) )
12621269 }
12631270 }
12641271 RealFileName :: Remapped {
0 commit comments