From 5be9bac7df20b59569082edb0ebc5fdbabda1db2 Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Wed, 11 May 2022 13:53:54 -0500 Subject: [PATCH] metrics: fix compilation with unstable, process, and rt --- tokio/src/io/driver/metrics.rs | 10 ++++++---- tokio/src/io/driver/mod.rs | 28 +++++++++++++++------------- tokio/src/macros/cfg.rs | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/tokio/src/io/driver/metrics.rs b/tokio/src/io/driver/metrics.rs index 410732ce7dd..ec341efe680 100644 --- a/tokio/src/io/driver/metrics.rs +++ b/tokio/src/io/driver/metrics.rs @@ -4,7 +4,7 @@ //! these need to be available in the case when `net` is enabled but //! `rt` is not. -cfg_not_rt_and_metrics! { +cfg_not_rt_and_metrics_and_net! { #[derive(Default)] pub(crate) struct IoDriverMetrics {} @@ -15,8 +15,10 @@ cfg_not_rt_and_metrics! { } } -cfg_rt! { - cfg_metrics! { - pub(crate) use crate::runtime::IoDriverMetrics; +cfg_net! { + cfg_rt! { + cfg_metrics! { + pub(crate) use crate::runtime::IoDriverMetrics; + } } } diff --git a/tokio/src/io/driver/mod.rs b/tokio/src/io/driver/mod.rs index 24939ca0e5c..931f22364f1 100644 --- a/tokio/src/io/driver/mod.rs +++ b/tokio/src/io/driver/mod.rs @@ -290,19 +290,21 @@ cfg_not_rt! { } } -cfg_metrics! { - impl Handle { - // TODO: Remove this when handle contains `Arc` so that we can return - // &IoDriverMetrics instead of using a closure. - // - // Related issue: https://github.com/tokio-rs/tokio/issues/4509 - pub(crate) fn with_io_driver_metrics(&self, f: F) -> Option - where - F: Fn(&IoDriverMetrics) -> R, - { - self.inner().map(|inner| f(&inner.metrics)) - } - } +cfg_net! { + cfg_metrics! { + impl Handle { + // TODO: Remove this when handle contains `Arc` so that we can return + // &IoDriverMetrics instead of using a closure. + // + // Related issue: https://github.com/tokio-rs/tokio/issues/4509 + pub(crate) fn with_io_driver_metrics(&self, f: F) -> Option + where + F: Fn(&IoDriverMetrics) -> R, + { + self.inner().map(|inner| f(&inner.metrics)) + } + } + } } impl Handle { diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs index 608eef08cea..45ae5f9913a 100644 --- a/tokio/src/macros/cfg.rs +++ b/tokio/src/macros/cfg.rs @@ -195,9 +195,19 @@ macro_rules! cfg_not_metrics { } } -macro_rules! cfg_not_rt_and_metrics { +macro_rules! cfg_not_rt_and_metrics_and_net { ($($item:item)*) => { - $( #[cfg(not(all(feature = "rt", all(tokio_unstable, not(loom)))))] $item )* + $( #[cfg(not(all(feature = "net", feature = "rt", all(tokio_unstable, not(loom)))))]$item )* + } +} + +macro_rules! cfg_net_or_process { + ($($item:item)*) => { + $( + #[cfg(any(feature = "net", feature = "process"))] + #[cfg_attr(docsrs, doc(cfg(any(feature = "net", feature = "process"))))] + $item + )* } }