chore: use Expr.forEachWhere to implement linter

closes #1899

TODO: use `Expr.forEachWhere` in other modules. There are many other opportunities.
This commit is contained in:
Leonardo de Moura 2022-11-30 18:44:20 -08:00
parent 1c5706bcc0
commit 30d625697e

View file

@ -1,4 +1,5 @@
import Lean.Elab.Command
import Lean.Util.ForEachExprWhere
import Lean.Linter.Util
import Lean.Server.References
@ -179,9 +180,7 @@ def unusedVariables : Linter := fun cmdStx => do
let tacticFVarUses : HashSet FVarId ←
tacticMVarAssignments.foldM (init := .empty) fun uses _ expr => do
let (_, s) ← StateT.run (s := uses) <| expr.forEach fun
| .fvar id => modify (·.insert id)
| _ => pure ()
let (_, s) ← StateT.run (s := uses) <| expr.forEachWhere Expr.isFVar fun e => modify (·.insert e.fvarId!)
return s
-- collect ignore functions