cargo / thiserror
thiserror
What changed in thiserror 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
4 breaking4 new APIs and options1 behavior and defaults1 tooling1 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initthiserror 211 changes
Breaking changes 4
Fields shadowed by an explicit named format argument no longer contribute inferred trait bounds.
Tuple structs and variants cannot combine numerical field access with extra positional format arguments because the references are ambiguous.
Raw identifiers for keyword-named fields are no longer accepted in format strings; use the unraw name instead.
Code invoking thiserror's derive must have a direct dependency on the thiserror crate, regardless of the error data structure.
New APIs and options 4
The
#[error(fmt = path::to::myfmt)]attribute lets enum variants define formatting logic out of line.Using
r#sourceas a field name opts out of treating the field as an error'sError::source().The default
stdCargo feature can be disabled to use thiserror without its standard library dependency.An individually transparent variant can override an enum-level format message.
Behavior and default changes 1
Infinite recursion in a generated
Displayimplementation now produces anunconditional_recursionwarning.
Tooling 1
Suppresses the redundant_field_names clippy lint in generated code, avoiding lint reports for that code.
Fixes and other changes 1
Fixes parsing of generic unit variants in display expressions.