@@ -1138,7 +1138,8 @@ impl FilePathMapping {
1138
1138
/// Applies any path prefix substitution as defined by the mapping.
1139
1139
/// The return value is the remapped path and a boolean indicating whether
1140
1140
/// 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 ( ) ;
1142
1143
if path. as_os_str ( ) . is_empty ( ) {
1143
1144
// Exit early if the path is empty and therefore there's nothing to remap.
1144
1145
// This is mostly to reduce spam for `RUSTC_LOG=[remap_path_prefix]`.
@@ -1148,7 +1149,10 @@ impl FilePathMapping {
1148
1149
return remap_path_prefix ( & self . mapping , path) ;
1149
1150
1150
1151
#[ 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 ) {
1152
1156
// NOTE: We are iterating over the mapping entries from last to first
1153
1157
// because entries specified later on the command line should
1154
1158
// take precedence.
@@ -1163,9 +1167,9 @@ impl FilePathMapping {
1163
1167
// in remapped paths down the line.
1164
1168
// So, if we have an exact match, we just return that without a call
1165
1169
// to `Path::join()`.
1166
- to. clone ( )
1170
+ to. into ( )
1167
1171
} else {
1168
- to. join ( rest)
1172
+ to. join ( rest) . into ( )
1169
1173
} ;
1170
1174
debug ! ( "Match - remapped" ) ;
1171
1175
@@ -1183,11 +1187,11 @@ impl FilePathMapping {
1183
1187
fn map_filename_prefix ( & self , file : & FileName ) -> ( FileName , bool ) {
1184
1188
match file {
1185
1189
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) ;
1187
1191
let realfile = if mapped {
1188
1192
RealFileName :: Remapped {
1189
1193
local_path : Some ( local_path. clone ( ) ) ,
1190
- virtual_name : mapped_path,
1194
+ virtual_name : mapped_path. into_owned ( ) ,
1191
1195
}
1192
1196
} else {
1193
1197
realfile. clone ( )
@@ -1228,14 +1232,17 @@ impl FilePathMapping {
1228
1232
let ( new_path, was_remapped) = self . map_prefix ( unmapped_file_path) ;
1229
1233
if was_remapped {
1230
1234
// 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
+ } ;
1232
1239
}
1233
1240
1234
1241
if new_path. is_absolute ( ) {
1235
1242
// No remapping has applied to this path and it is absolute,
1236
1243
// so the working directory cannot influence it either, so
1237
1244
// we are done.
1238
- return RealFileName :: LocalPath ( new_path) ;
1245
+ return RealFileName :: LocalPath ( new_path. into_owned ( ) ) ;
1239
1246
}
1240
1247
1241
1248
debug_assert ! ( new_path. is_relative( ) ) ;
@@ -1253,12 +1260,12 @@ impl FilePathMapping {
1253
1260
RealFileName :: Remapped {
1254
1261
// Erase the actual path
1255
1262
local_path : None ,
1256
- virtual_name : file_path_abs,
1263
+ virtual_name : file_path_abs. into_owned ( ) ,
1257
1264
}
1258
1265
} else {
1259
1266
// No kind of remapping applied to this path, so
1260
1267
// we leave it as it is.
1261
- RealFileName :: LocalPath ( file_path_abs)
1268
+ RealFileName :: LocalPath ( file_path_abs. into_owned ( ) )
1262
1269
}
1263
1270
}
1264
1271
RealFileName :: Remapped {
0 commit comments