Repository navigation
fix: infer deprecation allowances from error attributes - #70
Merged
rklaehn merged 1 commit intoNov 9, 2026
Merged
Conversation
4 tasks done
Frando
approved these changes
Nov 9, 2026
Frando
left a comment
Member
There was a problem hiding this comment.
Cool, this is cleaner than the other approach for sure.
rklaehn
added a commit
that referenced
this pull request
Nov 9, 2026
…es (#52) ## Description The `stack_error` macro expands to impls that match on and construct every enum variant, including deprecated ones. With `#[deny(deprecated)]`, an enum with a `#[deprecated]` variant therefore fails to compile at the `#[stack_error(..)]` call site. `StackError` now allows the `deprecated` lint in its generated impls when the type or one of its variants has `#[deprecated]` or `#[allow(deprecated)]`. This needs no option. Serde handles deprecation the same way. - The allowance covers only the generated impls: they are wrapped in `#[allow(deprecated)] const _: () = { ... };`. User code that constructs a deprecated variant still warns. - An enum without deprecation keeps the lint as it is, also in user-provided formatting expressions such as `#[error("{}", old_formatter())]`. Two `compile_fail` doctests in `tests/deprecated.md` check this, together with the case above. - Unit tests cover deprecated variants, deprecated enums and structs, an `#[allow(deprecated)]` on the item or on a variant, and an enum without deprecation under `#[forbid(deprecated)]`. ## Breaking Changes None. ## Notes & open questions The first version of this PR added an opt-in `allow_deprecated` option to `stack_error`. It is gone; the allowance is now inferred from the attributes (#69, #70). On per-arm allowances: the allowance is scoped to the generated impls, and those only touch the type's own variants, so allowing it on the whole impl hides no warning in user code. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented. --------- Co-authored-by: Ruediger Klaehn <rklaehn@protonmail.com> Co-authored-by: Rüdiger Klaehn <rklaehn@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Alternative to the unconditional allowance in #69, stacked on that branch for a focused comparison. No explicit
allow_deprecatedmacro option.Follow Serde's detection: if the type or one of its enum variants has
#[deprecated]or#[allow(deprecated)], allow deprecation in the generated impls. Otherwise leave the lint unchanged.This keeps ordinary enums working under
forbid(deprecated)and preserves warnings for deprecated functions used in their#[error("...", expression)]formatting arguments. Deprecated types and variants still derive without internal warnings; direct uses in user code still warn.The implementation adds 34 lines around derive expansion and removes the unconditional allowances. A scoped anonymous const holds the generated impls, avoiding an extra flag passed through each generator. This also handles deprecated structs and whole enums. No new dependencies.
Breaking Changes
Compared with #69, deprecated formatting helpers on otherwise ordinary enums warn again. This preserves the behavior before the proposed unconditional allowance.
Notes & open questions
As with Serde, once detection triggers, the allowance covers all generated impls, including user-provided formatting expressions inside them. It is conditional, not scoped to individual expressions.
Validation: 26 unit tests and 4 doctests pass, including two compile-fail regressions.
cargo fmt --checkpasses. Clippy passes with the existingclippy::useless_formatwarning atsrc/tests.rs:110allowed; strict Clippy fails on that unchanged line.Change checklist
forbid(deprecated), and retained user-code diagnostics.