Small improvements for metaprogramming

Some things I needed while writing a procedural macro recently.