Skip to content

Commit

Permalink
[derive] Suppress non_camel_case_types...
Browse files Browse the repository at this point in the history
...in derive-generated code.

Closes #2051

gherrit-pr-id: If3dbedcccd338435b5aa72dd724caaf9447b1baa
  • Loading branch information
joshlf committed Nov 13, 2024
1 parent e3b2ec1 commit 7674ad0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion zerocopy-derive/src/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn generate_tag_enum(repr: &EnumRepr, data: &DataEnum) -> TokenStream

quote! {
#repr
#[allow(dead_code)]
#[allow(dead_code, non_camel_case_types)]
enum ___ZerocopyTag {
#(#variants,)*
}
Expand Down
3 changes: 3 additions & 0 deletions zerocopy-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,9 @@ fn impl_block<D: DataExt>(
// TODO(#553): Add a test that generates a warning when
// `#[allow(deprecated)]` isn't present.
#[allow(deprecated)]
// While there are not currently any warnings that this suppresses (that
// we're aware of), it's good future-proofing hygiene.
#[automatically_derived]
unsafe impl < #(#params),* > #trait_path for #type_ident < #(#param_idents),* >
where
#(#bounds,)*
Expand Down
16 changes: 16 additions & 0 deletions zerocopy-derive/tests/enum_try_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,19 @@ fn test_trivial_is_bit_valid() {
util_assert_not_impl_any!(FooU8: imp::FromBytes);
util::test_trivial_is_bit_valid::<FooU8>();
}

#[deny(non_camel_case_types)]
mod issue_2051 {
use super::*;

// Test that the `non_camel_case_types` lint isn't triggered by generated code.
// Prevents regressions of #2051.
#[repr(u32)]
#[derive(imp::TryFromBytes)]
#[allow(non_camel_case_types)]
pub enum Code {
I32_ADD,
I32_SUB,
I32_MUL,
}
}

0 comments on commit 7674ad0

Please sign in to comment.