Skip to content

Commit 4ef9d00

Browse files
authored
fix: fully qualify #cratename::BorshSchema in derive-generated code to void function name collisions leading to compilation errors (#244)
1 parent 49df318 commit 4ef9d00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+378
-144
lines changed

borsh-derive/src/internals/attributes/field/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Attributes {
178178
}
179179
pub(crate) fn collect_bounds(&self, ty: BoundType) -> Vec<WherePredicate> {
180180
let predicates = self.get_bounds(ty);
181-
predicates.unwrap_or(vec![])
181+
predicates.unwrap_or_default()
182182
}
183183
}
184184

borsh-derive/src/internals/schema/enums/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn process(input: &ItemEnum, cratename: Path) -> syn::Result<TokenStream2> {
7272
tag_width: 1,
7373
variants: #cratename::__private::maybestd::vec![#(#variants_defs),*],
7474
};
75-
#cratename::schema::add_definition(Self::declaration(), definition, definitions);
75+
#cratename::schema::add_definition(<Self as #cratename::BorshSchema>::declaration(), definition, definitions);
7676
}
7777
};
7878

@@ -147,7 +147,7 @@ fn process_variant(
147147
process_discriminant(&variant.ident, discriminant_info)?;
148148

149149
let variant_entry = quote! {
150-
(#discriminant_variable as i64, #variant_name.to_string(), <#full_variant_ident #inner_struct_ty_generics>::declaration())
150+
(#discriminant_variable as i64, #variant_name.to_string(), <#full_variant_ident #inner_struct_ty_generics as #cratename::BorshSchema>::declaration())
151151
};
152152
Ok(VariantOutput {
153153
inner_struct,

borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_false.snap

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@ impl borsh::BorshSchema for X {
5151
let definition = borsh::schema::Definition::Enum {
5252
tag_width: 1,
5353
variants: borsh::__private::maybestd::vec![
54-
(discriminant_0 as i64, "A".to_string(), < XA > ::declaration()),
55-
(discriminant_1 as i64, "B".to_string(), < XB > ::declaration()),
56-
(discriminant_2 as i64, "C".to_string(), < XC > ::declaration()),
57-
(discriminant_3 as i64, "D".to_string(), < XD > ::declaration()),
58-
(discriminant_4 as i64, "E".to_string(), < XE > ::declaration()),
59-
(discriminant_5 as i64, "F".to_string(), < XF > ::declaration())
54+
(discriminant_0 as i64, "A".to_string(), < XA as borsh::BorshSchema >
55+
::declaration()), (discriminant_1 as i64, "B".to_string(), < XB as
56+
borsh::BorshSchema > ::declaration()), (discriminant_2 as i64, "C"
57+
.to_string(), < XC as borsh::BorshSchema > ::declaration()),
58+
(discriminant_3 as i64, "D".to_string(), < XD as borsh::BorshSchema >
59+
::declaration()), (discriminant_4 as i64, "E".to_string(), < XE as
60+
borsh::BorshSchema > ::declaration()), (discriminant_5 as i64, "F"
61+
.to_string(), < XF as borsh::BorshSchema > ::declaration())
6062
],
6163
};
62-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
64+
borsh::schema::add_definition(
65+
<Self as borsh::BorshSchema>::declaration(),
66+
definition,
67+
definitions,
68+
);
6369
}
6470
}
6571

borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_true.snap

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@ impl borsh::BorshSchema for X {
5151
let definition = borsh::schema::Definition::Enum {
5252
tag_width: 1,
5353
variants: borsh::__private::maybestd::vec![
54-
(discriminant_0 as i64, "A".to_string(), < XA > ::declaration()),
55-
(discriminant_1 as i64, "B".to_string(), < XB > ::declaration()),
56-
(discriminant_2 as i64, "C".to_string(), < XC > ::declaration()),
57-
(discriminant_3 as i64, "D".to_string(), < XD > ::declaration()),
58-
(discriminant_4 as i64, "E".to_string(), < XE > ::declaration()),
59-
(discriminant_5 as i64, "F".to_string(), < XF > ::declaration())
54+
(discriminant_0 as i64, "A".to_string(), < XA as borsh::BorshSchema >
55+
::declaration()), (discriminant_1 as i64, "B".to_string(), < XB as
56+
borsh::BorshSchema > ::declaration()), (discriminant_2 as i64, "C"
57+
.to_string(), < XC as borsh::BorshSchema > ::declaration()),
58+
(discriminant_3 as i64, "D".to_string(), < XD as borsh::BorshSchema >
59+
::declaration()), (discriminant_4 as i64, "E".to_string(), < XE as
60+
borsh::BorshSchema > ::declaration()), (discriminant_5 as i64, "F"
61+
.to_string(), < XF as borsh::BorshSchema > ::declaration())
6062
],
6163
};
62-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
64+
borsh::schema::add_definition(
65+
<Self as borsh::BorshSchema>::declaration(),
66+
definition,
67+
definitions,
68+
);
6369
}
6470
}
6571

borsh-derive/src/internals/schema/enums/snapshots/complex_enum.snap

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,19 @@ impl borsh::BorshSchema for A {
4242
let definition = borsh::schema::Definition::Enum {
4343
tag_width: 1,
4444
variants: borsh::__private::maybestd::vec![
45-
(discriminant_0 as i64, "Bacon".to_string(), < ABacon > ::declaration()),
46-
(discriminant_1 as i64, "Eggs".to_string(), < AEggs > ::declaration()),
47-
(discriminant_2 as i64, "Salad".to_string(), < ASalad > ::declaration()),
48-
(discriminant_3 as i64, "Sausage".to_string(), < ASausage >
49-
::declaration())
45+
(discriminant_0 as i64, "Bacon".to_string(), < ABacon as
46+
borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs"
47+
.to_string(), < AEggs as borsh::BorshSchema > ::declaration()),
48+
(discriminant_2 as i64, "Salad".to_string(), < ASalad as
49+
borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage"
50+
.to_string(), < ASausage as borsh::BorshSchema > ::declaration())
5051
],
5152
};
52-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
53+
borsh::schema::add_definition(
54+
<Self as borsh::BorshSchema>::declaration(),
55+
definition,
56+
definitions,
57+
);
5358
}
5459
}
5560

borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics.snap

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ where
99
{
1010
fn declaration() -> borsh::schema::Declaration {
1111
let params = borsh::__private::maybestd::vec![
12-
< C > ::declaration(), < W > ::declaration()
12+
< C as borsh::BorshSchema > ::declaration(), < W as borsh::BorshSchema >
13+
::declaration()
1314
];
1415
format!(r#"{}<{}>"#, "A", params.join(", "))
1516
}
@@ -49,14 +50,19 @@ where
4950
let definition = borsh::schema::Definition::Enum {
5051
tag_width: 1,
5152
variants: borsh::__private::maybestd::vec![
52-
(discriminant_0 as i64, "Bacon".to_string(), < ABacon > ::declaration()),
53-
(discriminant_1 as i64, "Eggs".to_string(), < AEggs > ::declaration()),
54-
(discriminant_2 as i64, "Salad".to_string(), < ASalad < C > >
55-
::declaration()), (discriminant_3 as i64, "Sausage".to_string(), <
56-
ASausage < W > > ::declaration())
53+
(discriminant_0 as i64, "Bacon".to_string(), < ABacon as
54+
borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs"
55+
.to_string(), < AEggs as borsh::BorshSchema > ::declaration()),
56+
(discriminant_2 as i64, "Salad".to_string(), < ASalad < C > as
57+
borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage"
58+
.to_string(), < ASausage < W > as borsh::BorshSchema > ::declaration())
5759
],
5860
};
59-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
61+
borsh::schema::add_definition(
62+
<Self as borsh::BorshSchema>::declaration(),
63+
definition,
64+
definitions,
65+
);
6066
}
6167
}
6268

borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_named_field.snap

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ where
99
{
1010
fn declaration() -> borsh::schema::Declaration {
1111
let params = borsh::__private::maybestd::vec![
12-
< U > ::declaration(), < C > ::declaration()
12+
< U as borsh::BorshSchema > ::declaration(), < C as borsh::BorshSchema >
13+
::declaration()
1314
];
1415
format!(r#"{}<{}>"#, "A", params.join(", "))
1516
}
@@ -51,14 +52,20 @@ where
5152
let definition = borsh::schema::Definition::Enum {
5253
tag_width: 1,
5354
variants: borsh::__private::maybestd::vec![
54-
(discriminant_0 as i64, "Bacon".to_string(), < ABacon > ::declaration()),
55-
(discriminant_1 as i64, "Eggs".to_string(), < AEggs > ::declaration()),
56-
(discriminant_2 as i64, "Salad".to_string(), < ASalad < C > >
57-
::declaration()), (discriminant_3 as i64, "Sausage".to_string(), <
58-
ASausage < W, U > > ::declaration())
55+
(discriminant_0 as i64, "Bacon".to_string(), < ABacon as
56+
borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs"
57+
.to_string(), < AEggs as borsh::BorshSchema > ::declaration()),
58+
(discriminant_2 as i64, "Salad".to_string(), < ASalad < C > as
59+
borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage"
60+
.to_string(), < ASausage < W, U > as borsh::BorshSchema >
61+
::declaration())
5962
],
6063
};
61-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
64+
borsh::schema::add_definition(
65+
<Self as borsh::BorshSchema>::declaration(),
66+
definition,
67+
definitions,
68+
);
6269
}
6370
}
6471

borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_tuple_field.snap

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ where
88
W: borsh::BorshSchema,
99
{
1010
fn declaration() -> borsh::schema::Declaration {
11-
let params = borsh::__private::maybestd::vec![< W > ::declaration()];
11+
let params = borsh::__private::maybestd::vec![
12+
< W as borsh::BorshSchema > ::declaration()
13+
];
1214
format!(r#"{}<{}>"#, "A", params.join(", "))
1315
}
1416
fn add_definitions_recursively(
@@ -50,14 +52,19 @@ where
5052
let definition = borsh::schema::Definition::Enum {
5153
tag_width: 1,
5254
variants: borsh::__private::maybestd::vec![
53-
(discriminant_0 as i64, "Bacon".to_string(), < ABacon > ::declaration()),
54-
(discriminant_1 as i64, "Eggs".to_string(), < AEggs > ::declaration()),
55-
(discriminant_2 as i64, "Salad".to_string(), < ASalad < C > >
56-
::declaration()), (discriminant_3 as i64, "Sausage".to_string(), <
57-
ASausage < W > > ::declaration())
55+
(discriminant_0 as i64, "Bacon".to_string(), < ABacon as
56+
borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs"
57+
.to_string(), < AEggs as borsh::BorshSchema > ::declaration()),
58+
(discriminant_2 as i64, "Salad".to_string(), < ASalad < C > as
59+
borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage"
60+
.to_string(), < ASausage < W > as borsh::BorshSchema > ::declaration())
5861
],
5962
};
60-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
63+
borsh::schema::add_definition(
64+
<Self as borsh::BorshSchema>::declaration(),
65+
definition,
66+
definitions,
67+
);
6168
}
6269
}
6370

borsh-derive/src/internals/schema/enums/snapshots/filter_foreign_attrs.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ impl borsh::BorshSchema for A {
3434
let definition = borsh::schema::Definition::Enum {
3535
tag_width: 1,
3636
variants: borsh::__private::maybestd::vec![
37-
(discriminant_0 as i64, "B".to_string(), < AB > ::declaration()),
38-
(discriminant_1 as i64, "Negative".to_string(), < ANegative >
39-
::declaration())
37+
(discriminant_0 as i64, "B".to_string(), < AB as borsh::BorshSchema >
38+
::declaration()), (discriminant_1 as i64, "Negative".to_string(), <
39+
ANegative as borsh::BorshSchema > ::declaration())
4040
],
4141
};
42-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
42+
borsh::schema::add_definition(
43+
<Self as borsh::BorshSchema>::declaration(),
44+
definition,
45+
definitions,
46+
);
4347
}
4448
}
4549

borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type.snap

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ where
1515
{
1616
fn declaration() -> borsh::schema::Declaration {
1717
let params = borsh::__private::maybestd::vec![
18-
< T > ::declaration(), < K > ::declaration(), < K::Associated >
19-
::declaration(), < V > ::declaration()
18+
< T as borsh::BorshSchema > ::declaration(), < K as borsh::BorshSchema >
19+
::declaration(), < K::Associated as borsh::BorshSchema > ::declaration(), < V
20+
as borsh::BorshSchema > ::declaration()
2021
];
2122
format!(r#"{}<{}>"#, "EnumParametrized", params.join(", "))
2223
}
@@ -60,12 +61,17 @@ where
6061
let definition = borsh::schema::Definition::Enum {
6162
tag_width: 1,
6263
variants: borsh::__private::maybestd::vec![
63-
(discriminant_0 as i64, "B".to_string(), < EnumParametrizedB < K, V > >
64-
::declaration()), (discriminant_1 as i64, "C".to_string(), <
65-
EnumParametrizedC < T > > ::declaration())
64+
(discriminant_0 as i64, "B".to_string(), < EnumParametrizedB < K, V > as
65+
borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "C"
66+
.to_string(), < EnumParametrizedC < T > as borsh::BorshSchema >
67+
::declaration())
6668
],
6769
};
68-
borsh::schema::add_definition(Self::declaration(), definition, definitions);
70+
borsh::schema::add_definition(
71+
<Self as borsh::BorshSchema>::declaration(),
72+
definition,
73+
definitions,
74+
);
6975
}
7076
}
7177

0 commit comments

Comments
 (0)