diff options
author | David Tolnay <dtolnay@chromium.org> | 2019-04-12 11:27:37 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-15 02:06:04 -0700 |
commit | a70a2193ad10a6e0f2e28c45a2e75fff6a102f22 (patch) | |
tree | 6e001f53cfdeed7bdd0f10b15ce2ef56d9226360 /sys_util/src | |
parent | 1b7f3ed23505b83343b376c8d8777366457402d0 (diff) | |
download | crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.tar crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.tar.gz crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.tar.bz2 crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.tar.lz crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.tar.xz crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.tar.zst crosvm-a70a2193ad10a6e0f2e28c45a2e75fff6a102f22.zip |
sys_util: Enable macros imported individually
The syslog and ioctl macros in sys_util were originally written to be imported through `#[macro_use] extern crate sys_util` which is essentially a glob import of all macros from the crate. In 2018 edition, extern crate is deprecated and macros are imported the same as any other item. As these sys_util macros are currently written, importing an individual macro requires the caller to also import any other sys_util macros that the invocation internally expands to. Example: use sys_util::{error, log}; fn main() { error!("..."); } This CL adjusts all sys_util macros to invoke helper macros through a `$crate::` prefix so that the caller is not required to have the helper macros in scope themselves. use sys_util::error; fn main() { error!("..."); } TEST=kokoro Change-Id: I2d9f16dca8e7a4a4c0e63d9f10ead9f7413d9c3c Reviewed-on: https://chromium-review.googlesource.com/1565544 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'sys_util/src')
-rw-r--r-- | sys_util/src/handle_eintr.rs | 2 | ||||
-rw-r--r-- | sys_util/src/ioctl.rs | 20 | ||||
-rw-r--r-- | sys_util/src/syslog.rs | 13 |
3 files changed, 16 insertions, 19 deletions
diff --git a/sys_util/src/handle_eintr.rs b/sys_util/src/handle_eintr.rs index 39baf6d..670e8d2 100644 --- a/sys_util/src/handle_eintr.rs +++ b/sys_util/src/handle_eintr.rs @@ -111,7 +111,7 @@ impl<T> InterruptibleResult for io::Result<T> { /// # Examples /// /// ``` -/// # #[macro_use] extern crate sys_util; +/// # use sys_util::handle_eintr; /// # use std::io::stdin; /// # fn main() { /// let mut line = String::new(); diff --git a/sys_util/src/ioctl.rs b/sys_util/src/ioctl.rs index 2b4ae00..a0309ff 100644 --- a/sys_util/src/ioctl.rs +++ b/sys_util/src/ioctl.rs @@ -26,13 +26,13 @@ macro_rules! ioctl_ioc_nr { ($name:ident, $dir:expr, $ty:expr, $nr:expr, $size:expr) => { #[allow(non_snake_case)] pub fn $name() -> ::std::os::raw::c_ulong { - ioctl_expr!($dir, $ty, $nr, $size) + $crate::ioctl_expr!($dir, $ty, $nr, $size) } }; ($name:ident, $dir:expr, $ty:expr, $nr:expr, $size:expr, $($v:ident),+) => { #[allow(non_snake_case)] pub fn $name($($v: ::std::os::raw::c_uint),+) -> ::std::os::raw::c_ulong { - ioctl_expr!($dir, $ty, $nr, $size) + $crate::ioctl_expr!($dir, $ty, $nr, $size) } }; } @@ -41,10 +41,10 @@ macro_rules! ioctl_ioc_nr { #[macro_export] macro_rules! ioctl_io_nr { ($name:ident, $ty:expr, $nr:expr) => { - ioctl_ioc_nr!($name, $crate::ioctl::_IOC_NONE, $ty, $nr, 0); + $crate::ioctl_ioc_nr!($name, $crate::ioctl::_IOC_NONE, $ty, $nr, 0); }; ($name:ident, $ty:expr, $nr:expr, $($v:ident),+) => { - ioctl_ioc_nr!($name, $crate::ioctl::_IOC_NONE, $ty, $nr, 0, $($v),+); + $crate::ioctl_ioc_nr!($name, $crate::ioctl::_IOC_NONE, $ty, $nr, 0, $($v),+); }; } @@ -52,7 +52,7 @@ macro_rules! ioctl_io_nr { #[macro_export] macro_rules! ioctl_ior_nr { ($name:ident, $ty:expr, $nr:expr, $size:ty) => { - ioctl_ioc_nr!( + $crate::ioctl_ioc_nr!( $name, $crate::ioctl::_IOC_READ, $ty, @@ -61,7 +61,7 @@ macro_rules! ioctl_ior_nr { ); }; ($name:ident, $ty:expr, $nr:expr, $size:ty, $($v:ident),+) => { - ioctl_ioc_nr!( + $crate::ioctl_ioc_nr!( $name, $crate::ioctl::_IOC_READ, $ty, @@ -76,7 +76,7 @@ macro_rules! ioctl_ior_nr { #[macro_export] macro_rules! ioctl_iow_nr { ($name:ident, $ty:expr, $nr:expr, $size:ty) => { - ioctl_ioc_nr!( + $crate::ioctl_ioc_nr!( $name, $crate::ioctl::_IOC_WRITE, $ty, @@ -85,7 +85,7 @@ macro_rules! ioctl_iow_nr { ); }; ($name:ident, $ty:expr, $nr:expr, $size:ty, $($v:ident),+) => { - ioctl_ioc_nr!( + $crate::ioctl_ioc_nr!( $name, $crate::ioctl::_IOC_WRITE, $ty, @@ -100,7 +100,7 @@ macro_rules! ioctl_iow_nr { #[macro_export] macro_rules! ioctl_iowr_nr { ($name:ident, $ty:expr, $nr:expr, $size:ty) => { - ioctl_ioc_nr!( + $crate::ioctl_ioc_nr!( $name, $crate::ioctl::_IOC_READ | $crate::ioctl::_IOC_WRITE, $ty, @@ -109,7 +109,7 @@ macro_rules! ioctl_iowr_nr { ); }; ($name:ident, $ty:expr, $nr:expr, $size:ty, $($v:ident),+) => { - ioctl_ioc_nr!( + $crate::ioctl_ioc_nr!( $name, $crate::ioctl::_IOC_READ | $crate::ioctl::_IOC_WRITE, $ty, diff --git a/sys_util/src/syslog.rs b/sys_util/src/syslog.rs index a87a2ea..af5cefc 100644 --- a/sys_util/src/syslog.rs +++ b/sys_util/src/syslog.rs @@ -10,9 +10,7 @@ //! # Examples //! //! ``` -//! #[macro_use] extern crate sys_util; -//! -//! use sys_util::syslog; +//! use sys_util::{error, syslog, warn}; //! //! fn main() { //! if let Err(e) = syslog::init() { @@ -396,7 +394,6 @@ fn get_localtime() -> tm { /// # Examples /// /// ``` -/// # #[macro_use] extern crate sys_util; /// # use sys_util::syslog; /// # fn main() { /// # if let Err(e) = syslog::init() { @@ -479,7 +476,7 @@ macro_rules! log { /// Note that this will fail silently if syslog was not initialized. #[macro_export] macro_rules! error { - ($($args:tt)+) => (log!($crate::syslog::Priority::Error, $($args)*)) + ($($args:tt)+) => ($crate::log!($crate::syslog::Priority::Error, $($args)*)) } /// A macro for logging a warning. @@ -487,7 +484,7 @@ macro_rules! error { /// Note that this will fail silently if syslog was not initialized. #[macro_export] macro_rules! warn { - ($($args:tt)+) => (log!($crate::syslog::Priority::Warning, $($args)*)) + ($($args:tt)+) => ($crate::log!($crate::syslog::Priority::Warning, $($args)*)) } /// A macro for logging info. @@ -495,7 +492,7 @@ macro_rules! warn { /// Note that this will fail silently if syslog was not initialized. #[macro_export] macro_rules! info { - ($($args:tt)+) => (log!($crate::syslog::Priority::Info, $($args)*)) + ($($args:tt)+) => ($crate::log!($crate::syslog::Priority::Info, $($args)*)) } /// A macro for logging debug information. @@ -503,7 +500,7 @@ macro_rules! info { /// Note that this will fail silently if syslog was not initialized. #[macro_export] macro_rules! debug { - ($($args:tt)+) => (log!($crate::syslog::Priority::Debug, $($args)*)) + ($($args:tt)+) => ($crate::log!($crate::syslog::Priority::Debug, $($args)*)) } #[cfg(test)] |