diff --git a/src/Lean/Meta/Match/Basic.lean b/src/Lean/Meta/Match/Basic.lean index 3b616bf0de..ba46ab6e43 100644 --- a/src/Lean/Meta/Match/Basic.lean +++ b/src/Lean/Meta/Match/Basic.lean @@ -9,6 +9,15 @@ import Lean.Meta.Match.CaseArraySizes namespace Lean.Meta.Match +/-- + Auxiliary annotation used to mark terms marked with the "inaccessible" annotation `.(t)` and + `_` in patterns. -/ +def mkInaccessible (e : Expr) : Expr := + mkAnnotation `_inaccessible e + +def inaccessible? (e : Expr) : Option Expr := + annotation? `_inaccessible e + inductive Pattern : Type where | inaccessible (e : Expr) : Pattern | var (fvarId : FVarId) : Pattern @@ -36,7 +45,7 @@ where match p with | inaccessible e => if annotate then - pure (mkAnnotation `inaccessible e) + pure (mkInaccessible e) else pure e | var fvarId => pure $ mkFVar fvarId @@ -256,15 +265,6 @@ structure MatcherResult where counterExamples : List CounterExample unusedAltIdxs : List Nat -/-- - Auxiliary annotation used to mark terms marked with the "inaccessible" annotation `.(t)` and - `_` in patterns. -/ -def mkInaccessible (e : Expr) : Expr := - mkAnnotation `_inaccessible e - -def inaccessible? (e : Expr) : Option Expr := - annotation? `_inaccessible e - /-- Convert a expression occurring as the argument of a `match` motive application back into a `Pattern` For example, we can use this method to convert `x::y::xs` at diff --git a/src/Lean/PrettyPrinter/Delaborator/Builtins.lean b/src/Lean/PrettyPrinter/Delaborator/Builtins.lean index 9b43efc995..04b55cd24d 100644 --- a/src/Lean/PrettyPrinter/Delaborator/Builtins.lean +++ b/src/Lean/PrettyPrinter/Delaborator/Builtins.lean @@ -265,23 +265,20 @@ def delabAppMatch : Delab := whenPPOption getPPNotation do @[builtinDelab mdata] def delabMData : Delab := do - -- only interpret `pp.` values by default - let Expr.mdata m _ _ ← getExpr | unreachable! - let mut posOpts := (← read).optionsPerPos - let mut inaccessible := false - let pos := (← read).pos - for (k, v) in m do - if (`pp).isPrefixOf k then - let opts := posOpts.find? pos |>.getD {} - posOpts := posOpts.insert pos (opts.insert k v) - if k == `inaccessible then - inaccessible := true - withReader ({ · with optionsPerPos := posOpts }) do + if let some _ := Lean.Meta.Match.inaccessible? (← getExpr) then let s ← withMDataExpr delab - if inaccessible then - `(.($s)) - else - pure s + `(.($s)) + else + -- only interpret `pp.` values by default + let Expr.mdata m _ _ ← getExpr | unreachable! + let mut posOpts := (← read).optionsPerPos + let pos := (← read).pos + for (k, v) in m do + if (`pp).isPrefixOf k then + let opts := posOpts.find? pos |>.getD {} + posOpts := posOpts.insert pos (opts.insert k v) + withReader ({ · with optionsPerPos := posOpts }) do + withMDataExpr delab /-- Check for a `Syntax.ident` of the given name anywhere in the tree.