Skip to content

Commit f632ac6

Browse files
Cheban1996tyranron
andauthored
Proxy-pass #[allow]/#[expect] attributes in Constructor derive (#477, #397)
Resolves #397 ## Synopsis Clippy emits a `too_many_arguments` warning for the new method generated by the `Constructor` derive. Clippy attributes currently have no effect in this context. ## Solution Proxy-pass `#[allow(clippy::too_many_arguments)]` to the generated `impl` to suppress the warning. Co-authored-by: Kai Ren <tyranron@gmail.com>
1 parent 47d8c10 commit f632ac6

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
([#469](https://github.com/JelteF/derive_more/pull/469))
2222
- Add `PartialEq` derive similar to `std`'s one, but considering generics correctly.
2323
([#473](https://github.com/JelteF/derive_more/pull/473))
24+
- Proxy-pass `#[allow]`/`#[expect]` attributes of the type in `Constructor` derive.
25+
([#477](https://github.com/JelteF/derive_more/pull/477))
2426

2527
### Changed
2628

impl/src/constructor.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ pub fn expand(input: &DeriveInput, _: &str) -> TokenStream {
2323
},
2424
_ => panic!("Only structs can derive a constructor"),
2525
};
26+
27+
let inherited_lint_attrs = input.attrs.iter().filter(|attr| {
28+
attr.path()
29+
.get_ident()
30+
.is_some_and(|name| name == "allow" || name == "expect")
31+
});
32+
2633
let original_types = &get_field_types(&fields);
2734
quote! {
28-
#[allow(deprecated)] // omit warnings on deprecated fields/variants
35+
#[allow(deprecated)] // omit warnings on deprecated fields/variants
2936
#[allow(missing_docs)]
3037
#[allow(unreachable_code)] // omit warnings for `!` and other unreachable types
38+
#(#inherited_lint_attrs)* // proxy-pass any `#[allow]`/`#[expect]` attributes
3139
#[automatically_derived]
3240
impl #impl_generics #input_type #ty_generics #where_clause {
3341
#[inline]

tests/constructor.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,38 @@ mod deprecated {
6868
field: i32,
6969
}
7070
}
71+
72+
mod proxy_lint_attr {
73+
#![deny(non_snake_case, clippy::too_many_arguments)]
74+
75+
use super::*;
76+
77+
#[allow(clippy::too_many_arguments)]
78+
#[derive(Constructor)]
79+
struct ManyArguments(
80+
u8,
81+
u8,
82+
u8,
83+
u8,
84+
u8,
85+
u8,
86+
u8,
87+
u8,
88+
u8,
89+
u8,
90+
u8,
91+
u8,
92+
u8,
93+
u8,
94+
u8,
95+
u8,
96+
u8,
97+
u8,
98+
);
99+
100+
#[expect(non_snake_case)]
101+
#[derive(Constructor)]
102+
struct User {
103+
Num: i32,
104+
}
105+
}

0 commit comments

Comments
 (0)