Fix rustc panic on second compile_input

Closes #19371
may as well inline this for the test to make it as minimal as possible