feat: add deprecated_arg attribute#13011
Merged
wkrozowski merged 7 commits intoleanprover:masterfrom Mar 30, 2026
Merged
Conversation
This disables `cbv` usage warning and reflects that in the corresponding unit tests. chore: add `DeprecatedArg` extension chore: elaborate `deprecated_arg` attribute and basic error handling chore: add elaborator warning test: add package test chore: fix deprecation message
Contributor
Author
|
!bench |
|
Benchmark results for c4cc192 against d9c3bbf are in. There are no significant changes. @wkrozowski
Small changes (2🟥)
|
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
5c86bdb to
78261c0
Compare
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
This PR adds a `@[deprecated_arg]` attribute that marks individual function parameters as deprecated. When a caller uses the old parameter name, the elaborator emits a deprecation warning with a code action hint to rename or delete the argument, and silently forwards the value to the correct binder. Supported forms: - `@[deprecated_arg old new (since := "...")]` — renamed parameter, warns and forwards - `@[deprecated_arg old new "reason" (since := "...")]` — with custom message - `@[deprecated_arg removed (since := "...")]` — removed parameter, errors with delete hint - `@[deprecated_arg removed "reason" (since := "...")]` — removed with custom message A warning is emitted if `(since := "...")` is omitted. When a parameter is deprecated without a replacement, the elaborator treats it as no longer present: using it as a named argument produces an error. Note that positional uses of deprecated arguments are not checked — if a function's arity changed, the caller will simply get a "function expected" error. The `linter.deprecated.arg` option (default `true`) controls behavior: when enabled, renamed args produce warnings and removed args produce specific deprecation errors with code action hints; when disabled, both fall through to the standard "invalid argument name" error. This lets library authors phase out old parameter names without breaking downstream code immediately. Example (renamed parameter): ```lean @[deprecated_arg old new (since := "2026-03-18")] def f (new : Nat) : Nat := new /-- warning: parameter `old` of `f` has been deprecated, use `new` instead Hint: Rename this argument: o̵l̵d̵n̲e̲w̲ --- info: f 42 : Nat -/ #guard_msgs in #check f (old := 42) ``` Example (removed parameter): ```lean @[deprecated_arg removed (since := "2026-03-18")] def g (x : Nat) : Nat := x /-- error: parameter `removed` of `g` has been deprecated Hint: Delete this argument: (̵r̵e̵m̵o̵v̵e̵d̵ ̵:̵=̵ ̵4̵2̵)̵ -/ #guard_msgs in #check g (removed := 42) ```
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.
This PR adds a
@[deprecated_arg]attribute that marks individual function parameters as deprecated. When a caller uses the old parameter name, the elaborator emits a deprecation warning with a code action hint to rename or delete the argument, and silently forwards the value to the correct binder.Supported forms:
@[deprecated_arg old new (since := "...")]— renamed parameter, warns and forwards@[deprecated_arg old new "reason" (since := "...")]— with custom message@[deprecated_arg removed (since := "...")]— removed parameter, errors with delete hint@[deprecated_arg removed "reason" (since := "...")]— removed with custom messageA warning is emitted if
(since := "...")is omitted.When a parameter is deprecated without a replacement, the elaborator treats it as no longer present: using it as a named argument produces an error. Note that positional uses of deprecated arguments are not checked — if a function's arity changed, the caller will simply get a "function expected" error.
The
linter.deprecated.argoption (defaulttrue) controls behavior: when enabled, renamed args produce warnings and removed args produce specific deprecation errors with code action hints; when disabled, both fall through to the standard "invalid argument name" error. This lets library authors phase out old parameter names without breaking downstream code immediately.Example (renamed parameter):
Example (removed parameter):