Skip to content

Commit b89e4b7

Browse files
authored
[derive] Suppress non_camel_case_types... (#2057)
...in derive-generated code. Closes #2051 gherrit-pr-id: If3dbedcccd338435b5aa72dd724caaf9447b1baa
1 parent ad47fa2 commit b89e4b7

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

zerocopy-derive/src/enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) fn generate_tag_enum(repr: &EnumRepr, data: &DataEnum) -> TokenStream
3535

3636
quote! {
3737
#repr
38-
#[allow(dead_code)]
38+
#[allow(dead_code, non_camel_case_types)]
3939
enum ___ZerocopyTag {
4040
#(#variants,)*
4141
}

zerocopy-derive/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,9 @@ fn impl_block<D: DataExt>(
13391339
// TODO(#553): Add a test that generates a warning when
13401340
// `#[allow(deprecated)]` isn't present.
13411341
#[allow(deprecated)]
1342+
// While there are not currently any warnings that this suppresses (that
1343+
// we're aware of), it's good future-proofing hygiene.
1344+
#[automatically_derived]
13421345
unsafe impl < #(#params),* > #trait_path for #type_ident < #(#param_idents),* >
13431346
where
13441347
#(#bounds,)*

zerocopy-derive/src/output_tests.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ fn test_known_layout() {
102102
struct Foo;
103103
} expands to {
104104
#[allow(deprecated)]
105+
#[automatically_derived]
105106
unsafe impl ::zerocopy::KnownLayout for Foo
106107
where
107108
Self: ::zerocopy::util::macro_util::core_reexport::marker::Sized,
@@ -134,6 +135,7 @@ fn test_immutable() {
134135
struct Foo;
135136
} expands to {
136137
#[allow(deprecated)]
138+
#[automatically_derived]
137139
unsafe impl ::zerocopy::Immutable for Foo {
138140
fn only_derive_is_allowed_to_implement_this_trait() {}
139141
}
@@ -148,6 +150,7 @@ fn test_try_from_bytes() {
148150
struct Foo;
149151
} expands to {
150152
#[allow(deprecated)]
153+
#[automatically_derived]
151154
unsafe impl ::zerocopy::TryFromBytes for Foo {
152155
fn only_derive_is_allowed_to_implement_this_trait() {}
153156

@@ -172,6 +175,7 @@ fn test_from_zeros() {
172175
struct Foo;
173176
} expands to {
174177
#[allow(deprecated)]
178+
#[automatically_derived]
175179
unsafe impl ::zerocopy::TryFromBytes for Foo {
176180
fn only_derive_is_allowed_to_implement_this_trait() {}
177181

@@ -187,6 +191,7 @@ fn test_from_zeros() {
187191
}
188192

189193
#[allow(deprecated)]
194+
#[automatically_derived]
190195
unsafe impl ::zerocopy::FromZeros for Foo {
191196
fn only_derive_is_allowed_to_implement_this_trait() {}
192197
}
@@ -201,6 +206,7 @@ fn test_from_bytes_struct() {
201206
struct Foo;
202207
} expands to {
203208
#[allow(deprecated)]
209+
#[automatically_derived]
204210
unsafe impl ::zerocopy::TryFromBytes for Foo {
205211
fn only_derive_is_allowed_to_implement_this_trait() {}
206212

@@ -225,11 +231,13 @@ fn test_from_bytes_struct() {
225231
}
226232

227233
#[allow(deprecated)]
234+
#[automatically_derived]
228235
unsafe impl ::zerocopy::FromZeros for Foo {
229236
fn only_derive_is_allowed_to_implement_this_trait() {}
230237
}
231238

232239
#[allow(deprecated)]
240+
#[automatically_derived]
233241
unsafe impl ::zerocopy::FromBytes for Foo {
234242
fn only_derive_is_allowed_to_implement_this_trait() {}
235243
}
@@ -246,6 +254,7 @@ fn test_from_bytes_union() {
246254
}
247255
} expands to {
248256
#[allow(deprecated)]
257+
#[automatically_derived]
249258
unsafe impl ::zerocopy::TryFromBytes for Foo
250259
where
251260
u8: ::zerocopy::TryFromBytes + ::zerocopy::Immutable,
@@ -273,6 +282,7 @@ fn test_from_bytes_union() {
273282
}
274283

275284
#[allow(deprecated)]
285+
#[automatically_derived]
276286
unsafe impl ::zerocopy::FromZeros for Foo
277287
where
278288
u8: ::zerocopy::FromZeros + ::zerocopy::Immutable,
@@ -281,6 +291,7 @@ fn test_from_bytes_union() {
281291
}
282292

283293
#[allow(deprecated)]
294+
#[automatically_derived]
284295
unsafe impl ::zerocopy::FromBytes for Foo
285296
where
286297
u8: ::zerocopy::FromBytes + ::zerocopy::Immutable,
@@ -299,6 +310,7 @@ fn test_into_bytes() {
299310
struct Foo;
300311
} expands to {
301312
#[allow(deprecated)]
313+
#[automatically_derived]
302314
unsafe impl ::zerocopy::IntoBytes for Foo {
303315
fn only_derive_is_allowed_to_implement_this_trait() {}
304316
}
@@ -314,6 +326,7 @@ fn test_into_bytes() {
314326
}
315327
} expands to {
316328
#[allow(deprecated)]
329+
#[automatically_derived]
317330
unsafe impl ::zerocopy::IntoBytes for Foo
318331
where
319332
u8: ::zerocopy::IntoBytes,
@@ -337,6 +350,7 @@ fn test_unaligned() {
337350
struct Foo;
338351
} expands to {
339352
#[allow(deprecated)]
353+
#[automatically_derived]
340354
unsafe impl ::zerocopy::Unaligned for Foo {
341355
fn only_derive_is_allowed_to_implement_this_trait() {}
342356
}
@@ -359,6 +373,7 @@ fn test_try_from_bytes_enum() {
359373
}
360374
} expands to {
361375
#[allow(deprecated)]
376+
#[automatically_derived]
362377
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
363378
for ComplexWithGenerics<'a, { N }, X, Y>
364379
where
@@ -382,7 +397,7 @@ fn test_try_from_bytes_enum() {
382397
{
383398
use ::zerocopy::util::macro_util::core_reexport;
384399
#[repr(u8)]
385-
#[allow(dead_code)]
400+
#[allow(dead_code, non_camel_case_types)]
386401
enum ___ZerocopyTag {
387402
UnitLike,
388403
StructLike,
@@ -416,6 +431,7 @@ fn test_try_from_bytes_enum() {
416431
where
417432
X: Deref<Target = &'a [(X, Y); N]>;
418433
#[allow(deprecated)]
434+
#[automatically_derived]
419435
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
420436
for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y>
421437
where
@@ -512,6 +528,7 @@ fn test_try_from_bytes_enum() {
512528
where
513529
X: Deref<Target = &'a [(X, Y); N]>;
514530
#[allow(deprecated)]
531+
#[automatically_derived]
515532
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
516533
for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y>
517534
where
@@ -653,6 +670,7 @@ fn test_try_from_bytes_enum() {
653670
}
654671
} expands to {
655672
#[allow(deprecated)]
673+
#[automatically_derived]
656674
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
657675
for ComplexWithGenerics<'a, { N }, X, Y>
658676
where
@@ -676,7 +694,7 @@ fn test_try_from_bytes_enum() {
676694
{
677695
use ::zerocopy::util::macro_util::core_reexport;
678696
#[repr(u32)]
679-
#[allow(dead_code)]
697+
#[allow(dead_code, non_camel_case_types)]
680698
enum ___ZerocopyTag {
681699
UnitLike,
682700
StructLike,
@@ -710,6 +728,7 @@ fn test_try_from_bytes_enum() {
710728
where
711729
X: Deref<Target = &'a [(X, Y); N]>;
712730
#[allow(deprecated)]
731+
#[automatically_derived]
713732
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
714733
for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y>
715734
where
@@ -806,6 +825,7 @@ fn test_try_from_bytes_enum() {
806825
where
807826
X: Deref<Target = &'a [(X, Y); N]>;
808827
#[allow(deprecated)]
828+
#[automatically_derived]
809829
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
810830
for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y>
811831
where
@@ -947,6 +967,7 @@ fn test_try_from_bytes_enum() {
947967
}
948968
} expands to {
949969
#[allow(deprecated)]
970+
#[automatically_derived]
950971
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
951972
for ComplexWithGenerics<'a, { N }, X, Y>
952973
where
@@ -970,7 +991,7 @@ fn test_try_from_bytes_enum() {
970991
{
971992
use ::zerocopy::util::macro_util::core_reexport;
972993
#[repr(C)]
973-
#[allow(dead_code)]
994+
#[allow(dead_code, non_camel_case_types)]
974995
enum ___ZerocopyTag {
975996
UnitLike,
976997
StructLike,
@@ -1004,6 +1025,7 @@ fn test_try_from_bytes_enum() {
10041025
where
10051026
X: Deref<Target = &'a [(X, Y); N]>;
10061027
#[allow(deprecated)]
1028+
#[automatically_derived]
10071029
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
10081030
for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y>
10091031
where
@@ -1100,6 +1122,7 @@ fn test_try_from_bytes_enum() {
11001122
where
11011123
X: Deref<Target = &'a [(X, Y); N]>;
11021124
#[allow(deprecated)]
1125+
#[automatically_derived]
11031126
unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes
11041127
for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y>
11051128
where
@@ -1496,6 +1519,7 @@ fn test_from_bytes_enum() {
14961519
}
14971520
} expands to {
14981521
#[allow(deprecated)]
1522+
#[automatically_derived]
14991523
unsafe impl ::zerocopy::TryFromBytes for Foo {
15001524
fn only_derive_is_allowed_to_implement_this_trait() {}
15011525

@@ -1520,11 +1544,13 @@ fn test_from_bytes_enum() {
15201544
}
15211545

15221546
#[allow(deprecated)]
1547+
#[automatically_derived]
15231548
unsafe impl ::zerocopy::FromZeros for Foo {
15241549
fn only_derive_is_allowed_to_implement_this_trait() {}
15251550
}
15261551

15271552
#[allow(deprecated)]
1553+
#[automatically_derived]
15281554
unsafe impl ::zerocopy::FromBytes for Foo {
15291555
fn only_derive_is_allowed_to_implement_this_trait() {}
15301556
}
@@ -1801,6 +1827,7 @@ fn test_try_from_bytes_trivial_is_bit_valid_enum() {
18011827
}
18021828
} expands to {
18031829
#[allow(deprecated)]
1830+
#[automatically_derived]
18041831
unsafe impl ::zerocopy::TryFromBytes for Foo {
18051832
fn only_derive_is_allowed_to_implement_this_trait() {}
18061833

zerocopy-derive/tests/enum_try_from_bytes.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,19 @@ fn test_trivial_is_bit_valid() {
626626
util_assert_not_impl_any!(FooU8: imp::FromBytes);
627627
util::test_trivial_is_bit_valid::<FooU8>();
628628
}
629+
630+
#[deny(non_camel_case_types)]
631+
mod issue_2051 {
632+
use super::*;
633+
634+
// Test that the `non_camel_case_types` lint isn't triggered by generated code.
635+
// Prevents regressions of #2051.
636+
#[repr(u32)]
637+
#[derive(imp::TryFromBytes)]
638+
#[allow(non_camel_case_types)]
639+
pub enum Code {
640+
I32_ADD,
641+
I32_SUB,
642+
I32_MUL,
643+
}
644+
}

0 commit comments

Comments
 (0)