@@ -137,37 +137,28 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx
137
137
& mut self ,
138
138
file_type : std:: io:: Result < FileType > ,
139
139
) -> InterpResult < ' tcx , i32 > {
140
+ #[ cfg( unix) ]
141
+ use std:: os:: unix:: fs:: FileTypeExt ;
142
+
140
143
let this = self . eval_context_mut ( ) ;
141
144
match file_type {
142
145
Ok ( file_type) => {
143
- if file_type. is_dir ( ) {
144
- Ok ( this. eval_libc ( "DT_DIR" ) . to_u8 ( ) ?. into ( ) )
145
- } else if file_type. is_file ( ) {
146
- Ok ( this. eval_libc ( "DT_REG" ) . to_u8 ( ) ?. into ( ) )
147
- } else if file_type. is_symlink ( ) {
148
- Ok ( this. eval_libc ( "DT_LNK" ) . to_u8 ( ) ?. into ( ) )
149
- } else {
146
+ match ( ) {
147
+ _ if file_type. is_dir ( ) => Ok ( this. eval_libc ( "DT_DIR" ) . to_u8 ( ) ?. into ( ) ) ,
148
+ _ if file_type. is_file ( ) => Ok ( this. eval_libc ( "DT_REG" ) . to_u8 ( ) ?. into ( ) ) ,
149
+ _ if file_type. is_symlink ( ) => Ok ( this. eval_libc ( "DT_LNK" ) . to_u8 ( ) ?. into ( ) ) ,
150
150
// Certain file types are only supported when the host is a Unix system.
151
- // (i.e. devices and sockets) If it is, check those cases, if not, fall back to
152
- // DT_UNKNOWN sooner.
153
-
154
151
#[ cfg( unix) ]
155
- {
156
- use std:: os:: unix:: fs:: FileTypeExt ;
157
- if file_type. is_block_device ( ) {
158
- Ok ( this. eval_libc ( "DT_BLK" ) . to_u8 ( ) ?. into ( ) )
159
- } else if file_type. is_char_device ( ) {
160
- Ok ( this. eval_libc ( "DT_CHR" ) . to_u8 ( ) ?. into ( ) )
161
- } else if file_type. is_fifo ( ) {
162
- Ok ( this. eval_libc ( "DT_FIFO" ) . to_u8 ( ) ?. into ( ) )
163
- } else if file_type. is_socket ( ) {
164
- Ok ( this. eval_libc ( "DT_SOCK" ) . to_u8 ( ) ?. into ( ) )
165
- } else {
166
- Ok ( this. eval_libc ( "DT_UNKNOWN" ) . to_u8 ( ) ?. into ( ) )
167
- }
168
- }
169
- #[ cfg( not( unix) ) ]
170
- Ok ( this. eval_libc ( "DT_UNKNOWN" ) . to_u8 ( ) ?. into ( ) )
152
+ _ if file_type. is_block_device ( ) =>
153
+ Ok ( this. eval_libc ( "DT_BLK" ) . to_u8 ( ) ?. into ( ) ) ,
154
+ #[ cfg( unix) ]
155
+ _ if file_type. is_char_device ( ) => Ok ( this. eval_libc ( "DT_CHR" ) . to_u8 ( ) ?. into ( ) ) ,
156
+ #[ cfg( unix) ]
157
+ _ if file_type. is_fifo ( ) => Ok ( this. eval_libc ( "DT_FIFO" ) . to_u8 ( ) ?. into ( ) ) ,
158
+ #[ cfg( unix) ]
159
+ _ if file_type. is_socket ( ) => Ok ( this. eval_libc ( "DT_SOCK" ) . to_u8 ( ) ?. into ( ) ) ,
160
+ // Fallback
161
+ _ => Ok ( this. eval_libc ( "DT_UNKNOWN" ) . to_u8 ( ) ?. into ( ) ) ,
171
162
}
172
163
}
173
164
Err ( e) =>
@@ -1314,7 +1305,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1314
1305
}
1315
1306
}
1316
1307
1317
- #[ cfg_attr( not( unix) , allow( unused) ) ]
1318
1308
fn isatty (
1319
1309
& mut self ,
1320
1310
miri_fd : & OpTy < ' tcx , Provenance > ,
@@ -1467,8 +1457,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1467
1457
#[ cfg( unix) ]
1468
1458
{
1469
1459
use std:: os:: unix:: fs:: OpenOptionsExt ;
1470
- fopts. mode ( 0o600 ) ;
1471
1460
// Do not allow others to read or modify this file.
1461
+ fopts. mode ( 0o600 ) ;
1472
1462
fopts. custom_flags ( libc:: O_EXCL ) ;
1473
1463
}
1474
1464
#[ cfg( windows) ]
0 commit comments