lean4-htt/tests/lean/run/exact_rw_deprecated.lean
Kim Morrison 975a81cdb8
feat: filter out deprecated lemmas from suggestions in exact?/rw? (#11918)
This PR filters deprecated lemmas from `exact?` and `rw?` suggestions.

Previously, both tactics would suggest deprecated lemmas, which could be
confusing for users since using the suggestion would trigger a
deprecation warning.

Now, lemmas marked with `@[deprecated]` are filtered out in the
`addImport` functions that populate the discrimination trees used by
these tactics.

**Example (before this PR):**
```lean
import Mathlib.Logic.Basic

example (h : ∃ n : Nat, n > 0) : True := by
  choose (n : Nat) (hn : n > 0 + 0) using h
  guard_hyp hn : n > 0  -- `rw?` would suggest `Eq.rec_eq_cast` which is deprecated
```

Zulip discussion:
https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/deprecated.20lemma.20from.20rw.3F/near/554106870

🤖 Prepared with Claude Code

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 23:45:04 +00:00

38 lines
1,016 B
Text

/-!
# Test that `exact?` and `rw?` do not suggest deprecated lemmas
-/
-- Create a deprecated lemma and its non-deprecated replacement
@[deprecated "use myLemma2" (since := "2025-01-01")]
theorem myLemma1 : True := trivial
theorem myLemma2 : True := trivial
-- Test that exact? suggests myLemma2, not the deprecated myLemma1
/--
info: Try this:
[apply] exact myLemma2
-/
#guard_msgs in
example : True := by exact?
-- Create a unique type so our lemmas are the only matches
structure MyType where
val : Nat
def myFn (x : MyType) : MyType := x
-- Create deprecated and non-deprecated rewrite lemmas with unique signature
@[deprecated "use myRwLemma2" (since := "2025-01-01")]
theorem myRwLemma1 (x : MyType) : myFn (myFn x) = myFn x := rfl
theorem myRwLemma2 (x : MyType) : myFn (myFn x) = myFn x := rfl
-- Test that rw? suggests myRwLemma2, not the deprecated myRwLemma1
/--
info: Try this:
[apply] rw [myRwLemma2]
-- no goals
-/
#guard_msgs in
example (x : MyType) : myFn (myFn x) = myFn x := by rw?