@@ -161,38 +161,23 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
161161 // We've encountered an `AnonConst` in some path, so we need to
162162 // figure out which generic parameter it corresponds to and return
163163 // the relevant type.
164- let filtered = path. segments . iter ( ) . find_map ( |seg| {
165- seg. args ?
166- . args
164+ let Some ( ( arg_index, segment) ) = path. segments . iter ( ) . find_map ( |seg| {
165+ let args = seg. args ?;
166+ args. args
167+ . iter ( )
168+ . filter ( |arg| arg. is_ty_or_const ( ) )
169+ . position ( |arg| arg. id ( ) == hir_id)
170+ . map ( |index| ( index, seg) ) . or_else ( || args. bindings
167171 . iter ( )
168- . filter ( |arg| arg. is_ty_or_const ( ) )
169- . position ( |arg| arg. id ( ) == hir_id)
170- . map ( |index| ( index, seg) )
171- } ) ;
172-
173- // FIXME(associated_const_generics): can we blend this with iteration above?
174- let ( arg_index, segment) = match filtered {
175- None => {
176- let binding_filtered = path. segments . iter ( ) . find_map ( |seg| {
177- seg. args ?
178- . bindings
179- . iter ( )
180- . filter_map ( TypeBinding :: opt_const)
181- . position ( |ct| ct. hir_id == hir_id)
182- . map ( |idx| ( idx, seg) )
183- } ) ;
184- match binding_filtered {
185- Some ( inner) => inner,
186- None => {
187- tcx. sess . delay_span_bug (
188- tcx. def_span ( def_id) ,
189- "no arg matching AnonConst in path" ,
190- ) ;
191- return None ;
192- }
193- }
194- }
195- Some ( inner) => inner,
172+ . filter_map ( TypeBinding :: opt_const)
173+ . position ( |ct| ct. hir_id == hir_id)
174+ . map ( |idx| ( idx, seg) ) )
175+ } ) else {
176+ tcx. sess . delay_span_bug (
177+ tcx. def_span ( def_id) ,
178+ "no arg matching AnonConst in path" ,
179+ ) ;
180+ return None ;
196181 } ;
197182
198183 // Try to use the segment resolution if it is valid, otherwise we
0 commit comments