@@ -21,14 +21,14 @@ enum Pathconversion {
21
21
22
22
/// Perform path separator conversion if needed.
23
23
fn convert_path_separator < ' a > (
24
- os_str : & ' a OsStr ,
24
+ os_str : Cow < ' a , OsStr > ,
25
25
target_os : & str ,
26
26
direction : Pathconversion ,
27
27
) -> Cow < ' a , OsStr > {
28
28
#[ cfg( windows) ]
29
29
return if target_os == "windows" {
30
30
// Windows-on-Windows, all fine.
31
- Cow :: Borrowed ( os_str)
31
+ os_str
32
32
} else {
33
33
// Unix target, Windows host.
34
34
let ( from, to) = match direction {
@@ -56,7 +56,7 @@ fn convert_path_separator<'a>(
56
56
Cow :: Owned ( OsString :: from_vec ( converted) )
57
57
} else {
58
58
// Unix-on-Unix, all is fine.
59
- Cow :: Borrowed ( os_str)
59
+ os_str
60
60
} ;
61
61
}
62
62
@@ -226,7 +226,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226
226
let this = self . eval_context_ref ( ) ;
227
227
let os_str = this. read_os_str_from_c_str ( scalar) ?;
228
228
229
- Ok ( match convert_path_separator ( os_str, & this. tcx . sess . target . target . target_os , Pathconversion :: TargetToHost ) {
229
+ Ok ( match convert_path_separator ( Cow :: Borrowed ( os_str) , & this. tcx . sess . target . target . target_os , Pathconversion :: TargetToHost ) {
230
230
Cow :: Borrowed ( x) => Cow :: Borrowed ( Path :: new ( x) ) ,
231
231
Cow :: Owned ( y) => Cow :: Owned ( PathBuf :: from ( y) ) ,
232
232
} )
@@ -237,7 +237,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
237
237
let this = self . eval_context_ref ( ) ;
238
238
let os_str = this. read_os_str_from_wide_str ( scalar) ?;
239
239
240
- Ok ( PathBuf :: from ( & convert_path_separator ( & os_str, & this. tcx . sess . target . target . target_os , Pathconversion :: TargetToHost ) ) )
240
+ Ok ( convert_path_separator ( Cow :: Owned ( os_str) , & this. tcx . sess . target . target . target_os , Pathconversion :: TargetToHost ) . into_owned ( ) . into ( ) )
241
241
}
242
242
243
243
/// Write a Path to the machine memory (as a null-terminated sequence of bytes),
@@ -249,7 +249,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
249
249
size : u64 ,
250
250
) -> InterpResult < ' tcx , ( bool , u64 ) > {
251
251
let this = self . eval_context_mut ( ) ;
252
- let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , Pathconversion :: HostToTarget ) ;
252
+ let os_str = convert_path_separator ( Cow :: Borrowed ( path. as_os_str ( ) ) , & this. tcx . sess . target . target . target_os , Pathconversion :: HostToTarget ) ;
253
253
this. write_os_str_to_c_str ( & os_str, scalar, size)
254
254
}
255
255
@@ -262,7 +262,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
262
262
size : u64 ,
263
263
) -> InterpResult < ' tcx , ( bool , u64 ) > {
264
264
let this = self . eval_context_mut ( ) ;
265
- let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , Pathconversion :: HostToTarget ) ;
265
+ let os_str = convert_path_separator ( Cow :: Borrowed ( path. as_os_str ( ) ) , & this. tcx . sess . target . target . target_os , Pathconversion :: HostToTarget ) ;
266
266
this. write_os_str_to_wide_str ( & os_str, scalar, size)
267
267
}
268
268
}
0 commit comments