Remove type defaults from generics in derive macro
When the Variant derive macros are used on types with defaults for type
parameters, the defaults are contained in the generated impl blocks, triggering
the `invalid-type-param-default` deny-by-default lint.
This should fix the issue.
@@ -341,9 +341,13 @@ pub(crate) fn derive_to_variant(input: TokenStream) -> TokenStream {
let DeriveData {
ident,
repr,
- generics,
+ mut generics,
} = parse_derive_input(input, &bound);
+ for param in generics.type_params_mut() {
+ param.default = None;
+ }
+
let return_expr = match repr {
Repr::Struct(var_repr) => {
let destructure_pattern = var_repr.destructure_pattern();
@@ -403,9 +407,13 @@ pub(crate) fn derive_from_variant(input: TokenStream) -> TokenStream {
let DeriveData {
ident,
repr,
- generics,
+ mut generics,
} = parse_derive_input(input, &bound);
+ for param in generics.type_params_mut() {
+ param.default = None;
+ }
+
let input_ident = Ident::new("__variant", Span::call_site());
let return_expr = match repr {
