diff --git a/nutype_macros/src/common/gen/parse_error.rs b/nutype_macros/src/common/gen/parse_error.rs index 2780b38..c45f361 100644 --- a/nutype_macros/src/common/gen/parse_error.rs +++ b/nutype_macros/src/common/gen/parse_error.rs @@ -67,36 +67,32 @@ pub fn gen_def_parse_error( } }; - cfg_if! { - if #[cfg(ERROR_IN_CORE)] { - let generics_with_fromstr_and_debug_bounds = add_bound_to_all_type_params( - &generics_with_fromstr_bound, - syn::parse_quote!(::core::fmt::Debug), - ); - let impl_error = quote! { - impl #generics_with_fromstr_and_debug_bounds ::core::error::Error for #parse_error_type_name #generics_without_bounds { - fn source(&self) -> Option<&(dyn ::core::error::Error + 'static)> { - None - } - } - }; - } else if #[cfg(feature = "std")] { - let generics_with_fromstr_and_debug_bounds = add_bound_to_all_type_params( - &generics_with_fromstr_bound, - syn::parse_quote!(::core::fmt::Debug), - ); - let impl_error = quote! { - impl #generics_with_fromstr_and_debug_bounds ::std::error::Error for #parse_error_type_name #generics_without_bounds { - fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> { - None - } + #[allow(unused_assignments, reason = "Sometimes triggered when developping nutype due to feature flags.")] + let mut impl_error = quote! {}; + + #[cfg(any(ERROR_IN_CORE, feature = "std"))] + { + let generics_with_fromstr_and_debug_bounds = add_bound_to_all_type_params( + &generics_with_fromstr_bound, + syn::parse_quote!(::core::fmt::Debug), + ); + + cfg_if! { + if #[cfg(ERROR_IN_CORE)] { + let error = quote! { ::core::error::Error }; + } else { + let error = quote! { ::std::error::Error }; + } + }; + + impl_error = quote! { + impl #generics_with_fromstr_and_debug_bounds #error for #parse_error_type_name #generics_without_bounds { + fn source(&self) -> Option<&(dyn ::core::error::Error + 'static)> { + None } - }; - } else { - // NOTE: `::core::error::Error` is stable only for rust >= 1.81.0. - let impl_error = quote! {}; - } - }; + } + }; + } quote! { #definition