@@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
179
179
let this = self . eval_context_ref ( ) ;
180
180
let os_str: & ' a OsStr = this. read_os_str_from_c_str ( scalar) ?;
181
181
182
- Ok ( match convert_path_separator ( os_str, & this. tcx . sess . target . target . target_os , false ) {
182
+ Ok ( match convert_path_separator ( os_str, & this. tcx . sess . target . target . target_os , PathConversionDirection :: TargetToHost ) {
183
183
Cow :: Borrowed ( x) => Cow :: Borrowed ( Path :: new ( x) ) ,
184
184
Cow :: Owned ( y) => Cow :: Owned ( PathBuf :: from ( y) ) ,
185
185
} )
@@ -190,7 +190,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
190
190
let this = self . eval_context_ref ( ) ;
191
191
let os_str: OsString = this. read_os_str_from_wide_str ( scalar) ?;
192
192
193
- Ok ( PathBuf :: from ( & convert_path_separator ( & os_str, & this. tcx . sess . target . target . target_os , false ) ) )
193
+ Ok ( PathBuf :: from ( & convert_path_separator ( & os_str, & this. tcx . sess . target . target . target_os , PathConversionDirection :: TargetToHost ) ) )
194
194
}
195
195
196
196
/// Write a Path to the machine memory (as a null-terminated sequence of bytes),
@@ -202,7 +202,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
202
202
size : u64 ,
203
203
) -> InterpResult < ' tcx , ( bool , u64 ) > {
204
204
let this = self . eval_context_mut ( ) ;
205
- let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , true ) ;
205
+ let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , PathConversionDirection :: HostToTarget ) ;
206
206
this. write_os_str_to_c_str ( & os_str, scalar, size)
207
207
}
208
208
@@ -215,26 +215,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
215
215
size : u64 ,
216
216
) -> InterpResult < ' tcx , ( bool , u64 ) > {
217
217
let this = self . eval_context_mut ( ) ;
218
- let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , true ) ;
218
+ let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , PathConversionDirection :: HostToTarget ) ;
219
219
this. write_os_str_to_wide_str ( & os_str, scalar, size)
220
220
}
221
221
}
222
222
223
+ enum PathConversionDirection {
224
+ HostToTarget ,
225
+ TargetToHost ,
226
+ }
227
+
223
228
/// Perform path separator conversion if needed.
224
- /// if direction == true, Convert from 'host' to 'target'.
225
- /// if direction == false, Convert from 'target' to 'host'.
226
229
fn convert_path_separator < ' a > (
227
230
os_str : & ' a OsStr ,
228
231
target_os : & str ,
229
- direction : bool ,
232
+ direction : PathConversionDirection ,
230
233
) -> Cow < ' a , OsStr > {
231
234
#[ cfg( windows) ]
232
235
return if target_os == "windows" {
233
236
// Windows-on-Windows, all fine.
234
237
Cow :: Borrowed ( os_str)
235
238
} else {
236
239
// Unix target, Windows host.
237
- let ( from, to) = if direction { ( '\\' , '/' ) } else { ( '/' , '\\' ) } ;
240
+ let ( from, to) = match direction {
241
+ PathConversionDirection :: HostToTarget => ( '\\' , '/' ) ,
242
+ PathConversionDirection :: TargetToHost => ( '/' , '\\' ) ,
243
+ } ;
238
244
let converted = os_str
239
245
. encode_wide ( )
240
246
. map ( |wchar| if wchar == from as u16 { to as u16 } else { wchar } )
@@ -244,7 +250,10 @@ fn convert_path_separator<'a>(
244
250
#[ cfg( unix) ]
245
251
return if target_os == "windows" {
246
252
// Windows target, Unix host.
247
- let ( from, to) = if direction { ( '/' , '\\' ) } else { ( '\\' , '/' ) } ;
253
+ let ( from, to) = match direction {
254
+ PathConversionDirection :: HostToTarget => ( '/' , '\\' ) ,
255
+ PathConversionDirection :: TargetToHost => ( '\\' , '/' ) ,
256
+ } ;
248
257
let converted = os_str
249
258
. as_bytes ( )
250
259
. iter ( )
0 commit comments