You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature request] Enabling support for transitive "#[from]' handling #435
I will explain myself with a very simple example :
Say I have this huge error type on my codebase :
#[derive(Error,Debug)]pubenumMyError{#[error("Network error: {0}")]Network(String),#[error("Conversion Error: {0}")]ConversionError(#[from]ConversionDbError),// Around 30 other variants
I still need to add the manual conversions in order to forward the error down my enum :
implFrom<uuid::Error>forDbError{fnfrom(e: uuid::Error) -> Self{Self::ConversionError(ConversionDbError::Uuid(e))}}// and the 2 others
This kindof takes away my goal from importing the thiserror crate, which is to reduce boilerplate redundant code to the maximum. Of course, the code above isn't my production code. My code is so huge that this kind of feature will make it way more human-friendly.
Am I doing smth wrong or this is a feature that can be implemented ?
I also encountered this issue, but tried to look at it from a feasibility / proc_macro standpoint.
In your example, your error is called MyError but later called DbError, I'll go with DbError.
proc_macros only have the context of the object right below them, so when the first derive(Error) looks at DbError, and then at its field ConversionDbError, it has no clue what it is an enum, with a field Uuid, that can be converted to ConversionDbError.
This could be solved by a macro giving more context to derive(Error), so for instance:
#[derive(Error,Debug)]pubenumMyError{#[error("Network error: {0}")]Network(String),#[error("Conversion Error: {0}")]#[from(uuid::Error)]ConversionError(#[from]ConversionDbError),// Around 30 other variants
Would also love to see support for a transitive From impl for a given variant.
Ideally as a variant of #[from] (eg. #[from_transitive]), since it only works if there are no overlapping From impls between the parent & nested error enums. Eg. if they both have variants with #[from] std::io::Error it will fail to compile with Conflicting implementations of trait `From<std::io::Error>` for type `Parent`..
I currently use the following when I don't have overlapping From impls:
Activity
TuTiuTe commentedon Oct 22, 2025
I also encountered this issue, but tried to look at it from a feasibility / proc_macro standpoint.
In your example, your error is called MyError but later called DbError, I'll go with DbError.
proc_macros only have the context of the object right below them, so when the first
derive(Error)looks atDbError, and then at its fieldConversionDbError, it has no clue what it is an enum, with a fieldUuid, that can be converted toConversionDbError.This could be solved by a macro giving more context to
derive(Error), so for instance:In which case the macro could expand to
Note that this is only theoretical and I did not try it out nor am I affiliated with this project
Grimeh commentedon Jul 24, 2026
Would also love to see support for a transitive
Fromimpl for a given variant.Ideally as a variant of
#[from](eg.#[from_transitive]), since it only works if there are no overlappingFromimpls between the parent & nested error enums. Eg. if they both have variants with#[from] std::io::Errorit will fail to compile withConflicting implementations of trait `From<std::io::Error>` for type `Parent`..I currently use the following when I don't have overlapping
Fromimpls: