@@ -137,37 +137,28 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx
137137 & mut self ,
138138 file_type : std:: io:: Result < FileType > ,
139139 ) -> InterpResult < ' tcx , i32 > {
140+ #[ cfg( unix) ]
141+ use std:: os:: unix:: fs:: FileTypeExt ;
142+
140143 let this = self . eval_context_mut ( ) ;
141144 match file_type {
142145 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 ( ) ) ,
150150 // 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-
154151 #[ 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 ( ) ) ,
171162 }
172163 }
173164 Err ( e) =>
@@ -1314,7 +1305,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
13141305 }
13151306 }
13161307
1317- #[ cfg_attr( not( unix) , allow( unused) ) ]
13181308 fn isatty (
13191309 & mut self ,
13201310 miri_fd : & OpTy < ' tcx , Provenance > ,
@@ -1467,8 +1457,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
14671457 #[ cfg( unix) ]
14681458 {
14691459 use std:: os:: unix:: fs:: OpenOptionsExt ;
1470- fopts. mode ( 0o600 ) ;
14711460 // Do not allow others to read or modify this file.
1461+ fopts. mode ( 0o600 ) ;
14721462 fopts. custom_flags ( libc:: O_EXCL ) ;
14731463 }
14741464 #[ cfg( windows) ]
0 commit comments