@@ -798,16 +798,16 @@ where
798798 ///
799799 /// # Panics
800800 ///
801- /// Panics if either `self` or `other` is a multi-output circuit node.
801+ /// Panics if either `self` is a multi-output circuit node.
802802 /// Panics if the weak reference to the netlist is lost.
803- pub fn replace_uses_with ( self , other : & Self ) -> Result < Object < I > , Error > {
803+ pub fn replace_uses_with ( self , other : & DrivenNet < I > ) -> Result < Object < I > , Error > {
804804 let netlist = self
805805 . netref
806806 . borrow ( )
807807 . owner
808808 . upgrade ( )
809809 . expect ( "NetRef is unlinked from netlist" ) ;
810- netlist. replace_net_uses ( self , other)
810+ netlist. replace_net_uses ( self . into ( ) , other)
811811 }
812812
813813 /// Clears the attribute with the given key on this circuit node.
@@ -1364,17 +1364,25 @@ where
13641364 }
13651365
13661366 /// Replaces the uses of a circuit node with another circuit node. The [Object] stored at `of` is returned.
1367- /// Panics if `of` and `with` are not single-output nodes.
1368- pub fn replace_net_uses ( & self , of : NetRef < I > , with : & NetRef < I > ) -> Result < Object < I > , Error > {
1369- let unwrapped = of. clone ( ) . unwrap ( ) ;
1367+ pub fn replace_net_uses (
1368+ & self ,
1369+ of : DrivenNet < I > ,
1370+ with : & DrivenNet < I > ,
1371+ ) -> Result < Object < I > , Error > {
1372+ let unwrapped = of. clone ( ) . unwrap ( ) . unwrap ( ) ;
13701373 if Rc :: strong_count ( & unwrapped) > 3 {
1371- return Err ( Error :: DanglingReference ( of. nets ( ) . collect ( ) ) ) ;
1374+ return Err ( Error :: DanglingReference ( of. unwrap ( ) . nets ( ) . collect ( ) ) ) ;
13721375 }
13731376
1374- let old_tag: DrivenNet < I > = of. clone ( ) . into ( ) ;
1375- let old_index = old_tag. get_operand ( ) ;
1376- let new_tag: DrivenNet < I > = with. clone ( ) . into ( ) ;
1377- let new_index = new_tag. get_operand ( ) ;
1377+ let old_index = of. get_operand ( ) ;
1378+
1379+ if let Some ( v) = self . outputs . borrow ( ) . get ( & old_index)
1380+ && * v == * of. as_net ( )
1381+ {
1382+ return Err ( Error :: NonuniqueNets ( vec ! [ v. clone( ) ] ) ) ;
1383+ }
1384+
1385+ let new_index = with. get_operand ( ) ;
13781386 let objects = self . objects . borrow ( ) ;
13791387 for oref in objects. iter ( ) {
13801388 let operands = & mut oref. borrow_mut ( ) . operands ;
@@ -1396,7 +1404,7 @@ where
13961404 self . outputs . borrow_mut ( ) . insert ( new_index, v. clone ( ) ) ;
13971405 }
13981406
1399- Ok ( of. unwrap ( ) . borrow ( ) . get ( ) . clone ( ) )
1407+ Ok ( of. unwrap ( ) . unwrap ( ) . borrow ( ) . get ( ) . clone ( ) )
14001408 }
14011409}
14021410
0 commit comments