Mutation/Creation of HIR
⚓ Rust 📅 2026-05-01 👤 surdeus 👁️ 3I was looking into the compiler API for rustc_drivers and I saw that there exists a MutVisitor trait one can implement to mutate different language items/expressions when working with the AST. This trait also exits for the MIR. However, it does not seem to exist for the HIR (only Visitor exists). My first question is why is this the case. I looked at previous posts and they all mention that the HIR is immutable but I don't understand why it needs to be that way. Finally, assuming there is a principled reason the HIR is immutable. Would it be possible to copy the HIR perform some modifications on the copy and pass it down for further compilation? If this is not possible it would also be good to understand why. Thank you very much in advance.
cross post: Mutation/Creation of HIR - compiler - Rust Internals
3 posts - 2 participants
🏷️ Rust_feed