Why am I getting this error (E0502)?

⚓ Rust    📅 2025-09-04    👤 surdeus    👁️ 3      

surdeus

I am getting this error:

error[E0502]: cannot borrow `*self` as immutable because it is also borrowed as mutable
    --> src/system.rs:1928:28
     |
1909 |                 let car: &mut Car = self.cars.get_mut(Cx).unwrap();
     |                                     --------- mutable borrow occurs here
...
1928 |                         if self.FixedRouteMirrorCheck(car,self.industries
     |                            ^^^^                       --- mutable borrow later used here
     |                            |
     |                            immutable borrow occurs here

FixedRouteMirrowCheck has this signature. None of its parameters are mutable. Why is the compiler complaining? FixedRouteMirrorCheck just does some checking and does not modify anything (but is does need the self parameter to allow looking some things up.

 fn FixedRouteMirrorCheck(&self,car: &Car,Ix: Option<&Industry>) -> bool {...}   

The full crate is here: GitHub - RobertPHeller/freight_car_forwarder: Freight Car Forwarders in rust

2 posts - 2 participants

Read full topic

🏷️ Rust_feed