Skip to content

Commit

Permalink
feat(macro): add more lint escapes to generated code (#66)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Ede <robjtede@icloud.com>
  • Loading branch information
tenuous-guidance and robjtede committed Dec 4, 2023
1 parent 8db91c3 commit dbdae8f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 24 additions & 3 deletions confik-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,6 @@ impl RootImplementer {
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();

quote! {
#[allow(clippy::needless_question_mark)]
#[automatically_derived]
impl #impl_generics ::confik::ConfigurationBuilder for #builder_name #type_generics #where_clause {
type Target = #target_name #type_generics;

Expand Down Expand Up @@ -904,13 +902,36 @@ fn derive_macro_builder_inner(target_struct: DeriveInput) -> syn::Result<proc_ma
let builder_impl = implementer.impl_builder();
let target_impl = implementer.impl_target();

let overall_lint_overrides = quote! {
#[doc(hidden)] // crate docs should cover builders' uses.
};

let impl_lint_overrides = quote! {
#[allow(clippy::needless_question_mark)] // Some `?` are used to simplify code generation even when they're not needed
#[automatically_derived] // Turns off some passes that make sense for automatically derived impls.
};

// These lints mostly consist of lints that are [allowed by default] but may be enabled by users.
//
// [allow by default]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html
let struct_lint_overrides = quote! {
#[allow(
missing_copy_implementations, // Some builders may be able to be `Copy` but do not benefit from it.
missing_debug_implementations, // Builders do not need `Debug` by default, can be opted in where needed.
variant_size_differences, // We add an empty enum varaint (`*Undefined`) which may be much smaller than other variants.
)]
};

let full_derive = quote! {
#[doc(hidden)]
#overall_lint_overrides
const _: () = {
#impl_lint_overrides
#target_impl

#struct_lint_overrides
#builder_struct

#impl_lint_overrides
#builder_impl
};
};
Expand Down
2 changes: 2 additions & 0 deletions confik/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Override the following lints in macro generated code: `missing_copy_implementations`, `missing_debug_implementations`, `variant_size_differences`

## 0.11.3

- Implement `Configuration` for [`camino::Utf8PathBuf`](https://docs.rs/camino/1/camino/struct.Utf8PathBuf.html).
Expand Down

0 comments on commit dbdae8f

Please sign in to comment.