Fix check for pickling closures

Only closures on the outer-most function don't work.
Internal closures that fully resolve should still be fine.
Merge pull request #5762 from minrk/better_closure_check

Fix check for pickling closures