Skip to content

Commit d40dee5

Browse files
committed
Prefix field names to avoid collisions
1 parent 4a1a60b commit d40dee5

File tree

10 files changed

+148
-145
lines changed

10 files changed

+148
-145
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Avoid collisions between field names and trait method parameters.
12+
1013
### Changed
1114
- `PartialOrd` implementations now use `Ord` if applicable.
1215

src/data/field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl<'a> Field<'a> {
110110
type_: &'a Type,
111111
) -> Result<Self> {
112112
let attr = FieldAttr::from_attrs(derive_wheres, skip_inner, attrs)?;
113-
let self_ident = format_ident!("__{}", member);
114-
let other_ident = format_ident!("__other_{}", member);
113+
let self_ident = format_ident!("__field_{}", member);
114+
let other_ident = format_ident!("__other_field_{}", member);
115115

116116
Ok(Self {
117117
attr,

src/test/basic.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fn struct_() -> Result<()> {
2424
impl<T> ::core::fmt::Debug for Test<T> {
2525
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
2626
match self {
27-
Test { field: ref __field } => {
27+
Test { field: ref __field_field } => {
2828
let mut __builder = ::core::fmt::Formatter::debug_struct(__f, "Test");
29-
::core::fmt::DebugStruct::field(&mut __builder, "field", __field);
29+
::core::fmt::DebugStruct::field(&mut __builder, "field", __field_field);
3030
::core::fmt::DebugStruct::finish(&mut __builder)
3131
}
3232
}
@@ -52,7 +52,7 @@ fn struct_() -> Result<()> {
5252
impl<T> ::core::hash::Hash for Test<T> {
5353
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
5454
match self {
55-
Test { field: ref __field } => { ::core::hash::Hash::hash(__field, __state); }
55+
Test { field: ref __field_field } => { ::core::hash::Hash::hash(__field_field, __state); }
5656
}
5757
}
5858
}
@@ -61,8 +61,8 @@ fn struct_() -> Result<()> {
6161
#[inline]
6262
fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
6363
match (self, __other) {
64-
(Test { field: ref __field }, Test { field: ref __other_field }) =>
65-
match ::core::cmp::Ord::cmp(__field, __other_field) {
64+
(Test { field: ref __field_field }, Test { field: ref __other_field_field }) =>
65+
match ::core::cmp::Ord::cmp(__field_field, __other_field_field) {
6666
::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal,
6767
__cmp => __cmp,
6868
},
@@ -74,8 +74,8 @@ fn struct_() -> Result<()> {
7474
#[inline]
7575
fn eq(&self, __other: &Self) -> bool {
7676
match (self, __other) {
77-
(Test { field: ref __field }, Test { field: ref __other_field }) =>
78-
true && ::core::cmp::PartialEq::eq(__field, __other_field),
77+
(Test { field: ref __field_field }, Test { field: ref __other_field_field }) =>
78+
true && ::core::cmp::PartialEq::eq(__field_field, __other_field_field),
7979
}
8080
}
8181
}
@@ -111,9 +111,9 @@ fn tuple() -> Result<()> {
111111
impl<T> ::core::fmt::Debug for Test<T> {
112112
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
113113
match self {
114-
Test(ref __0) => {
114+
Test(ref __field_0) => {
115115
let mut __builder = ::core::fmt::Formatter::debug_tuple(__f, "Test");
116-
::core::fmt::DebugTuple::field(&mut __builder, __0);
116+
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
117117
::core::fmt::DebugTuple::finish(&mut __builder)
118118
}
119119
}
@@ -139,7 +139,7 @@ fn tuple() -> Result<()> {
139139
impl<T> ::core::hash::Hash for Test<T> {
140140
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
141141
match self {
142-
Test(ref __0) => { ::core::hash::Hash::hash(__0, __state); }
142+
Test(ref __field_0) => { ::core::hash::Hash::hash(__field_0, __state); }
143143
}
144144
}
145145
}
@@ -148,8 +148,8 @@ fn tuple() -> Result<()> {
148148
#[inline]
149149
fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
150150
match (self, __other) {
151-
(Test(ref __0), Test(ref __other_0)) =>
152-
match ::core::cmp::Ord::cmp(__0, __other_0) {
151+
(Test(ref __field_0), Test(ref __other_field_0)) =>
152+
match ::core::cmp::Ord::cmp(__field_0, __other_field_0) {
153153
::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal,
154154
__cmp => __cmp,
155155
},
@@ -161,8 +161,8 @@ fn tuple() -> Result<()> {
161161
#[inline]
162162
fn eq(&self, __other: &Self) -> bool {
163163
match (self, __other) {
164-
(Test(ref __0), Test(ref __other_0)) =>
165-
true && ::core::cmp::PartialEq::eq(__0, __other_0),
164+
(Test(ref __field_0), Test(ref __other_field_0)) =>
165+
true && ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
166166
}
167167
}
168168
}
@@ -204,13 +204,13 @@ fn enum_() -> Result<()> {
204204
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
205205
let ord = quote! {
206206
match self {
207-
Test::A { field: ref __field } => ::core::cmp::Ordering::Less,
207+
Test::A { field: ref __field_field } => ::core::cmp::Ordering::Less,
208208
Test::B { } =>
209209
match __other {
210210
Test::A { .. } => ::core::cmp::Ordering::Greater,
211211
_ => ::core::cmp::Ordering::Less,
212212
},
213-
Test::C(ref __0) =>
213+
Test::C(ref __field_0) =>
214214
match __other {
215215
Test::A { .. } | Test::B { .. } => ::core::cmp::Ordering::Greater,
216216
_ => ::core::cmp::Ordering::Less,
@@ -250,18 +250,18 @@ fn enum_() -> Result<()> {
250250
impl<T> ::core::fmt::Debug for Test<T> {
251251
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
252252
match self {
253-
Test::A { field: ref __field } => {
253+
Test::A { field: ref __field_field } => {
254254
let mut __builder = ::core::fmt::Formatter::debug_struct(__f, "A");
255-
::core::fmt::DebugStruct::field(&mut __builder, "field", __field);
255+
::core::fmt::DebugStruct::field(&mut __builder, "field", __field_field);
256256
::core::fmt::DebugStruct::finish(&mut __builder)
257257
}
258258
Test::B { } => {
259259
let mut __builder = ::core::fmt::Formatter::debug_struct(__f, "B");
260260
::core::fmt::DebugStruct::finish(&mut __builder)
261261
}
262-
Test::C(ref __0) => {
262+
Test::C(ref __field_0) => {
263263
let mut __builder = ::core::fmt::Formatter::debug_tuple(__f, "C");
264-
::core::fmt::DebugTuple::field(&mut __builder, __0);
264+
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
265265
::core::fmt::DebugTuple::finish(&mut __builder)
266266
}
267267
Test::D() => {
@@ -293,16 +293,16 @@ fn enum_() -> Result<()> {
293293
impl<T> ::core::hash::Hash for Test<T> {
294294
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
295295
match self {
296-
Test::A { field: ref __field } => {
296+
Test::A { field: ref __field_field } => {
297297
::core::hash::Hash::hash(&::core::mem::discriminant(self), __state);
298-
::core::hash::Hash::hash(__field, __state);
298+
::core::hash::Hash::hash(__field_field, __state);
299299
}
300300
Test::B { } => {
301301
::core::hash::Hash::hash(&::core::mem::discriminant(self), __state);
302302
}
303-
Test::C(ref __0) => {
303+
Test::C(ref __field_0) => {
304304
::core::hash::Hash::hash(&::core::mem::discriminant(self), __state);
305-
::core::hash::Hash::hash(__0, __state);
305+
::core::hash::Hash::hash(__field_0, __state);
306306
}
307307
Test::D() => {
308308
::core::hash::Hash::hash(&::core::mem::discriminant(self), __state);
@@ -321,13 +321,13 @@ fn enum_() -> Result<()> {
321321

322322
if __self_disc == __other_disc {
323323
match (self, __other) {
324-
(Test::A { field: ref __field }, Test::A { field: ref __other_field }) =>
325-
match ::core::cmp::Ord::cmp(__field, __other_field) {
324+
(Test::A { field: ref __field_field }, Test::A { field: ref __other_field_field }) =>
325+
match ::core::cmp::Ord::cmp(__field_field, __other_field_field) {
326326
::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal,
327327
__cmp => __cmp,
328328
},
329-
(Test::C(ref __0), Test::C(ref __other_0)) =>
330-
match ::core::cmp::Ord::cmp(__0, __other_0) {
329+
(Test::C(ref __field_0), Test::C(ref __other_field_0)) =>
330+
match ::core::cmp::Ord::cmp(__field_0, __other_field_0) {
331331
::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal,
332332
__cmp => __cmp,
333333
},
@@ -344,10 +344,10 @@ fn enum_() -> Result<()> {
344344
fn eq(&self, __other: &Self) -> bool {
345345
if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) {
346346
match (self, __other) {
347-
(Test::A { field: ref __field }, Test::A { field: ref __other_field }) =>
348-
true && ::core::cmp::PartialEq::eq(__field, __other_field),
349-
(Test::C(ref __0), Test::C(ref __other_0)) =>
350-
true && ::core::cmp::PartialEq::eq(__0, __other_0),
347+
(Test::A { field: ref __field_field }, Test::A { field: ref __other_field_field }) =>
348+
true && ::core::cmp::PartialEq::eq(__field_field, __other_field_field),
349+
(Test::C(ref __field_0), Test::C(ref __other_field_0)) =>
350+
true && ::core::cmp::PartialEq::eq(__field_0, __other_field_0),
351351
_ => true,
352352
}
353353
} else {

src/test/bound.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn bound() -> Result<()> {
1717
#[inline]
1818
fn clone(&self) -> Self {
1919
match self {
20-
Test(ref __0, ref __1) => Test(::core::clone::Clone::clone(__0), ::core::clone::Clone::clone(__1)),
20+
Test(ref __field_0, ref __field_1) => Test(::core::clone::Clone::clone(__field_0), ::core::clone::Clone::clone(__field_1)),
2121
}
2222
}
2323
}
@@ -41,7 +41,7 @@ fn bound_multiple() -> Result<()> {
4141
#[inline]
4242
fn clone(&self) -> Self {
4343
match self {
44-
Test(ref __0, ref __1) => Test(::core::clone::Clone::clone(__0), ::core::clone::Clone::clone(__1)),
44+
Test(ref __field_0, ref __field_1) => Test(::core::clone::Clone::clone(__field_0), ::core::clone::Clone::clone(__field_1)),
4545
}
4646
}
4747
}
@@ -63,7 +63,7 @@ fn custom_bound() -> Result<()> {
6363
#[inline]
6464
fn clone(&self) -> Self {
6565
match self {
66-
Test(ref __0) => Test(::core::clone::Clone::clone(__0)),
66+
Test(ref __field_0) => Test(::core::clone::Clone::clone(__field_0)),
6767
}
6868
}
6969
}
@@ -87,7 +87,7 @@ fn where_() -> Result<()> {
8787
#[inline]
8888
fn clone(&self) -> Self {
8989
match self {
90-
Test(ref __0, ref __1) => Test(::core::clone::Clone::clone(__0), ::core::clone::Clone::clone(__1)),
90+
Test(ref __field_0, ref __field_1) => Test(::core::clone::Clone::clone(__field_0), ::core::clone::Clone::clone(__field_1)),
9191
}
9292
}
9393
}
@@ -109,7 +109,7 @@ fn associated_type() -> Result<()> {
109109
#[inline]
110110
fn clone(&self) -> Self {
111111
match self {
112-
Test(ref __0) => Test(::core::clone::Clone::clone(__0)),
112+
Test(ref __field_0) => Test(::core::clone::Clone::clone(__field_0)),
113113
}
114114
}
115115
}
@@ -131,7 +131,7 @@ fn associated_type_custom_bound() -> Result<()> {
131131
#[inline]
132132
fn clone(&self) -> Self {
133133
match self {
134-
Test(ref __0) => Test(::core::clone::Clone::clone(__0)),
134+
Test(ref __field_0) => Test(::core::clone::Clone::clone(__field_0)),
135135
}
136136
}
137137
}
@@ -165,10 +165,10 @@ fn check_trait_bounds() -> Result<()> {
165165
{
166166
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
167167
match self {
168-
Test(ref __0, ref __1) => {
168+
Test(ref __field_0, ref __field_1) => {
169169
let mut __builder = ::core::fmt::Formatter::debug_tuple(__f, "Test");
170-
::core::fmt::DebugTuple::field(&mut __builder, __0);
171-
::core::fmt::DebugTuple::field(&mut __builder, __1);
170+
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
171+
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
172172
::core::fmt::DebugTuple::finish(&mut __builder)
173173
}
174174
}
@@ -201,9 +201,9 @@ fn check_trait_bounds() -> Result<()> {
201201
{
202202
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
203203
match self {
204-
Test(ref __0, ref __1) => {
205-
::core::hash::Hash::hash(__0, __state);
206-
::core::hash::Hash::hash(__1, __state);
204+
Test(ref __field_0, ref __field_1) => {
205+
::core::hash::Hash::hash(__field_0, __state);
206+
::core::hash::Hash::hash(__field_1, __state);
207207
}
208208
}
209209
}
@@ -215,9 +215,9 @@ fn check_trait_bounds() -> Result<()> {
215215
#[inline]
216216
fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
217217
match (self, __other) {
218-
(Test(ref __0, ref __1), Test(ref __other_0, ref __other_1)) =>
219-
match ::core::cmp::Ord::cmp(__0, __other_0) {
220-
::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(__1, __other_1) {
218+
(Test(ref __field_0, ref __field_1), Test(ref __other_field_0, ref __other_field_1)) =>
219+
match ::core::cmp::Ord::cmp(__field_0, __other_field_0) {
220+
::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(__field_1, __other_field_1) {
221221
::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal,
222222
__cmp => __cmp,
223223
},
@@ -233,10 +233,10 @@ fn check_trait_bounds() -> Result<()> {
233233
#[inline]
234234
fn eq(&self, __other: &Self) -> bool {
235235
match (self, __other) {
236-
(Test(ref __0, ref __1), Test(ref __other_0, ref __other_1)) =>
236+
(Test(ref __field_0, ref __field_1), Test(ref __other_field_0, ref __other_field_1)) =>
237237
true
238-
&& ::core::cmp::PartialEq::eq(__0, __other_0)
239-
&& ::core::cmp::PartialEq::eq(__1, __other_1),
238+
&& ::core::cmp::PartialEq::eq(__field_0, __other_field_0)
239+
&& ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
240240
}
241241
}
242242
}
@@ -285,10 +285,10 @@ fn check_multiple_trait_bounds() -> Result<()> {
285285
{
286286
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
287287
match self {
288-
Test(ref __0, ref __1) => {
288+
Test(ref __field_0, ref __field_1) => {
289289
let mut __builder = ::core::fmt::Formatter::debug_tuple(__f, "Test");
290-
::core::fmt::DebugTuple::field(&mut __builder, __0);
291-
::core::fmt::DebugTuple::field(&mut __builder, __1);
290+
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
291+
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
292292
::core::fmt::DebugTuple::finish(&mut __builder)
293293
}
294294
}
@@ -327,9 +327,9 @@ fn check_multiple_trait_bounds() -> Result<()> {
327327
{
328328
fn hash<__H: ::core::hash::Hasher>(&self, __state: &mut __H) {
329329
match self {
330-
Test(ref __0, ref __1) => {
331-
::core::hash::Hash::hash(__0, __state);
332-
::core::hash::Hash::hash(__1, __state);
330+
Test(ref __field_0, ref __field_1) => {
331+
::core::hash::Hash::hash(__field_0, __state);
332+
::core::hash::Hash::hash(__field_1, __state);
333333
}
334334
}
335335
}
@@ -343,9 +343,9 @@ fn check_multiple_trait_bounds() -> Result<()> {
343343
#[inline]
344344
fn cmp(&self, __other: &Self) -> ::core::cmp::Ordering {
345345
match (self, __other) {
346-
(Test(ref __0, ref __1), Test(ref __other_0, ref __other_1)) =>
347-
match ::core::cmp::Ord::cmp(__0, __other_0) {
348-
::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(__1, __other_1) {
346+
(Test(ref __field_0, ref __field_1), Test(ref __other_field_0, ref __other_field_1)) =>
347+
match ::core::cmp::Ord::cmp(__field_0, __other_field_0) {
348+
::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(__field_1, __other_field_1) {
349349
::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal,
350350
__cmp => __cmp,
351351
},
@@ -363,10 +363,10 @@ fn check_multiple_trait_bounds() -> Result<()> {
363363
#[inline]
364364
fn eq(&self, __other: &Self) -> bool {
365365
match (self, __other) {
366-
(Test(ref __0, ref __1), Test(ref __other_0, ref __other_1)) =>
366+
(Test(ref __field_0, ref __field_1), Test(ref __other_field_0, ref __other_field_1)) =>
367367
true
368-
&& ::core::cmp::PartialEq::eq(__0, __other_0)
369-
&& ::core::cmp::PartialEq::eq(__1, __other_1),
368+
&& ::core::cmp::PartialEq::eq(__field_0, __other_field_0)
369+
&& ::core::cmp::PartialEq::eq(__field_1, __other_field_1),
370370
}
371371
}
372372
}

src/test/clone.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn struct_() -> Result<()> {
1515
#[inline]
1616
fn clone(&self) -> Self {
1717
match self {
18-
Test { field: ref __field } => Test { field: ::core::clone::Clone::clone(__field) },
18+
Test { field: ref __field_field } => Test { field: ::core::clone::Clone::clone(__field_field) },
1919
}
2020
}
2121
}
@@ -35,7 +35,7 @@ fn tuple() -> Result<()> {
3535
#[inline]
3636
fn clone(&self) -> Self {
3737
match self {
38-
Test(ref __0) => Test(::core::clone::Clone::clone(__0)),
38+
Test(ref __field_0) => Test(::core::clone::Clone::clone(__field_0)),
3939
}
4040
}
4141
}
@@ -61,9 +61,9 @@ fn enum_() -> Result<()> {
6161
#[inline]
6262
fn clone(&self) -> Self {
6363
match self {
64-
Test::A { field: ref __field } => Test::A { field: ::core::clone::Clone::clone(__field) },
64+
Test::A { field: ref __field_field } => Test::A { field: ::core::clone::Clone::clone(__field_field) },
6565
Test::B { } => Test::B { },
66-
Test::C(ref __0) => Test::C(::core::clone::Clone::clone(__0)),
66+
Test::C(ref __field_0) => Test::C(::core::clone::Clone::clone(__field_0)),
6767
Test::D() => Test::D(),
6868
Test::E => Test::E,
6969
}

0 commit comments

Comments
 (0)