Throw TypeErrors instead of uncatcheable exceptions in CodegenRust.py (fixes #347, #3065).