Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macro): add more lint escapes to generated code #66

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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