Skip to content

Commit 38b21bf

Browse files
committed
Prevent clippy::ignored_unit_patterns in macro expansions
This is a pedantic lint added in 1.73.0. Because it occurs inside a macro expansion, the lint is triggered from user code. The justification given by the lint definition is: > Matching with `()` explicitly instead of `_` outlines the fact that > the pattern contains no data. Also it would detect a type change that > `_` would ignore. Removing the lint requires a trivial change. It does introduce the possibility for compilation errors in the event the return type of the function currently returning `()` changes, but that seems like more of a benefit than a drawback. In these cases, it seems unlikely that the return type in question will change in the future. The user experience can be seen by linting the examples: ``` % cargo +nightly clippy --examples -- -A clippy::all -W clippy::ignored_unit_patterns -Z macro-backtrace Compiling prometheus v0.13.3 (/home/matt/src/rust-prometheus) ... warning: matching over `()` is more explicit --> /home/matt/src/rust-prometheus/src/macros.rs:217:58 | 214 | macro_rules! register_counter { | ----------------------------- | | | in this expansion of `register_counter!` (#1) | in this expansion of `register_counter!` (#2) | in this expansion of `register_counter!` (#3) ... 217 | $crate::register(Box::new(counter.clone())).map(|_| counter) | ^ ... 221 | register_counter!(@of_type Counter, $OPTS) | ------------------------------------------ in this macro invocation (#3) ... 225 | register_counter!(opts!($NAME, $HELP)) | -------------------------------------- in this macro invocation (#2) | ::: examples/example_push.rs:16:40 | 16 | static ref PUSH_COUNTER: Counter = register_counter!( | ________________________________________- 17 | | "example_push_total", 18 | | "Total number of prometheus client pushed." 19 | | ) | |_____- in this macro invocation (#1) | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns = note: requested on the command line with `-W clippy::ignored-unit-patterns` ... ``` Signed-off-by: Matt Weber <[email protected]>
1 parent 6e81890 commit 38b21bf

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/macros.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn test_histogram_opts_trailing_comma() {
214214
macro_rules! register_counter {
215215
(@of_type $TYPE:ident, $OPTS:expr) => {{
216216
let counter = $crate::$TYPE::with_opts($OPTS).unwrap();
217-
$crate::register(Box::new(counter.clone())).map(|_| counter)
217+
$crate::register(Box::new(counter.clone())).map(|()| counter)
218218
}};
219219

220220
($OPTS:expr $(,)?) => {{
@@ -260,7 +260,7 @@ fn test_register_counter_trailing_comma() {
260260
macro_rules! register_counter_with_registry {
261261
(@of_type $TYPE: ident, $OPTS:expr, $REGISTRY:expr) => {{
262262
let counter = $crate::$TYPE::with_opts($OPTS).unwrap();
263-
$REGISTRY.register(Box::new(counter.clone())).map(|_| counter)
263+
$REGISTRY.register(Box::new(counter.clone())).map(|()| counter)
264264
}};
265265

266266
($OPTS:expr, $REGISTRY:expr $(,)?) => {{
@@ -361,14 +361,14 @@ fn test_register_int_counter() {
361361
macro_rules! __register_counter_vec {
362362
($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr) => {{
363363
let counter_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap();
364-
$crate::register(Box::new(counter_vec.clone())).map(|_| counter_vec)
364+
$crate::register(Box::new(counter_vec.clone())).map(|()| counter_vec)
365365
}};
366366

367367
($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr, $REGISTRY:expr) => {{
368368
let counter_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap();
369369
$REGISTRY
370370
.register(Box::new(counter_vec.clone()))
371-
.map(|_| counter_vec)
371+
.map(|()| counter_vec)
372372
}};
373373
}
374374

@@ -543,12 +543,12 @@ fn test_register_int_counter_vec() {
543543
macro_rules! __register_gauge {
544544
($TYPE:ident, $OPTS:expr) => {{
545545
let gauge = $crate::$TYPE::with_opts($OPTS).unwrap();
546-
$crate::register(Box::new(gauge.clone())).map(|_| gauge)
546+
$crate::register(Box::new(gauge.clone())).map(|()| gauge)
547547
}};
548548

549549
($TYPE:ident, $OPTS:expr, $REGISTRY:expr) => {{
550550
let gauge = $crate::$TYPE::with_opts($OPTS).unwrap();
551-
$REGISTRY.register(Box::new(gauge.clone())).map(|_| gauge)
551+
$REGISTRY.register(Box::new(gauge.clone())).map(|()| gauge)
552552
}};
553553
}
554554

@@ -670,14 +670,14 @@ macro_rules! register_int_gauge_with_registry {
670670
macro_rules! __register_gauge_vec {
671671
($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr $(,)?) => {{
672672
let gauge_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap();
673-
$crate::register(Box::new(gauge_vec.clone())).map(|_| gauge_vec)
673+
$crate::register(Box::new(gauge_vec.clone())).map(|()| gauge_vec)
674674
}};
675675

676676
($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr, $REGISTRY:expr $(,)?) => {{
677677
let gauge_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap();
678678
$REGISTRY
679679
.register(Box::new(gauge_vec.clone()))
680-
.map(|_| gauge_vec)
680+
.map(|()| gauge_vec)
681681
}};
682682
}
683683

@@ -917,7 +917,7 @@ macro_rules! register_histogram {
917917

918918
($HOPTS:expr $(,)?) => {{
919919
let histogram = $crate::Histogram::with_opts($HOPTS).unwrap();
920-
$crate::register(Box::new(histogram.clone())).map(|_| histogram)
920+
$crate::register(Box::new(histogram.clone())).map(|()| histogram)
921921
}};
922922
}
923923

@@ -974,7 +974,7 @@ macro_rules! register_histogram_with_registry {
974974
let histogram = $crate::Histogram::with_opts($HOPTS).unwrap();
975975
$REGISTRY
976976
.register(Box::new(histogram.clone()))
977-
.map(|_| histogram)
977+
.map(|()| histogram)
978978
}};
979979
}
980980

@@ -1030,7 +1030,7 @@ fn test_register_histogram_with_registry_trailing_comma() {
10301030
macro_rules! register_histogram_vec {
10311031
($HOPTS:expr, $LABELS_NAMES:expr $(,)?) => {{
10321032
let histogram_vec = $crate::HistogramVec::new($HOPTS, $LABELS_NAMES).unwrap();
1033-
$crate::register(Box::new(histogram_vec.clone())).map(|_| histogram_vec)
1033+
$crate::register(Box::new(histogram_vec.clone())).map(|()| histogram_vec)
10341034
}};
10351035

10361036
($NAME:expr, $HELP:expr, $LABELS_NAMES:expr $(,)?) => {{
@@ -1094,7 +1094,7 @@ macro_rules! register_histogram_vec_with_registry {
10941094
let histogram_vec = $crate::HistogramVec::new($HOPTS, $LABELS_NAMES).unwrap();
10951095
$REGISTRY
10961096
.register(Box::new(histogram_vec.clone()))
1097-
.map(|_| histogram_vec)
1097+
.map(|()| histogram_vec)
10981098
}};
10991099

11001100
($NAME:expr, $HELP:expr, $LABELS_NAMES:expr, $REGISTRY:expr $(,)?) => {{

0 commit comments

Comments
 (0)