@@ -235,38 +235,40 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
235
235
} ;
236
236
237
237
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
239
243
. segments
240
244
. 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) | {
244
247
args. iter ( )
245
248
. filter ( |arg| arg. is_const ( ) )
246
249
. enumerate ( )
247
250
. filter ( |( _, arg) | arg. id ( ) == hir_id)
248
- . map ( |( index, _) | index)
251
+ . map ( |( index, _) | ( index, seg ) )
249
252
. next ( )
250
253
} )
251
254
. unwrap_or_else ( || {
252
255
bug ! ( "no arg matching AnonConst in path" ) ;
253
256
} ) ;
254
257
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) => {
261
263
tcx. generics_of ( tcx. parent ( def_id) . unwrap ( ) )
262
264
}
263
265
Res :: Def ( _, def_id) => tcx. generics_of ( def_id) ,
264
266
res => {
265
267
tcx. sess . delay_span_bug (
266
268
DUMMY_SP ,
267
269
& format ! (
268
- "unexpected const parent path def, parent: {:?}, def : {:?}" ,
269
- parent_node , res
270
+ "unexpected anon const res {:?} in path : {:?}" ,
271
+ res , path ,
270
272
) ,
271
273
) ;
272
274
return tcx. types . err ;
@@ -291,8 +293,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
291
293
tcx. sess . delay_span_bug (
292
294
DUMMY_SP ,
293
295
& format ! (
294
- "missing generic parameter for `AnonConst`, parent {:?}" ,
295
- parent_node
296
+ "missing generic parameter for `AnonConst`, parent: {:?}, res: {:?}" ,
297
+ parent_node, res
296
298
) ,
297
299
) ;
298
300
tcx. types . err
0 commit comments