From cd7de8c8a22123fc1b418bce2dcb33496fcfced4 Mon Sep 17 00:00:00 2001 From: David Herberth Date: Fri, 26 Apr 2024 15:18:44 +0200 Subject: [PATCH] Annotate metric types with must_use (#475) --- metrics/src/handles.rs | 3 +++ metrics/tests/macros/02_trailing_comma.rs | 4 ++-- metrics/tests/macros/03_mod_aliasing.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/metrics/src/handles.rs b/metrics/src/handles.rs index 490e4df3..33dc62d2 100644 --- a/metrics/src/handles.rs +++ b/metrics/src/handles.rs @@ -40,18 +40,21 @@ pub trait HistogramFn { /// A counter. #[derive(Clone)] +#[must_use = "counters do nothing unless you use them"] pub struct Counter { inner: Option>, } /// A gauge. #[derive(Clone)] +#[must_use = "gauges do nothing unless you use them"] pub struct Gauge { inner: Option>, } /// A histogram. #[derive(Clone)] +#[must_use = "histograms do nothing unless you use them"] pub struct Histogram { inner: Option>, } diff --git a/metrics/tests/macros/02_trailing_comma.rs b/metrics/tests/macros/02_trailing_comma.rs index fa7863f5..badeed52 100644 --- a/metrics/tests/macros/02_trailing_comma.rs +++ b/metrics/tests/macros/02_trailing_comma.rs @@ -12,9 +12,9 @@ fn no_trailing_comma() { #[allow(dead_code)] fn with_trailing_comma() { - counter!("qwe",); + counter!("qwe",).increment(1); counter!( - "qwe", + "qwe", "foo" => "bar", ).increment(1); counter!("qwe", vec![],).increment(1); diff --git a/metrics/tests/macros/03_mod_aliasing.rs b/metrics/tests/macros/03_mod_aliasing.rs index dac8537f..acacf700 100644 --- a/metrics/tests/macros/03_mod_aliasing.rs +++ b/metrics/tests/macros/03_mod_aliasing.rs @@ -13,7 +13,7 @@ use framework::*; // This exposes mod `framework::metrics`. #[inline] pub fn register_metrics() { - ::metrics::counter!( + let _ = ::metrics::counter!( metrics::UPLOAD_METRIC_NAME, &[ (metrics::UPLOAD_METRIC_LABEL_PROCESS_TYPE, ""),