This PR adjusts the "try this" widget to be rendered as a widget message under 'Messages', not a separate widget under a 'Suggestions' section. The main benefit of this is that the message of the widget is not duplicated between 'Messages' and 'Suggestions'. Since widget message suggestions were already implemented by @jrr6 for the new hint infrastructure, this PR replaces the old "try this" implementation with the new hint infrastructure. In doing so, the `style?` field of suggestions is deprecated, since the hint infrastructure highlights hints using diff colors, and `style?` also never saw much use downstream. Additionally, since the message and the suggestion are now the same component, the `messageData?` field of suggestions is deprecated as well. Notably, the "Try this:" message string now also contains a newline and indentation to separate the suggestion from the rest of the message more clearly and the `postInfo?` field of the suggestion is now part of the message. Finally, this PR changes the diff colors used by the hint infrastructure to be more color-blindness-friendly (insertions are now blue, not green, and text that remains unchanged is now using the editor foreground color instead of blue). ### Breaking changes Tests that use `#guard_msgs` to test the "Try this:" message may need to be adjusted for the new formatting of the message.
129 lines
3.3 KiB
Text
129 lines
3.3 KiB
Text
private axiom test_sorry : ∀ {α}, α
|
||
|
||
-- To see the (sorted) list of lemmas that `rw?` will try rewriting by, use:
|
||
-- set_option trace.Tactic.rewrites.lemmas true
|
||
|
||
/--
|
||
info: Try this:
|
||
rw [@List.map_append]
|
||
-- no goals
|
||
-/
|
||
#guard_msgs in
|
||
example (f : α → β) (L M : List α) : (L ++ M).map f = L.map f ++ M.map f := by
|
||
rw?
|
||
|
||
/--
|
||
info: Try this:
|
||
rw [Nat.one_mul]
|
||
-- no goals
|
||
-/
|
||
#guard_msgs in
|
||
example (h : Nat) : 1 * h = h := by
|
||
rw?
|
||
|
||
#guard_msgs(drop info) in
|
||
example (h : Int) (hyp : g * 1 = h) : g = h := by
|
||
rw? at hyp
|
||
assumption
|
||
|
||
#guard_msgs(drop info) in
|
||
example : ∀ (x y : Nat), x ≤ y := by
|
||
intro x y
|
||
rw? -- Used to be an error here https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/panic.20and.20error.20with.20rw.3F/near/370495531
|
||
exact test_sorry
|
||
|
||
example : ∀ (x y : Nat), x ≤ y := by
|
||
-- Used to be a panic here https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/panic.20and.20error.20with.20rw.3F/near/370495531
|
||
fail_if_success rw?
|
||
exact test_sorry
|
||
|
||
axiom K : Type
|
||
@[instance] axiom K.hasOne : OfNat K 1
|
||
@[instance] axiom K.hasIntCoe : Coe K Int
|
||
|
||
noncomputable def foo : K → K := test_sorry
|
||
|
||
#guard_msgs(drop info) in
|
||
example : foo x = 1 ↔ ∃ k : Int, x = k := by
|
||
rw? -- Used to panic, see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/panic.20and.20error.20with.20rw.3F/near/370598036
|
||
exact test_sorry
|
||
|
||
theorem six_eq_seven : 6 = 7 := test_sorry
|
||
|
||
-- This test also verifies that we are removing duplicate results;
|
||
-- it previously also reported `Nat.cast_ofNat`
|
||
#guard_msgs(drop info) in
|
||
example : ∀ (x : Nat), x ≤ 6 := by
|
||
rw?
|
||
guard_target = ∀ (x : Nat), x ≤ 7
|
||
exact test_sorry
|
||
|
||
#guard_msgs(drop info) in
|
||
example : ∀ (x : Nat) (_w : x ≤ 6), x ≤ 8 := by
|
||
rw?
|
||
guard_target = ∀ (x : Nat) (_w : x ≤ 7), x ≤ 8
|
||
exact test_sorry
|
||
|
||
-- check we can look inside let expressions
|
||
#guard_msgs(drop info) in
|
||
example (n : Nat) : let y := 3; n + y = 3 + n := by
|
||
rw?
|
||
|
||
axiom α : Type
|
||
axiom f : α → α
|
||
axiom z : α
|
||
axiom f_eq (n) : f n = z
|
||
|
||
-- Check that the same lemma isn't used multiple times.
|
||
-- This used to report two redundant copies of `f_eq`.
|
||
-- It be lovely if `rw?` could produce two *different* rewrites by `f_eq` here!
|
||
#guard_msgs(drop info) in
|
||
theorem test : f n = f m := by
|
||
fail_if_success rw? [-f_eq] -- Check that we can forbid lemmas.
|
||
rw?
|
||
rw [f_eq]
|
||
|
||
-- Check that we can rewrite by local hypotheses.
|
||
#guard_msgs(drop info) in
|
||
example (h : 1 = 2) : 2 = 1 := by
|
||
rw?
|
||
|
||
def zero : Nat := 0
|
||
|
||
-- This used to (incorrectly!) succeed because `rw?` would try `rfl`,
|
||
-- rather than `withReducible` `rfl`.
|
||
#guard_msgs(drop info) in
|
||
example : zero = 0 := by
|
||
rw?
|
||
exact test_sorry
|
||
|
||
-- Discharge side conditions from local hypotheses.
|
||
/--
|
||
info: Try this:
|
||
rw [h p]
|
||
-- no goals
|
||
-/
|
||
#guard_msgs in
|
||
example {P : Prop} (p : P) (h : P → 1 = 2) : 2 = 1 := by
|
||
rw?
|
||
|
||
-- Use `solve_by_elim` to discharge side conditions.
|
||
/--
|
||
info: Try this:
|
||
rw [h (f p)]
|
||
-- no goals
|
||
-/
|
||
#guard_msgs in
|
||
example {P Q : Prop} (p : P) (f : P → Q) (h : Q → 1 = 2) : 2 = 1 := by
|
||
rw?
|
||
|
||
-- Rewrite in reverse, discharging side conditions from local hypotheses.
|
||
/--
|
||
info: Try this:
|
||
rw [← h₁ p]
|
||
-- Q a
|
||
-/
|
||
#guard_msgs in
|
||
example {P : Prop} (p : P) (Q : α → Prop) (a b : α) (h₁ : P → a = b) (w : Q a) : Q b := by
|
||
rw?
|
||
exact w
|