@@ -235,38 +235,40 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
235235 } ;
236236
237237 if let Some ( path) = path {
238- let arg_index = path
238+ // We've encountered an `AnonConst` in some path, so we need to
239+ // figure out which generic parameter it corresponds to and return
240+ // the relevant type.
241+
242+ let ( arg_index, segment) = path
239243 . segments
240244 . iter ( )
241- . filter_map ( |seg| seg. args . as_ref ( ) )
242- . map ( |generic_args| generic_args. args )
243- . find_map ( |args| {
245+ . filter_map ( |seg| seg. args . as_ref ( ) . map ( |args| ( args. args , seg) ) )
246+ . find_map ( |( args, seg) | {
244247 args. iter ( )
245248 . filter ( |arg| arg. is_const ( ) )
246249 . enumerate ( )
247250 . filter ( |( _, arg) | arg. id ( ) == hir_id)
248- . map ( |( index, _) | index)
251+ . map ( |( index, _) | ( index, seg ) )
249252 . next ( )
250253 } )
251254 . unwrap_or_else ( || {
252255 bug ! ( "no arg matching AnonConst in path" ) ;
253256 } ) ;
254257
255- // We've encountered an `AnonConst` in some path, so we need to
256- // figure out which generic parameter it corresponds to and return
257- // the relevant type.
258- let generics = match path. res {
259- Res :: Def ( DefKind :: Ctor ( ..) , def_id)
260- | Res :: Def ( DefKind :: AssocTy , def_id) => {
258+ // Try to use the segment resolution if it is valid, otherwise we
259+ // default to the path resolution.
260+ let res = segment. res . filter ( |& r| r != Res :: Err ) . unwrap_or ( path. res ) ;
261+ let generics = match res {
262+ Res :: Def ( DefKind :: Ctor ( ..) , def_id) => {
261263 tcx. generics_of ( tcx. parent ( def_id) . unwrap ( ) )
262264 }
263265 Res :: Def ( _, def_id) => tcx. generics_of ( def_id) ,
264266 res => {
265267 tcx. sess . delay_span_bug (
266268 DUMMY_SP ,
267269 & format ! (
268- "unexpected const parent path def, parent: {:?}, def : {:?}" ,
269- parent_node , res
270+ "unexpected anon const res {:?} in path : {:?}" ,
271+ res , path ,
270272 ) ,
271273 ) ;
272274 return tcx. types . err ;
@@ -291,8 +293,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
291293 tcx. sess . delay_span_bug (
292294 DUMMY_SP ,
293295 & format ! (
294- "missing generic parameter for `AnonConst`, parent {:?}" ,
295- parent_node
296+ "missing generic parameter for `AnonConst`, parent: {:?}, res: {:?}" ,
297+ parent_node, res
296298 ) ,
297299 ) ;
298300 tcx. types . err
0 commit comments