Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vic1707 committed Nov 8, 2024
1 parent d504f92 commit e5d428a
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions nutype_macros/src/common/gen/parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]

Check warning on line 70 in nutype_macros/src/common/gen/parse_error.rs

View workflow job for this annotation

GitHub Actions / Typos

"developping" should be "developing".
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
Expand Down

0 comments on commit e5d428a

Please sign in to comment.