librustc: Call return_type only for functions.

Fixes #18576.