Skip to content

Commit e1e1f42

Browse files
committed
make errno table syntactically more similar to rustc library code
1 parent 9154f8b commit e1e1f42

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

src/helpers.rs

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,51 @@ use crate::*;
2323

2424
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
2525

26-
// This mapping is the reverse of `decode_error_kind` in
27-
// <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/mod.rs>
28-
// and should be kept in sync.
29-
const UNIX_IO_ERROR_TABLE: &[(std::io::ErrorKind, &str)] = {
26+
// This mapping should match `decode_error_kind` in
27+
// <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/mod.rs>.
28+
const UNIX_IO_ERROR_TABLE: &[(&str, std::io::ErrorKind)] = {
3029
use std::io::ErrorKind::*;
3130
&[
32-
(ArgumentListTooLong, "E2BIG"),
33-
(AddrInUse, "EADDRINUSE"),
34-
(AddrNotAvailable, "EADDRNOTAVAIL"),
35-
(ResourceBusy, "EBUSY"),
36-
(ConnectionAborted, "ECONNABORTED"),
37-
(ConnectionRefused, "ECONNREFUSED"),
38-
(ConnectionReset, "ECONNRESET"),
39-
(Deadlock, "EDEADLK"),
40-
(FilesystemQuotaExceeded, "EDQUOT"),
41-
(AlreadyExists, "EEXIST"),
42-
(FileTooLarge, "EFBIG"),
43-
(HostUnreachable, "EHOSTUNREACH"),
44-
(Interrupted, "EINTR"),
45-
(InvalidInput, "EINVAL"),
46-
(IsADirectory, "EISDIR"),
47-
(FilesystemLoop, "ELOOP"),
48-
(NotFound, "ENOENT"),
49-
(OutOfMemory, "ENOMEM"),
50-
(StorageFull, "ENOSPC"),
51-
(Unsupported, "ENOSYS"),
52-
(TooManyLinks, "EMLINK"),
53-
(InvalidFilename, "ENAMETOOLONG"),
54-
(NetworkDown, "ENETDOWN"),
55-
(NetworkUnreachable, "ENETUNREACH"),
56-
(NotConnected, "ENOTCONN"),
57-
(NotADirectory, "ENOTDIR"),
58-
(DirectoryNotEmpty, "ENOTEMPTY"),
59-
(BrokenPipe, "EPIPE"),
60-
(ReadOnlyFilesystem, "EROFS"),
61-
(NotSeekable, "ESPIPE"),
62-
(StaleNetworkFileHandle, "ESTALE"),
63-
(TimedOut, "ETIMEDOUT"),
64-
(ExecutableFileBusy, "ETXTBSY"),
65-
(CrossesDevices, "EXDEV"),
66-
// The following have two valid options...we pick one.
67-
(PermissionDenied, "EPERM"),
68-
(WouldBlock, "EWOULDBLOCK"),
31+
("E2BIG", ArgumentListTooLong),
32+
("EADDRINUSE", AddrInUse),
33+
("EADDRNOTAVAIL", AddrNotAvailable),
34+
("EBUSY", ResourceBusy),
35+
("ECONNABORTED", ConnectionAborted),
36+
("ECONNREFUSED", ConnectionRefused),
37+
("ECONNRESET", ConnectionReset),
38+
("EDEADLK", Deadlock),
39+
("EDQUOT", FilesystemQuotaExceeded),
40+
("EEXIST", AlreadyExists),
41+
("EFBIG", FileTooLarge),
42+
("EHOSTUNREACH", HostUnreachable),
43+
("EINTR", Interrupted),
44+
("EINVAL", InvalidInput),
45+
("EISDIR", IsADirectory),
46+
("ELOOP", FilesystemLoop),
47+
("ENOENT", NotFound),
48+
("ENOMEM", OutOfMemory),
49+
("ENOSPC", StorageFull),
50+
("ENOSYS", Unsupported),
51+
("EMLINK", TooManyLinks),
52+
("ENAMETOOLONG", InvalidFilename),
53+
("ENETDOWN", NetworkDown),
54+
("ENETUNREACH", NetworkUnreachable),
55+
("ENOTCONN", NotConnected),
56+
("ENOTDIR", NotADirectory),
57+
("ENOTEMPTY", DirectoryNotEmpty),
58+
("EPIPE", BrokenPipe),
59+
("EROFS", ReadOnlyFilesystem),
60+
("ESPIPE", NotSeekable),
61+
("ESTALE", StaleNetworkFileHandle),
62+
("ETIMEDOUT", TimedOut),
63+
("ETXTBSY", ExecutableFileBusy),
64+
("EXDEV", CrossesDevices),
65+
// The following have two valid options. We have both for the forwards mapping; only the
66+
// first one will be used for the backwards mapping.
67+
("EPERM", PermissionDenied),
68+
("EACCES", PermissionDenied),
69+
("EWOULDBLOCK", WouldBlock),
70+
("EAGAIN", WouldBlock),
6971
]
7072
};
7173

@@ -577,7 +579,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
577579
let this = self.eval_context_ref();
578580
let target = &this.tcx.sess.target;
579581
if target.families.iter().any(|f| f == "unix") {
580-
for &(kind, name) in UNIX_IO_ERROR_TABLE {
582+
for &(name, kind) in UNIX_IO_ERROR_TABLE {
581583
if err_kind == kind {
582584
return this.eval_libc(name);
583585
}
@@ -615,7 +617,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
615617
let target = &this.tcx.sess.target;
616618
if target.families.iter().any(|f| f == "unix") {
617619
let errnum = errnum.to_i32()?;
618-
for &(kind, name) in UNIX_IO_ERROR_TABLE {
620+
for &(name, kind) in UNIX_IO_ERROR_TABLE {
619621
if errnum == this.eval_libc_i32(name)? {
620622
return Ok(kind);
621623
}

0 commit comments

Comments
 (0)