1
+ use std:: any:: Any ;
1
2
use std:: borrow:: Cow ;
2
3
use std:: collections:: BTreeMap ;
3
4
use std:: convert:: TryInto ;
@@ -24,7 +25,7 @@ pub struct FileHandle {
24
25
writable : bool ,
25
26
}
26
27
27
- pub trait FileDescriptor : std:: fmt:: Debug + helpers :: AsAny {
28
+ pub trait FileDescriptor : std:: fmt:: Debug + Any {
28
29
fn name ( & self ) -> & ' static str ;
29
30
30
31
fn read < ' tcx > (
@@ -72,6 +73,18 @@ pub trait FileDescriptor: std::fmt::Debug + helpers::AsAny {
72
73
}
73
74
}
74
75
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
+
75
88
impl FileDescriptor for FileHandle {
76
89
fn name ( & self ) -> & ' static str {
77
90
"FILE"
@@ -689,7 +702,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
689
702
if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
690
703
// FIXME: Support fullfsync for all FDs
691
704
let FileHandle { file, writable } =
692
- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
705
+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
693
706
err_unsup_format ! (
694
707
"`F_FULLFSYNC` is only supported on file-backed file descriptors"
695
708
)
@@ -1522,7 +1535,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1522
1535
if let Some ( file_descriptor) = this. machine . file_handler . handles . get_mut ( & fd) {
1523
1536
// FIXME: Support ftruncate64 for all FDs
1524
1537
let FileHandle { file, writable } =
1525
- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1538
+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1526
1539
err_unsup_format ! (
1527
1540
"`ftruncate64` is only supported on file-backed file descriptors"
1528
1541
)
@@ -1568,7 +1581,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1568
1581
if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
1569
1582
// FIXME: Support fsync for all FDs
1570
1583
let FileHandle { file, writable } =
1571
- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1584
+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1572
1585
err_unsup_format ! ( "`fsync` is only supported on file-backed file descriptors" )
1573
1586
} ) ?;
1574
1587
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> {
1593
1606
if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
1594
1607
// FIXME: Support fdatasync for all FDs
1595
1608
let FileHandle { file, writable } =
1596
- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1609
+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1597
1610
err_unsup_format ! (
1598
1611
"`fdatasync` is only supported on file-backed file descriptors"
1599
1612
)
@@ -1643,7 +1656,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1643
1656
if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
1644
1657
// FIXME: Support sync_data_range for all FDs
1645
1658
let FileHandle { file, writable } =
1646
- file_descriptor. as_any ( ) . downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1659
+ file_descriptor. downcast_ref :: < FileHandle > ( ) . ok_or_else ( || {
1647
1660
err_unsup_format ! (
1648
1661
"`sync_data_range` is only supported on file-backed file descriptors"
1649
1662
)
@@ -1953,7 +1966,6 @@ impl FileMetadata {
1953
1966
let file = match option {
1954
1967
Some ( file_descriptor) =>
1955
1968
& file_descriptor
1956
- . as_any ( )
1957
1969
. downcast_ref :: < FileHandle > ( )
1958
1970
. ok_or_else ( || {
1959
1971
err_unsup_format ! (
0 commit comments