Skip to content

Commit 640e4aa

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 640e4aa

File tree

4 files changed

+127
-106
lines changed

4 files changed

+127
-106
lines changed

serde_with/src/de/duplicates.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 90 additions & 80 deletions
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,89 +13,98 @@ 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-
($m:ident) => {
17-
#[cfg(feature = "alloc")]
18-
$m!(BTreeMap<K: Ord, V>, (|_size| BTreeMap::new()));
19-
#[cfg(feature = "std")]
20-
$m!(
21-
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
22-
(|size| HashMap::with_capacity_and_hasher(size, Default::default()))
23-
);
24-
#[cfg(feature = "hashbrown_0_14")]
25-
$m!(
26-
HashbrownMap014<K: Eq + Hash, V, S: BuildHasher + Default>,
27-
(|size| HashbrownMap014::with_capacity_and_hasher(size, Default::default()))
28-
);
29-
#[cfg(feature = "indexmap_1")]
30-
$m!(
31-
IndexMap<K: Eq + Hash, V, S: BuildHasher + Default>,
32-
(|size| IndexMap::with_capacity_and_hasher(size, Default::default()))
33-
);
34-
#[cfg(feature = "indexmap_2")]
35-
$m!(
36-
IndexMap2<K: Eq + Hash, V, S: BuildHasher + Default>,
37-
(|size| IndexMap2::with_capacity_and_hasher(size, Default::default()))
38-
);
39-
};
40-
}
41-
pub(crate) use 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)]
4220

43-
macro_rules! foreach_set {
44-
($m:ident) => {
45-
#[cfg(feature = "alloc")]
46-
$m!(BTreeSet<T: Ord>, (|_| BTreeSet::new()), insert);
47-
#[cfg(feature = "std")]
48-
$m!(
49-
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
50-
(|size| HashSet::with_capacity_and_hasher(size, S::default())),
51-
insert
52-
);
53-
#[cfg(feature = "hashbrown_0_14")]
54-
$m!(
55-
HashbrownSet014<T: Eq + Hash, S: BuildHasher + Default>,
56-
(|size| HashbrownSet014::with_capacity_and_hasher(size, S::default())),
57-
insert
58-
);
59-
#[cfg(feature = "indexmap_1")]
60-
$m!(
61-
IndexSet<T: Eq + Hash, S: BuildHasher + Default>,
62-
(|size| IndexSet::with_capacity_and_hasher(size, S::default())),
63-
insert
64-
);
65-
#[cfg(feature = "indexmap_2")]
66-
$m!(
67-
IndexSet2<T: Eq + Hash, S: BuildHasher + Default>,
68-
(|size| IndexSet2::with_capacity_and_hasher(size, S::default())),
69-
insert
70-
);
71-
};
72-
}
73-
pub(crate) use foreach_set;
21+
macro_rules! foreach_map {
22+
($m:ident) => {
23+
#[cfg(feature = "alloc")]
24+
$m!(BTreeMap<K: Ord, V>, (|_size| BTreeMap::new()));
25+
#[cfg(feature = "std")]
26+
$m!(
27+
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
28+
(|size| HashMap::with_capacity_and_hasher(size, Default::default()))
29+
);
30+
#[cfg(feature = "hashbrown_0_14")]
31+
$m!(
32+
HashbrownMap014<K: Eq + Hash, V, S: BuildHasher + Default>,
33+
(|size| HashbrownMap014::with_capacity_and_hasher(size, Default::default()))
34+
);
35+
#[cfg(feature = "indexmap_1")]
36+
$m!(
37+
IndexMap<K: Eq + Hash, V, S: BuildHasher + Default>,
38+
(|size| IndexMap::with_capacity_and_hasher(size, Default::default()))
39+
);
40+
#[cfg(feature = "indexmap_2")]
41+
$m!(
42+
IndexMap2<K: Eq + Hash, V, S: BuildHasher + Default>,
43+
(|size| IndexMap2::with_capacity_and_hasher(size, Default::default()))
44+
);
45+
};
46+
}
7447

75-
macro_rules! foreach_seq {
76-
($m:ident) => {
77-
foreach_set!($m);
48+
macro_rules! foreach_set {
49+
($m:ident) => {
50+
#[cfg(feature = "alloc")]
51+
$m!(BTreeSet<T: Ord>, (|_| BTreeSet::new()), insert);
52+
#[cfg(feature = "std")]
53+
$m!(
54+
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
55+
(|size| HashSet::with_capacity_and_hasher(size, S::default())),
56+
insert
57+
);
58+
#[cfg(feature = "hashbrown_0_14")]
59+
$m!(
60+
HashbrownSet014<T: Eq + Hash, S: BuildHasher + Default>,
61+
(|size| HashbrownSet014::with_capacity_and_hasher(size, S::default())),
62+
insert
63+
);
64+
#[cfg(feature = "indexmap_1")]
65+
$m!(
66+
IndexSet<T: Eq + Hash, S: BuildHasher + Default>,
67+
(|size| IndexSet::with_capacity_and_hasher(size, S::default())),
68+
insert
69+
);
70+
#[cfg(feature = "indexmap_2")]
71+
$m!(
72+
IndexSet2<T: Eq + Hash, S: BuildHasher + Default>,
73+
(|size| IndexSet2::with_capacity_and_hasher(size, S::default())),
74+
insert
75+
);
76+
};
77+
}
7878

79-
#[cfg(feature = "alloc")]
80-
$m!(
81-
BinaryHeap<T: Ord>,
82-
(|size| BinaryHeap::with_capacity(size)),
83-
push
84-
);
85-
#[cfg(feature = "alloc")]
86-
$m!(BoxedSlice<T>, (|size| Vec::with_capacity(size)), push);
87-
#[cfg(feature = "alloc")]
88-
$m!(LinkedList<T>, (|_| LinkedList::new()), push_back);
89-
#[cfg(feature = "alloc")]
90-
$m!(Vec<T>, (|size| Vec::with_capacity(size)), push);
91-
#[cfg(feature = "alloc")]
92-
$m!(
93-
VecDeque<T>,
94-
(|size| VecDeque::with_capacity(size)),
95-
push_back
96-
);
97-
};
79+
macro_rules! foreach_seq {
80+
($m:ident) => {
81+
foreach_set!($m);
82+
83+
#[cfg(feature = "alloc")]
84+
$m!(
85+
BinaryHeap<T: Ord>,
86+
(|size| BinaryHeap::with_capacity(size)),
87+
push
88+
);
89+
#[cfg(feature = "alloc")]
90+
$m!(BoxedSlice<T>, (|size| Vec::with_capacity(size)), push);
91+
#[cfg(feature = "alloc")]
92+
$m!(LinkedList<T>, (|_| LinkedList::new()), push_back);
93+
#[cfg(feature = "alloc")]
94+
$m!(Vec<T>, (|size| Vec::with_capacity(size)), push);
95+
#[cfg(feature = "alloc")]
96+
$m!(
97+
VecDeque<T>,
98+
(|size| VecDeque::with_capacity(size)),
99+
push_back
100+
);
101+
};
102+
}
103+
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;
98108
}
99109

100110
///////////////////////////////////////////////////////////////////////////////

serde_with/src/ser/duplicates.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 35 additions & 24 deletions
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)