Skip to content

Commit f20c03b

Browse files
committed
Use BTreeSet for stable ordering of type params.
Signed-off-by: Toralf Wittner <tw@dtex.org>
1 parent 429fe4a commit f20c03b

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

minicbor-derive/src/blacklist.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use std::collections::HashSet;
1+
use std::collections::BTreeSet;
22
use std::ops::Deref;
33

44
use crate::{collect_type_params, is_phantom_data, Mode};
55
use crate::{attrs::CustomCodec, fields::Fields};
66

7-
pub(crate) struct Blacklist(HashSet<syn::Ident>);
7+
pub(crate) struct Blacklist(BTreeSet<syn::Ident>);
88

99
impl Blacklist {
1010
pub(crate) fn empty() -> Self {
11-
Self(HashSet::new())
11+
Self(BTreeSet::new())
1212
}
1313

1414
/// Generate a blacklist of type parameters that should not have bounds attached.
@@ -105,14 +105,14 @@ impl Blacklist {
105105
}
106106
}
107107

108-
impl From<Blacklist> for HashSet<syn::Ident> {
108+
impl From<Blacklist> for BTreeSet<syn::Ident> {
109109
fn from(b: Blacklist) -> Self {
110110
b.0
111111
}
112112
}
113113

114114
impl Deref for Blacklist {
115-
type Target = HashSet<syn::Ident>;
115+
type Target = BTreeSet<syn::Ident>;
116116

117117
fn deref(&self) -> &Self::Target {
118118
&self.0

minicbor-derive/src/cbor_len.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use std::collections::BTreeSet;
22

33
use quote::{quote, ToTokens};
44
use syn::spanned::Spanned;
@@ -97,7 +97,7 @@ fn on_enum(inp: &mut syn::DeriveInput) -> syn::Result<proc_macro2::TokenStream>
9797
for ((var, idx), attrs) in data.variants.iter().zip(variants.indices.iter()).zip(&variants.attrs) {
9898
let fields = Fields::try_from(var.ident.span(), var.fields.iter(), &[attrs, &enum_attrs])?;
9999
blacklist_len.merge(&fields, &inp.generics, Blacklist::full(Mode::Length, &fields, &inp.generics));
100-
blacklist_enc.add(HashSet::from(blacklist_is_nil_params(&inp.generics, &fields)));
100+
blacklist_enc.add(BTreeSet::from(blacklist_is_nil_params(&inp.generics, &fields)));
101101
let con = &var.ident;
102102
let encoding = attrs.encoding().unwrap_or(enum_encoding);
103103
let tag = on_tag(attrs);

minicbor-derive/src/decode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use std::collections::BTreeSet;
22

33
use quote::quote;
44
use syn::spanned::Spanned;
@@ -53,7 +53,7 @@ fn on_struct(inp: &mut syn::DeriveInput) -> syn::Result<proc_macro2::TokenStream
5353
add_bound_to_type_params(Mode::Decode, bound, params, &blacklist, fields.fields().attributes());
5454

5555
// Collect type parameters which require a `Default` bound.
56-
let default_types: HashSet<syn::Ident> =
56+
let default_types: BTreeSet<syn::Ident> =
5757
collect_type_params(&inp.generics, fields.fields().chain(fields.skipped()).filter(|f| {
5858
f.attrs.default() || f.attrs.skip() || f.attrs.skip_if_codec()
5959
}));
@@ -151,7 +151,7 @@ fn on_enum(inp: &mut syn::DeriveInput) -> syn::Result<proc_macro2::TokenStream>
151151
let mut decode_blacklist = Blacklist::empty();
152152
let mut field_attrs = Vec::new();
153153
let mut default_blacklist = Blacklist::empty();
154-
let mut defaults = HashSet::new();
154+
let mut defaults = BTreeSet::new();
155155
let mut default_attrs = Vec::new();
156156
let mut lifetime = gen_lifetime();
157157
let mut rows = Vec::new();

minicbor-derive/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ pub(crate) mod lifetimes;
540540
pub(crate) mod variants;
541541
pub(crate) mod blacklist;
542542

543-
use std::collections::HashSet;
543+
use std::collections::BTreeSet;
544544

545545
/// Derive the `minicbor::Decode` trait for a struct or enum.
546546
///
@@ -681,15 +681,15 @@ fn is_decode_bound(bound: &syn::TypeParamBound) -> bool {
681681
}
682682

683683
/// Traverse all field types and collect all type parameters along the way.
684-
fn collect_type_params<'a, I>(all: &syn::Generics, fields: I) -> HashSet<syn::Ident>
684+
fn collect_type_params<'a, I>(all: &syn::Generics, fields: I) -> BTreeSet<syn::Ident>
685685
where
686686
I: Iterator<Item = &'a fields::Field>
687687
{
688688
use syn::visit::Visit;
689689

690690
struct Collector {
691-
all: HashSet<syn::Ident>,
692-
found: HashSet<syn::Ident>
691+
all: BTreeSet<syn::Ident>,
692+
found: BTreeSet<syn::Ident>
693693
}
694694

695695
impl<'a> Visit<'a> for Collector {
@@ -706,7 +706,7 @@ where
706706

707707
let mut c = Collector {
708708
all: all.type_params().map(|tp| tp.ident.clone()).collect(),
709-
found: HashSet::new()
709+
found: BTreeSet::new()
710710
};
711711

712712
for f in fields {
@@ -720,7 +720,7 @@ fn add_bound_to_type_params<'a, I, A>
720720
( mode: Mode
721721
, bound: syn::TypeParamBound
722722
, params: I
723-
, blacklist: &HashSet<syn::Ident>
723+
, blacklist: &BTreeSet<syn::Ident>
724724
, attrs: A
725725
)
726726
where

0 commit comments

Comments
 (0)