Skip to content

Commit cd7de8c

Browse files
authored
Annotate metric types with must_use (#475)
1 parent f322087 commit cd7de8c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

metrics/src/handles.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@ pub trait HistogramFn {
4040

4141
/// A counter.
4242
#[derive(Clone)]
43+
#[must_use = "counters do nothing unless you use them"]
4344
pub struct Counter {
4445
inner: Option<Arc<dyn CounterFn + Send + Sync>>,
4546
}
4647

4748
/// A gauge.
4849
#[derive(Clone)]
50+
#[must_use = "gauges do nothing unless you use them"]
4951
pub struct Gauge {
5052
inner: Option<Arc<dyn GaugeFn + Send + Sync>>,
5153
}
5254

5355
/// A histogram.
5456
#[derive(Clone)]
57+
#[must_use = "histograms do nothing unless you use them"]
5558
pub struct Histogram {
5659
inner: Option<Arc<dyn HistogramFn + Send + Sync>>,
5760
}

metrics/tests/macros/02_trailing_comma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ fn no_trailing_comma() {
1212

1313
#[allow(dead_code)]
1414
fn with_trailing_comma() {
15-
counter!("qwe",);
15+
counter!("qwe",).increment(1);
1616
counter!(
17-
"qwe",
17+
"qwe",
1818
"foo" => "bar",
1919
).increment(1);
2020
counter!("qwe", vec![],).increment(1);

metrics/tests/macros/03_mod_aliasing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use framework::*; // This exposes mod `framework::metrics`.
1313

1414
#[inline]
1515
pub fn register_metrics() {
16-
::metrics::counter!(
16+
let _ = ::metrics::counter!(
1717
metrics::UPLOAD_METRIC_NAME,
1818
&[
1919
(metrics::UPLOAD_METRIC_LABEL_PROCESS_TYPE, ""),

0 commit comments

Comments
 (0)