From 512c35121e62062a802dadd787ee3dbda340a624 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 20 Jul 2017 20:00:00 +0200 Subject: [PATCH] Stop reexporting `Errno` and its variants cc #664 (unsure if this is everything needed) --- CHANGELOG.md | 2 ++ src/errno.rs | 4 ++-- src/fcntl.rs | 3 ++- src/lib.rs | 12 ++++++------ src/mount.rs | 3 ++- src/mqueue.rs | 3 ++- src/poll.rs | 3 ++- src/pty.rs | 3 ++- src/sched.rs | 3 ++- src/sys/aio.rs | 3 ++- src/sys/epoll.rs | 3 ++- src/sys/eventfd.rs | 3 ++- src/sys/ioctl/mod.rs | 8 +++++--- src/sys/memfd.rs | 3 ++- src/sys/mman.rs | 3 ++- src/sys/ptrace.rs | 3 ++- src/sys/quota.rs | 3 ++- src/sys/reboot.rs | 3 ++- src/sys/select.rs | 3 ++- src/sys/sendfile.rs | 3 ++- src/sys/signal.rs | 3 ++- src/sys/signalfd.rs | 3 ++- src/sys/socket/addr.rs | 3 ++- src/sys/socket/mod.rs | 3 ++- src/sys/socket/sockopt.rs | 3 ++- src/sys/stat.rs | 3 ++- src/sys/statfs.rs | 3 ++- src/sys/statvfs.rs | 3 ++- src/sys/termios.rs | 3 ++- src/sys/uio.rs | 3 ++- src/sys/wait.rs | 3 ++- src/ucontext.rs | 4 +++- src/unistd.rs | 10 ++++++---- test/sys/test_epoll.rs | 3 ++- test/sys/test_ioctl.rs | 4 ++-- test/sys/test_socket.rs | 3 ++- 36 files changed, 84 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e3994c823..3960244933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). - The syscall module has been removed. This only exposed enough functionality for `memfd_create()` and `pivot_root()`, which are still exposed as separate functions. ([#747](https://github.com/nix-rust/nix/pull/747)) +- The `Errno` variants are no longer reexported from the `errno` module. `Errno` itself is no longer reexported from the + crate root and instead must be accessed using the `errno` module. ([#696](https://github.com/nix-rust/nix/pull/696)) ## [0.9.0] 2017-07-23 diff --git a/src/errno.rs b/src/errno.rs index e7486c8ef6..cbbf83806f 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -3,7 +3,6 @@ use std::{fmt, io, error}; use {Error, Result}; pub use self::consts::*; -pub use self::consts::Errno::*; cfg_if! { if #[cfg(any(target_os = "freebsd", @@ -113,6 +112,7 @@ fn last() -> Errno { } fn desc(errno: Errno) -> &'static str { + use self::Errno::*; match errno { UnknownErrno => "Unknown errno", EPERM => "Operation not permitted", @@ -1898,7 +1898,7 @@ mod consts { #[cfg(test)] mod test { - use super::*; + use super::Errno::*; use nixtest::assert_const_eq; use libc::c_int; diff --git a/src/fcntl.rs b/src/fcntl.rs index f99036d616..86375e4adb 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -1,4 +1,5 @@ -use {Error, Errno, Result, NixPath}; +use {Error, Result, NixPath}; +use errno::Errno; use libc::{self, c_int, c_uint, c_char, size_t, ssize_t}; use sys::stat::Mode; use std::os::unix::io::RawFd; diff --git a/src/lib.rs b/src/lib.rs index cadc7fb41f..a51c5aa485 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ extern crate nix_test as nixtest; pub extern crate libc; -pub use errno::Errno; +use errno::Errno; pub mod errno; pub mod features; @@ -96,24 +96,24 @@ pub enum Error { impl Error { /// Create a nix Error from a given errno - pub fn from_errno(errno: errno::Errno) -> Error { + pub fn from_errno(errno: Errno) -> Error { Error::Sys(errno) } /// Get the current errno and convert it to a nix Error pub fn last() -> Error { - Error::Sys(errno::Errno::last()) + Error::Sys(Errno::last()) } /// Create a new invalid argument error (`EINVAL`) pub fn invalid_argument() -> Error { - Error::Sys(errno::EINVAL) + Error::Sys(Errno::EINVAL) } } -impl From for Error { - fn from(errno: errno::Errno) -> Error { Error::from_errno(errno) } +impl From for Error { + fn from(errno: Errno) -> Error { Error::from_errno(errno) } } impl From for Error { diff --git a/src/mount.rs b/src/mount.rs index ccfd5427df..fb43e24cb1 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -1,6 +1,7 @@ use libc::{c_ulong, c_int}; use libc; -use {Errno, Result, NixPath}; +use {Result, NixPath}; +use errno::Errno; bitflags!( pub struct MsFlags: c_ulong { diff --git a/src/mqueue.rs b/src/mqueue.rs index 4c88045c2a..89bb2784e6 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -2,7 +2,8 @@ //! //! [Further reading and details on the C API](http://man7.org/linux/man-pages/man7/mq_overview.7.html) -use {Errno, Result}; +use Result; +use errno::Errno; use libc::{self, c_char, c_long, mode_t, mqd_t, size_t}; use std::ffi::CString; diff --git a/src/poll.rs b/src/poll.rs index 30a466883e..78229a5bfe 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -5,7 +5,8 @@ use sys::signal::SigSet; use std::os::unix::io::RawFd; use libc; -use {Errno, Result}; +use Result; +use errno::Errno; /// This is a wrapper around `libc::pollfd`. /// diff --git a/src/pty.rs b/src/pty.rs index dbf3420803..d526ed17db 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -10,7 +10,8 @@ use std::mem; use std::os::unix::prelude::*; use sys::termios::Termios; -use {Errno, Result, Error, fcntl}; +use {Result, Error, fcntl}; +use errno::Errno; /// Representation of a master/slave pty pair /// diff --git a/src/sched.rs b/src/sched.rs index 74c2307298..9de1bd10e5 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -2,7 +2,8 @@ use std::mem; use std::os::unix::io::RawFd; use std::option::Option; use libc::{self, c_int, c_void}; -use {Errno, Error, Result}; +use {Error, Result}; +use errno::Errno; use ::unistd::Pid; // For some functions taking with a parameter of type CloneFlags, diff --git a/src/sys/aio.rs b/src/sys/aio.rs index 6166467c0c..fbae444384 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -1,4 +1,5 @@ -use {Error, Errno, Result}; +use {Error, Result}; +use errno::Errno; use std::os::unix::io::RawFd; use libc::{c_void, off_t, size_t}; use libc; diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 5d63e82f6c..43a543ab12 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -1,4 +1,5 @@ -use {Errno, Result}; +use Result; +use errno::Errno; use libc::{self, c_int}; use std::os::unix::io::RawFd; use std::ptr; diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index 51091478b0..c5a54e46a1 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -1,6 +1,7 @@ use libc; use std::os::unix::io::RawFd; -use {Errno, Result}; +use Result; +use errno::Errno; libc_bitflags! { pub struct EfdFlags: libc::c_int { diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index b29c8b422b..4169920bfb 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -66,7 +66,8 @@ //! ``` //! # #[macro_use] extern crate nix; //! # use std::mem; -//! # use nix::{Errno, libc, Result}; +//! # use nix::{libc, Result}; +//! # use nix::errno::Errno; //! # use nix::libc::c_int as c_int; //! # const SPI_IOC_MAGIC: u8 = b'k'; // Defined in linux/spi/spidev.h //! # const SPI_IOC_TYPE_MODE: u8 = 1; @@ -176,7 +177,8 @@ //! ``` //! # #[macro_use] extern crate nix; //! # use std::mem; -//! # use nix::{Errno, libc, Result}; +//! # use nix::{libc, Result}; +//! # use nix::errno::Errno; //! # use nix::libc::c_int as c_int; //! # const SPI_IOC_MAGIC: u8 = b'k'; //! # const SPI_IOC_TYPE_MESSAGE: u8 = 0; @@ -248,7 +250,7 @@ pub use self::platform::*; macro_rules! convert_ioctl_res { ($w:expr) => ( { - $crate::Errno::result($w) + $crate::errno::Errno::result($w) } ); } diff --git a/src/sys/memfd.rs b/src/sys/memfd.rs index 88c1dac987..9672429b31 100644 --- a/src/sys/memfd.rs +++ b/src/sys/memfd.rs @@ -1,6 +1,7 @@ use libc; use std::os::unix::io::RawFd; -use {Errno, Result}; +use Result; +use errno::Errno; use std::ffi::CStr; libc_bitflags!( diff --git a/src/sys/mman.rs b/src/sys/mman.rs index dc21899b71..a32cd54ad3 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -1,4 +1,5 @@ -use {Errno, Error, Result, NixPath}; +use {Error, Result, NixPath}; +use errno::Errno; use fcntl::OFlag; use libc::{self, c_int, c_void, size_t, off_t}; use sys::stat::Mode; diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 43a78862a0..e2b153d8e9 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -1,7 +1,8 @@ //! For detailed description of the ptrace requests, consult `man ptrace`. use std::{mem, ptr}; -use {Errno, Error, Result}; +use {Error, Result}; +use errno::Errno; use libc::{self, c_void, c_long, siginfo_t}; use ::unistd::Pid; use sys::signal::Signal; diff --git a/src/sys/quota.rs b/src/sys/quota.rs index 4a8fdf5eb9..abe114f0a9 100644 --- a/src/sys/quota.rs +++ b/src/sys/quota.rs @@ -15,7 +15,8 @@ use std::default::Default; use std::{mem, ptr}; use libc::{self, c_int, c_char}; -use {Errno, Result, NixPath}; +use {Result, NixPath}; +use errno::Errno; struct QuotaCmd(QuotaSubCmd, QuotaType); diff --git a/src/sys/reboot.rs b/src/sys/reboot.rs index 5b340e32d1..bafa8fc119 100644 --- a/src/sys/reboot.rs +++ b/src/sys/reboot.rs @@ -1,6 +1,7 @@ //! Reboot/shutdown or enable/disable Ctrl-Alt-Delete. -use {Errno, Error, Result}; +use {Error, Result}; +use errno::Errno; use libc; use void::Void; use std::mem::drop; diff --git a/src/sys/select.rs b/src/sys/select.rs index 252fa6bcb6..9a429103ab 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -2,7 +2,8 @@ use std::mem; use std::os::unix::io::RawFd; use std::ptr::null_mut; use libc::{self, c_int}; -use {Errno, Result}; +use Result; +use errno::Errno; use sys::time::TimeVal; pub use libc::FD_SETSIZE; diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs index 2c39ea9019..7f7a775165 100644 --- a/src/sys/sendfile.rs +++ b/src/sys/sendfile.rs @@ -3,7 +3,8 @@ use std::ptr; use libc::{self, off_t}; -use {Errno, Result}; +use Result; +use errno::Errno; pub fn sendfile(out_fd: RawFd, in_fd: RawFd, offset: Option<&mut off_t>, count: usize) -> Result { let offset = offset.map(|offset| offset as *mut _).unwrap_or(ptr::null_mut()); diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 967c641698..f82e450232 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -2,7 +2,8 @@ // See http://rust-lang.org/COPYRIGHT. use libc; -use {Errno, Error, Result}; +use {Error, Result}; +use errno::Errno; use std::mem; #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] use std::os::unix::io::RawFd; diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs index bbd38b23be..7ea09ee349 100644 --- a/src/sys/signalfd.rs +++ b/src/sys/signalfd.rs @@ -17,7 +17,8 @@ //! signal handlers. use libc; use unistd; -use {Error, Errno, Result}; +use {Error, Result}; +use errno::Errno; pub use sys::signal::{self, SigSet}; pub use libc::signalfd_siginfo as siginfo; diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 29832b3700..9917fdfd80 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1,5 +1,6 @@ use super::sa_family_t; -use {Errno, Error, Result, NixPath}; +use {Error, Result, NixPath}; +use errno::Errno; use libc; use std::{fmt, hash, mem, net, ptr, slice}; use std::ffi::OsStr; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index cdb8b4b3d9..c7d6d5814d 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1,7 +1,8 @@ //! Socket interface functions //! //! [Further reading](http://man7.org/linux/man-pages/man7/socket.7.html) -use {Error, Errno, Result}; +use {Error, Result}; +use errno::Errno; use features; use libc::{self, c_void, c_int, socklen_t, size_t, pid_t, uid_t, gid_t}; use std::{mem, ptr, slice}; diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 98a4eeac75..4741ec6640 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -1,5 +1,6 @@ use super::{GetSockOpt, SetSockOpt}; -use {Errno, Result}; +use Result; +use errno::Errno; use sys::time::TimeVal; use libc::{self, c_int, uint8_t, c_void, socklen_t}; use std::mem; diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 7a0b3970ce..9c0129f5e7 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -1,7 +1,8 @@ pub use libc::dev_t; pub use libc::stat as FileStat; -use {Errno, Result, NixPath}; +use {Result, NixPath}; +use errno::Errno; use fcntl::AtFlags; use libc::{self, mode_t}; use std::mem; diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs index afa61468fd..6d4fafe968 100644 --- a/src/sys/statfs.rs +++ b/src/sys/statfs.rs @@ -1,4 +1,5 @@ -use {Errno, Result, NixPath}; +use {Result, NixPath}; +use errno::Errno; use std::os::unix::io::AsRawFd; use libc; diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs index 2cfc61af98..0a0dab7fe8 100644 --- a/src/sys/statvfs.rs +++ b/src/sys/statvfs.rs @@ -7,7 +7,8 @@ use std::os::unix::io::AsRawFd; use libc::{self, c_ulong}; -use {Errno, Result, NixPath}; +use {Result, NixPath}; +use errno::Errno; bitflags!( /// File system mount Flags diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 34d960ff52..e27cee40c1 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -43,7 +43,8 @@ //! termios.control_flags |= ControlFlags::CS5; //! ``` -use {Errno, Result}; +use Result; +use errno::Errno; use libc::{self, c_int, tcflag_t}; use std::cell::{Ref, RefCell}; use std::convert::From; diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 16426ab91f..cd1614239c 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -1,7 +1,8 @@ // Silence invalid warnings due to rust-lang/rust#16719 #![allow(improper_ctypes)] -use {Errno, Result}; +use Result; +use errno::Errno; use libc::{self, c_int, c_void, size_t, off_t}; use std::marker::PhantomData; use std::os::unix::io::RawFd; diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 019b751f9c..6243634fad 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -1,5 +1,6 @@ use libc::{self, c_int}; -use {Errno, Result}; +use Result; +use errno::Errno; use unistd::Pid; use sys::signal::Signal; diff --git a/src/ucontext.rs b/src/ucontext.rs index 6886dd4151..da5a5b1322 100644 --- a/src/ucontext.rs +++ b/src/ucontext.rs @@ -1,6 +1,8 @@ use libc; #[cfg(not(target_env = "musl"))] -use {Errno, Result}; +use Result; +#[cfg(not(target_env = "musl"))] +use errno::Errno; use std::mem; use sys::signal::SigSet; diff --git a/src/unistd.rs b/src/unistd.rs index 4e27d675db..c3c78414ae 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1,7 +1,7 @@ //! Safe wrappers around functions found in libc "unistd.h" header -use errno; -use {Errno, Error, Result, NixPath}; +use errno::{self, Errno}; +use {Error, Result, NixPath}; use fcntl::{fcntl, FdFlag, OFlag}; use fcntl::FcntlArg::F_SETFD; use libc::{self, c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t, @@ -1942,7 +1942,8 @@ pub fn sysconf(var: SysconfVar) -> Result> { #[cfg(any(target_os = "android", target_os = "linux"))] mod pivot_root { use libc; - use {Errno, Result, NixPath}; + use {Result, NixPath}; + use errno::Errno; pub fn pivot_root( new_root: &P1, put_old: &P2) -> Result<()> { @@ -1962,7 +1963,8 @@ mod pivot_root { target_os = "linux", target_os = "openbsd"))] mod setres { use libc; - use {Errno, Result}; + use Result; + use errno::Errno; use super::{Uid, Gid}; /// Sets the real, effective, and saved uid. diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs index e32a4e23af..e0dc5131de 100644 --- a/test/sys/test_epoll.rs +++ b/test/sys/test_epoll.rs @@ -1,6 +1,7 @@ use nix::sys::epoll::{EpollCreateFlags, EpollFlags, EpollOp, EpollEvent}; use nix::sys::epoll::{epoll_create1, epoll_ctl}; -use nix::{Error, Errno}; +use nix::Error; +use nix::errno::Errno; #[test] pub fn test_epoll_errno() { diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 1b9e464b97..1ed4a4b4b9 100644 --- a/test/sys/test_ioctl.rs +++ b/test/sys/test_ioctl.rs @@ -210,7 +210,7 @@ mod linux_ioctls { use libc::{TCGETS, TCSBRK, TCSETS, TIOCNXCL, termios}; use nix::Error::Sys; - use nix::errno::{ENOTTY, ENOSYS}; + use nix::errno::Errno::{ENOTTY, ENOSYS}; ioctl!(bad none tiocnxcl with TIOCNXCL); #[test] @@ -345,7 +345,7 @@ mod freebsd_ioctls { use libc::termios; use nix::Error::Sys; - use nix::errno::ENOTTY; + use nix::errno::Errno::ENOTTY; // From sys/sys/ttycom.h const TTY_IOC_MAGIC: u8 = b't'; diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 8ec7f1fd21..d29b2ecb1e 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -242,7 +242,8 @@ pub fn test_unixdomain() { #[cfg(any(target_os = "macos", target_os = "ios"))] #[test] pub fn test_syscontrol() { - use nix::{Errno, Error}; + use nix::Error; + use nix::errno::Errno; use nix::sys::socket::{AddressFamily, socket, SockAddr, SockType, SockFlag, SockProtocol}; let fd = socket(AddressFamily::System, SockType::Datagram,