1+ use std:: any:: Any ;
12use std:: borrow:: Cow ;
23use std:: collections:: BTreeMap ;
34use std:: convert:: TryInto ;
@@ -24,7 +25,7 @@ pub struct FileHandle {
2425 writable : bool ,
2526}
2627
27- pub trait FileDescriptor : std:: fmt:: Debug + helpers :: AsAny {
28+ pub trait FileDescriptor : std:: fmt:: Debug + Any {
2829 fn name ( & self ) -> & ' static str ;
2930
3031 fn read < ' tcx > (
@@ -72,6 +73,18 @@ pub trait FileDescriptor: std::fmt::Debug + helpers::AsAny {
7273 }
7374}
7475
76+ impl dyn FileDescriptor {
77+ #[ inline( always) ]
78+ pub fn downcast_ref < T : Any > ( & self ) -> Option < & T > {
79+ ( self as & dyn Any ) . downcast_ref ( )
80+ }
81+
82+ #[ inline( always) ]
83+ pub fn downcast_mut < T : Any > ( & mut self ) -> Option < & mut T > {
84+ ( self as & mut dyn Any ) . downcast_mut ( )
85+ }
86+ }
87+
7588impl FileDescriptor for FileHandle {
7689 fn name ( & self ) -> & ' static str {
7790 "FILE"
@@ -689,7 +702,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
689702 if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
690703 // FIXME: Support fullfsync for all FDs
691704 let FileHandle { file, writable } =
692- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
705+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
693706 err_unsup_format ! (
694707 "`F_FULLFSYNC` is only supported on file-backed file descriptors"
695708 )
@@ -1522,7 +1535,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
15221535 if let Some ( file_descriptor) = this. machine . file_handler . handles . get_mut ( & fd) {
15231536 // FIXME: Support ftruncate64 for all FDs
15241537 let FileHandle { file, writable } =
1525- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1538+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
15261539 err_unsup_format ! (
15271540 "`ftruncate64` is only supported on file-backed file descriptors"
15281541 )
@@ -1568,7 +1581,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
15681581 if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
15691582 // FIXME: Support fsync for all FDs
15701583 let FileHandle { file, writable } =
1571- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1584+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
15721585 err_unsup_format ! ( "`fsync` is only supported on file-backed file descriptors" )
15731586 } ) ?;
15741587 let io_result = maybe_sync_file ( file, * writable, File :: sync_all) ;
@@ -1593,7 +1606,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
15931606 if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
15941607 // FIXME: Support fdatasync for all FDs
15951608 let FileHandle { file, writable } =
1596- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1609+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
15971610 err_unsup_format ! (
15981611 "`fdatasync` is only supported on file-backed file descriptors"
15991612 )
@@ -1643,7 +1656,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
16431656 if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
16441657 // FIXME: Support sync_data_range for all FDs
16451658 let FileHandle { file, writable } =
1646- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1659+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
16471660 err_unsup_format ! (
16481661 "`sync_data_range` is only supported on file-backed file descriptors"
16491662 )
@@ -1953,7 +1966,6 @@ impl FileMetadata {
19531966 let file = match option {
19541967 Some ( file_descriptor) =>
19551968 & file_descriptor
1956- . as_any ( )
19571969 . downcast_ref :: < FileHandle > ( )
19581970 . ok_or_else ( || {
19591971 err_unsup_format ! (
0 commit comments