Skip to content

Commit 8d0cf9f

Browse files
committed
Handle unused_import lint warnings around macro_rules re-exports
The bug rust#78894 in rustc is now a problem, since more warnings are issued. rust-lang/rust#78894 rust-lang/rust#117772
1 parent da57d86 commit 8d0cf9f

File tree

4 files changed

+52
-31
lines changed

4 files changed

+52
-31
lines changed

serde_with/src/de/duplicates.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::impls::{foreach_map, foreach_set};
1+
use super::impls::macros::{foreach_map, foreach_set};
22
use crate::{
33
duplicate_key_impls::{
44
DuplicateInsertsFirstWinsMap, DuplicateInsertsLastWinsSet, PreventDuplicateInsertsMap,

serde_with/src/de/impls.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub(crate) use self::macros::*;
12
use crate::{formats::*, prelude::*};
23
#[cfg(feature = "hashbrown_0_14")]
34
use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014};
@@ -12,7 +13,12 @@ use indexmap_2::{IndexMap as IndexMap2, IndexSet as IndexSet2};
1213
#[cfg(feature = "alloc")]
1314
type BoxedSlice<T> = Box<[T]>;
1415

15-
macro_rules! foreach_map {
16+
pub(crate) mod macros {
17+
// The unused_import lint has false-positives around macros
18+
// https://github.com/rust-lang/rust/issues/78894
19+
#![allow(unused_import)]
20+
21+
macro_rules! foreach_map {
1622
($m:ident) => {
1723
#[cfg(feature = "alloc")]
1824
$m!(BTreeMap<K: Ord, V>, (|_size| BTreeMap::new()));
@@ -38,9 +44,8 @@ macro_rules! foreach_map {
3844
);
3945
};
4046
}
41-
pub(crate) use foreach_map;
4247

43-
macro_rules! foreach_set {
48+
macro_rules! foreach_set {
4449
($m:ident) => {
4550
#[cfg(feature = "alloc")]
4651
$m!(BTreeSet<T: Ord>, (|_| BTreeSet::new()), insert);
@@ -70,9 +75,8 @@ macro_rules! foreach_set {
7075
);
7176
};
7277
}
73-
pub(crate) use foreach_set;
7478

75-
macro_rules! foreach_seq {
79+
macro_rules! foreach_seq {
7680
($m:ident) => {
7781
foreach_set!($m);
7882

@@ -97,6 +101,12 @@ macro_rules! foreach_seq {
97101
};
98102
}
99103

104+
// Make the macros available to the rest of the crate
105+
pub(crate) use foreach_map;
106+
pub(crate) use foreach_seq;
107+
pub(crate) use foreach_set;
108+
}
109+
100110
///////////////////////////////////////////////////////////////////////////////
101111
// region: Simple Wrapper types (e.g., Box, Option)
102112

serde_with/src/ser/duplicates.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::impls::{foreach_map, foreach_set};
1+
use super::impls::macros::{foreach_map, foreach_set};
22
use crate::prelude::*;
33
#[cfg(feature = "hashbrown_0_14")]
44
use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014};

serde_with/src/ser/impls.rs

+35-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub(crate) use self::macros::*;
12
use crate::{formats::Strictness, prelude::*};
23
#[cfg(feature = "hashbrown_0_14")]
34
use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014};
@@ -13,7 +14,12 @@ use indexmap_2::{IndexMap as IndexMap2, IndexSet as IndexSet2};
1314
type BoxedSlice<T> = Box<[T]>;
1415
type Slice<T> = [T];
1516

16-
macro_rules! foreach_map {
17+
pub(crate) mod macros {
18+
// The unused_import lint has false-positives around macros
19+
// https://github.com/rust-lang/rust/issues/78894
20+
#![allow(unused_import)]
21+
22+
macro_rules! foreach_map {
1723
($m:ident) => {
1824
#[cfg(feature = "alloc")]
1925
$m!(BTreeMap<K, V>);
@@ -27,9 +33,8 @@ macro_rules! foreach_map {
2733
$m!(IndexMap2<K, V, H: Sized>);
2834
};
2935
}
30-
pub(crate) use foreach_map;
3136

32-
macro_rules! foreach_set {
37+
macro_rules! foreach_set {
3338
($m:ident, $T:tt) => {
3439
#[cfg(feature = "alloc")]
3540
$m!(BTreeSet<$T>);
@@ -46,28 +51,34 @@ macro_rules! foreach_set {
4651
foreach_set!($m, T);
4752
};
4853
}
49-
pub(crate) use foreach_set;
50-
51-
macro_rules! foreach_seq {
52-
($m:ident, $T:tt) => {
53-
foreach_set!($m, $T);
5454

55-
$m!(Slice<$T>);
56-
57-
#[cfg(feature = "alloc")]
58-
$m!(BinaryHeap<$T>);
59-
#[cfg(feature = "alloc")]
60-
$m!(BoxedSlice<$T>);
61-
#[cfg(feature = "alloc")]
62-
$m!(LinkedList<$T>);
63-
#[cfg(feature = "alloc")]
64-
$m!(Vec<$T>);
65-
#[cfg(feature = "alloc")]
66-
$m!(VecDeque<$T>);
67-
};
68-
($m:ident) => {
69-
foreach_seq!($m, T);
70-
};
55+
macro_rules! foreach_seq {
56+
($m:ident, $T:tt) => {
57+
foreach_set!($m, $T);
58+
59+
$m!(Slice<$T>);
60+
61+
#[cfg(feature = "alloc")]
62+
$m!(BinaryHeap<$T>);
63+
#[cfg(feature = "alloc")]
64+
$m!(BoxedSlice<$T>);
65+
#[cfg(feature = "alloc")]
66+
$m!(LinkedList<$T>);
67+
#[cfg(feature = "alloc")]
68+
$m!(Vec<$T>);
69+
#[cfg(feature = "alloc")]
70+
$m!(VecDeque<$T>);
71+
};
72+
($m:
73+
ident) => {
74+
foreach_seq!($m, T);
75+
};
76+
}
77+
78+
// Make the macros available to the rest of the crate
79+
pub(crate) use foreach_map;
80+
pub(crate) use foreach_seq;
81+
pub(crate) use foreach_set;
7182
}
7283

7384
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)