fix infinite-recursion regression in rewrite

Reported by axion on IRC.