@@ -278,8 +278,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
278
278
}
279
279
TraitItemKind :: Const ( ty, body_id) => body_id
280
280
. and_then ( |body_id| {
281
- is_suggestable_infer_ty ( ty)
282
- . then ( || infer_placeholder_type ( tcx, def_id, body_id, ty. span , item. ident , "constant" , ) )
281
+ is_suggestable_infer_ty ( ty) . then ( || {
282
+ infer_placeholder_type (
283
+ tcx, def_id, body_id, ty. span , item. ident , "constant" ,
284
+ )
285
+ } )
283
286
} )
284
287
. unwrap_or_else ( || icx. to_ty ( ty) ) ,
285
288
TraitItemKind :: Type ( _, Some ( ty) ) => icx. to_ty ( ty) ,
@@ -335,14 +338,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
335
338
}
336
339
}
337
340
ItemKind :: TyAlias ( self_ty, _) => icx. to_ty ( self_ty) ,
338
- ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) => {
339
- match self_ty . find_self_aliases ( ) {
340
- spans if spans . len ( ) > 0 => {
341
- let guar = tcx . sess . emit_err ( crate :: errors :: SelfInImplSelf { span : spans. into ( ) , note : ( ) } ) ;
342
- tcx . ty_error ( guar )
343
- } ,
344
- _ => icx . to_ty ( * self_ty ) ,
341
+ ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) => match self_ty . find_self_aliases ( ) {
342
+ spans if spans . len ( ) > 0 => {
343
+ let guar = tcx . sess . emit_err ( crate :: errors :: SelfInImplSelf {
344
+ span : spans. into ( ) ,
345
+ note : ( ) ,
346
+ } ) ;
347
+ tcx . ty_error ( guar )
345
348
}
349
+ _ => icx. to_ty ( * self_ty) ,
346
350
} ,
347
351
ItemKind :: Fn ( ..) => {
348
352
let substs = InternalSubsts :: identity_for_item ( tcx, def_id. to_def_id ( ) ) ;
@@ -364,7 +368,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
364
368
..
365
369
} ) => {
366
370
if in_trait && !tcx. impl_defaultness ( owner) . has_value ( ) {
367
- span_bug ! ( tcx. def_span( def_id) , "tried to get type of this RPITIT with no definition" ) ;
371
+ span_bug ! (
372
+ tcx. def_span( def_id) ,
373
+ "tried to get type of this RPITIT with no definition"
374
+ ) ;
368
375
}
369
376
find_opaque_ty_constraints_for_rpit ( tcx, def_id, owner)
370
377
}
@@ -453,15 +460,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
453
460
tcx. adt_def ( tcx. hir ( ) . get_parent_item ( hir_id) ) . repr ( ) . discr_type ( ) . to_ty ( tcx)
454
461
}
455
462
456
- Node :: TypeBinding (
457
- TypeBinding {
458
- hir_id : binding_id,
459
- kind : TypeBindingKind :: Equality { term : Term :: Const ( e) } ,
460
- ident,
461
- ..
462
- } ,
463
- ) if let Node :: TraitRef ( trait_ref) =
464
- tcx. hir ( ) . get_parent ( * binding_id)
463
+ Node :: TypeBinding ( TypeBinding {
464
+ hir_id : binding_id,
465
+ kind : TypeBindingKind :: Equality { term : Term :: Const ( e) } ,
466
+ ident,
467
+ ..
468
+ } ) if let Node :: TraitRef ( trait_ref) = tcx. hir ( ) . get_parent ( * binding_id)
465
469
&& e. hir_id == hir_id =>
466
470
{
467
471
let Some ( trait_def_id) = trait_ref. trait_def_id ( ) else {
@@ -475,7 +479,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
475
479
def_id. to_def_id ( ) ,
476
480
) ;
477
481
if let Some ( assoc_item) = assoc_item {
478
- tcx. type_of ( assoc_item. def_id ) . subst_identity ( )
482
+ tcx. type_of ( assoc_item. def_id )
483
+ . no_bound_vars ( )
484
+ . expect ( "const parameter types cannot be generic" )
479
485
} else {
480
486
// FIXME(associated_const_equality): add a useful error message here.
481
487
tcx. ty_error_with_message (
@@ -485,10 +491,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
485
491
}
486
492
}
487
493
488
- Node :: TypeBinding (
489
- TypeBinding { hir_id : binding_id, gen_args, kind, ident, .. } ,
490
- ) if let Node :: TraitRef ( trait_ref) =
491
- tcx. hir ( ) . get_parent ( * binding_id)
494
+ Node :: TypeBinding ( TypeBinding {
495
+ hir_id : binding_id,
496
+ gen_args,
497
+ kind,
498
+ ident,
499
+ ..
500
+ } ) if let Node :: TraitRef ( trait_ref) = tcx. hir ( ) . get_parent ( * binding_id)
492
501
&& let Some ( ( idx, _) ) =
493
502
gen_args. args . iter ( ) . enumerate ( ) . find ( |( _, arg) | {
494
503
if let GenericArg :: Const ( ct) = arg {
@@ -517,15 +526,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
517
526
} ,
518
527
def_id. to_def_id ( ) ,
519
528
) ;
520
- if let Some ( param)
521
- = assoc_item. map ( |item| & tcx. generics_of ( item. def_id ) . params [ idx] ) . filter ( |param| param. kind . is_ty_or_const ( ) )
529
+ if let Some ( assoc_item) = assoc_item
530
+ && let param = & tcx. generics_of ( assoc_item. def_id ) . params [ idx]
531
+ && matches ! ( param. kind, ty:: GenericParamDefKind :: Const { .. } )
522
532
{
523
- tcx. type_of ( param. def_id ) . subst_identity ( )
533
+ tcx. type_of ( param. def_id )
534
+ . no_bound_vars ( )
535
+ . expect ( "const parameter types cannot be generic" )
524
536
} else {
525
537
// FIXME(associated_const_equality): add a useful error message here.
526
538
tcx. ty_error_with_message (
527
539
DUMMY_SP ,
528
- "Could not find associated const on trait " ,
540
+ "Could not find const param on associated item " ,
529
541
)
530
542
}
531
543
}
0 commit comments