check_static_recursion: Handle foreign items
auto merge of #18279 : bgamari/rust/check-static-recursion, r=alexcrichton

I just found this patch which at some point solved a problem I encountered. Unfortunately I apparently dropped it before I managed to write a test case. I'll try to dig up the code that triggered the issue.