@@ -40,7 +40,7 @@ impl PubGrubPriorities {
4040 match self . 0 . entry ( name. clone ( ) ) {
4141 std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
4242 // Preserve the original index.
43- let index = Self :: get_index ( next , & mut entry) ;
43+ let index = Self :: get_index ( & entry) . unwrap_or ( next ) ;
4444
4545 // Compute the priority.
4646 let priority = if urls. get ( name) . is_some ( ) {
@@ -80,14 +80,14 @@ impl PubGrubPriorities {
8080 }
8181 }
8282
83- fn get_index ( next : usize , entry : & mut OccupiedEntry < PackageName , PubGrubPriority > ) -> usize {
83+ fn get_index ( entry : & OccupiedEntry < PackageName , PubGrubPriority > ) -> Option < usize > {
8484 match entry. get ( ) {
85- PubGrubPriority :: ConflictLate ( Reverse ( index) ) => * index ,
86- PubGrubPriority :: Unspecified ( Reverse ( index) ) => * index ,
87- PubGrubPriority :: ConflictEarly ( Reverse ( index) ) => * index ,
88- PubGrubPriority :: Singleton ( Reverse ( index) ) => * index ,
89- PubGrubPriority :: DirectUrl ( Reverse ( index) ) => * index,
90- PubGrubPriority :: Root => next ,
85+ PubGrubPriority :: ConflictLate ( Reverse ( index) )
86+ | PubGrubPriority :: Unspecified ( Reverse ( index) )
87+ | PubGrubPriority :: ConflictEarly ( Reverse ( index) )
88+ | PubGrubPriority :: Singleton ( Reverse ( index) )
89+ | PubGrubPriority :: DirectUrl ( Reverse ( index) ) => Some ( * index) ,
90+ PubGrubPriority :: Root => None ,
9191 }
9292 }
9393
@@ -109,19 +109,19 @@ impl PubGrubPriorities {
109109 let next = self . 0 . len ( ) ;
110110 let Some ( name) = package. name_no_root ( ) else {
111111 // Not a correctness bug
112- assert ! (
113- !cfg! ( debug_assertions ) ,
114- "URL packages must not be involved in conflict handling"
115- ) ;
116- return false ;
112+ if cfg ! ( debug_assertions ) {
113+ panic ! ( "URL packages must not be involved in conflict handling" )
114+ } else {
115+ return false ;
116+ }
117117 } ;
118118 match self . 0 . entry ( name. clone ( ) ) {
119119 std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
120120 if matches ! ( entry. get( ) , PubGrubPriority :: ConflictEarly ( _) ) {
121121 // Already in the right category
122122 return false ;
123123 } ;
124- let index = Self :: get_index ( next , & mut entry) ;
124+ let index = Self :: get_index ( & entry) . unwrap_or ( next ) ;
125125 entry. insert ( PubGrubPriority :: ConflictEarly ( Reverse ( index) ) ) ;
126126 true
127127 }
@@ -136,11 +136,11 @@ impl PubGrubPriorities {
136136 let next = self . 0 . len ( ) ;
137137 let Some ( name) = package. name_no_root ( ) else {
138138 // Not a correctness bug
139- assert ! (
140- !cfg! ( debug_assertions ) ,
141- "URL packages must not be involved in conflict handling"
142- ) ;
143- return false ;
139+ if cfg ! ( debug_assertions ) {
140+ panic ! ( "URL packages must not be involved in conflict handling" )
141+ } else {
142+ return false ;
143+ }
144144 } ;
145145 match self . 0 . entry ( name. clone ( ) ) {
146146 std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
@@ -152,7 +152,7 @@ impl PubGrubPriorities {
152152 // Already in the right category
153153 return false ;
154154 } ;
155- let index = Self :: get_index ( next , & mut entry) ;
155+ let index = Self :: get_index ( & entry) . unwrap_or ( next ) ;
156156 entry. insert ( PubGrubPriority :: ConflictLate ( Reverse ( index) ) ) ;
157157 true
158158 }
0 commit comments