This reduces the complexity of this code a lot
itertools
Please read the rustc-dev-guide chapter on Backend Agnostic Codegen.