What permits `fn(&mut self) -> &Inner`?
⚓ Rust 📅 2026-03-22 👤 surdeus 👁️ 3So, this is, I think, a borrowchecker terminology question.
The following get_ref method (which, to be clear, compiles just fine) turns an exclusive borrow of self into a shared borrow of self.0:
struct MyStruct(i32);
impl MyStruct {
fn get_ref(&mut self) -> &i32 {
&self.0
}
}
Intuitively, I have no problems with this, it's exactly what I would expect (i.e., the borrow checker won't let you use &mut self again until &i32 reference has been dropped).
My question is: what feature permits me to "downgrade" from an &mut to an & like this? Is it "reborrowing"? "Projection"? Or maybe something involving the Deref/DerefMut traits?
2 posts - 2 participants
🏷️ Rust_feed