diff --git a/src/sandbox/mod.rs b/src/sandbox/mod.rs index 1cccd1d..1dad459 100644 --- a/src/sandbox/mod.rs +++ b/src/sandbox/mod.rs @@ -327,14 +327,16 @@ impl Sandbox { fn remove_net(&mut self, net_id: NetId) -> Option { if let Some((net, rename)) = self.nets.remove(net_id.0) { - // Rename all the references to the net that was moved into this position. - let renamed = self.nets.get(rename.dest).unwrap(); - for wire_id in &renamed.wires { - self.wires.get_mut(wire_id.0).unwrap().net_id = NetId(rename.dest); - } - //TODO remove this clone, reduce size of get_peg_mut borrow - for peg_id in &renamed.pegs.clone() { - self.get_peg_mut(peg_id).unwrap().net_id = NetId(rename.dest); + if rename.src != rename.dest { + // Rename all the references to the net that was moved into this position. + let renamed = self.nets.get(rename.dest).unwrap(); + for wire_id in &renamed.wires { + self.wires.get_mut(wire_id.0).unwrap().net_id = NetId(rename.dest); + } + //TODO remove this clone, reduce size of get_peg_mut borrow + for peg_id in &renamed.pegs.clone() { + self.get_peg_mut(peg_id).unwrap().net_id = NetId(rename.dest); + } } // Perform the same swap-remove in net_states: