next hemp =>
  simp at h
  have : stack.pop.size < stack.size := Array.lt_size_of_pop_of_not_empty _ (by assumption)
  cases Array.mem_pop_or_eq_of_mem _ _ hemp hmem with
  | inl hmem =>
    split at h
    next => exact mem_stack_mem_exploreεClosure h hmem
    next => exact mem_stack_mem_εClosure h hmem
  | inr heq =>
    split at h
    next target heq' =>
      rw [heq'] at heq
      have : target = i := by
        simp at heq
        rw [heq]
      rw [this] at h
      exact target_mem_exploreεClosure h
    next _ heq' =>
      rw [heq'] at heq
      contradiction
case inr
nfa : NFA
pos : String.Pos
next : SparseSet nfa.nodes.size
currentSave : Array (Option String.Pos)
matched : Option (Array (Option String.Pos))
saveSlots : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
stack : Array (StackEntry nfa.nodes.size)
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
i : Fin nfa.nodes.size
hmem : StackEntry.explore i ∈ stack
h✝ : ¬stack.isEmpty = true
h :
  (let entry := stack.back' h✝;
    let stack' := stack.pop;
    let_fun this := ⋯;
    match entry with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack'
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack') =
    (matched', next', saveSlots')
⊢ i ∈ next'
no goals