@@ -40,7 +40,7 @@ impl PubGrubPriorities {
40
40
match self . 0 . entry ( name. clone ( ) ) {
41
41
std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
42
42
// Preserve the original index.
43
- let index = Self :: get_index ( next , & mut entry) ;
43
+ let index = Self :: get_index ( & entry) . unwrap_or ( next ) ;
44
44
45
45
// Compute the priority.
46
46
let priority = if urls. get ( name) . is_some ( ) {
@@ -80,14 +80,14 @@ impl PubGrubPriorities {
80
80
}
81
81
}
82
82
83
- fn get_index ( next : usize , entry : & mut OccupiedEntry < PackageName , PubGrubPriority > ) -> usize {
83
+ fn get_index ( entry : & OccupiedEntry < PackageName , PubGrubPriority > ) -> Option < usize > {
84
84
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 ,
91
91
}
92
92
}
93
93
@@ -109,19 +109,19 @@ impl PubGrubPriorities {
109
109
let next = self . 0 . len ( ) ;
110
110
let Some ( name) = package. name_no_root ( ) else {
111
111
// 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
+ }
117
117
} ;
118
118
match self . 0 . entry ( name. clone ( ) ) {
119
119
std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
120
120
if matches ! ( entry. get( ) , PubGrubPriority :: ConflictEarly ( _) ) {
121
121
// Already in the right category
122
122
return false ;
123
123
} ;
124
- let index = Self :: get_index ( next , & mut entry) ;
124
+ let index = Self :: get_index ( & entry) . unwrap_or ( next ) ;
125
125
entry. insert ( PubGrubPriority :: ConflictEarly ( Reverse ( index) ) ) ;
126
126
true
127
127
}
@@ -136,11 +136,11 @@ impl PubGrubPriorities {
136
136
let next = self . 0 . len ( ) ;
137
137
let Some ( name) = package. name_no_root ( ) else {
138
138
// 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
+ }
144
144
} ;
145
145
match self . 0 . entry ( name. clone ( ) ) {
146
146
std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
@@ -152,7 +152,7 @@ impl PubGrubPriorities {
152
152
// Already in the right category
153
153
return false ;
154
154
} ;
155
- let index = Self :: get_index ( next , & mut entry) ;
155
+ let index = Self :: get_index ( & entry) . unwrap_or ( next ) ;
156
156
entry. insert ( PubGrubPriority :: ConflictLate ( Reverse ( index) ) ) ;
157
157
true
158
158
}
0 commit comments