Skip to content

Commit 5c6d8c4

Browse files
committed
feat(push): error message tweaks (#38008)
- make free variables in all errors "made no progress" hoverable (this applies also to ring, abel, field_simp, ...) - include the constant being pushed in the error message
1 parent f369f66 commit 5c6d8c4

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Mathlib/Tactic/Push.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def elabDischarger (stx : TSyntax ``discharger) : TacticM Simp.Discharge :=
211211
def push (cfg : Config) (disch? : Option Simp.Discharge) (head : Head) (loc : Location)
212212
(failIfUnchanged : Bool := true) : TacticM Unit := do
213213
let cfg := { distrib := cfg.distrib || (← getBoolOption `push_neg.use_distrib) }
214-
transformAtLocation (pushCore head cfg disch? ·) "push" loc failIfUnchanged
214+
transformAtLocation (pushCore head cfg disch? ·) s!"push {head}" loc failIfUnchanged
215215

216216
/--
217217
`push c` rewrites the goal by pushing the constant `c` deeper into an expression.

Mathlib/Util/AtLocation.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ def transformAtLocalDecl (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (
8080
ReaderT Simp.Context MetaM (Option MVarId) := do
8181
let ldecl ← fvarId.getDecl
8282
if ldecl.isImplementationDetail then
83-
throwError "Cannot run `{proc}` at `{ldecl.userName}`, it is an implementation detail"
83+
throwError "Cannot run `{proc}` at `{Expr.fvar fvarId}`, it is an implementation detail"
8484
let tgt ← instantiateMVars (← fvarId.getType)
8585
let eraseFVarId (ctx : Simp.Context) :=
8686
ctx.setSimpTheorems <| ctx.simpTheorems.eraseTheorem (.fvar fvarId)
8787
let r ← withReader eraseFVarId <| m tgt
8888
-- we use expression equality here (rather than defeq) to be consistent with, e.g.,
8989
-- `applySimpResultToLocalDeclCore`
9090
if failIfUnchanged && tgt.cleanupAnnotations == r.expr.cleanupAnnotations then
91-
throwError "`{proc}` made no progress at `{ldecl.userName}`"
91+
throwError "`{proc}` made no progress at `{Expr.fvar fvarId}`"
9292
return (← applySimpResultToLocalDecl goal fvarId r mayCloseGoal).map Prod.snd
9393

9494
/-- Use the procedure `m` to transform at specified locations (hypotheses and/or goal).

MathlibTest/push_neg.lean

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,29 @@ example (h : p ∧ q) : ¬¬(p ∧ q) := by
145145
exact h
146146

147147
-- new error message as of https://github.com/leanprover-community/mathlib4/issues/27562
148-
/-- error: `push` made no progress anywhere -/
148+
/-- error: `push Not` made no progress anywhere -/
149149
#guard_msgs in
150150
example {P : Prop} (h : P) : P := by push Not at *
151151

152152
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562
153153
-- (Previously, because of a metavariable instantiation issue, the tactic succeeded as a no-op.)
154-
/-- error: `push` made no progress at `h` -/
154+
/-- error: `push Not` made no progress at `h` -/
155155
#guard_msgs in
156156
example {x y : ℕ} : True := by
157157
have h : x ≤ y := test_sorry
158158
push Not at h
159159

160160
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562 (previously the tactic succeeded as a no-op)
161-
/-- error: Cannot run `push` at `inductive_proof`, it is an implementation detail -/
161+
/-- error: Cannot run `push Not` at `inductive_proof`, it is an implementation detail -/
162162
#guard_msgs in
163163
def inductive_proof : True := by
164164
push Not at inductive_proof
165165
trivial
166166

167+
/-- error: `push Not` made no progress on the goal -/
168+
#guard_msgs in
169+
example {P : Prop} (h : P) : P := by push Not
170+
167171
section use_distrib
168172

169173
example (h : ¬ p ∨ ¬ q) : ¬ (p ∧ q) := by

0 commit comments

Comments
 (0)