@@ -433,29 +433,37 @@ pub(super) fn thir_abstract_const<'tcx>(
433
433
tcx : TyCtxt < ' tcx > ,
434
434
def : ty:: WithOptConstParam < LocalDefId > ,
435
435
) -> Result < Option < & ' tcx [ thir:: abstract_const:: Node < ' tcx > ] > , ErrorReported > {
436
- if tcx. features ( ) . generic_const_exprs {
437
- match tcx. def_kind ( def. did ) {
438
- // FIXME(generic_const_exprs): We currently only do this for anonymous constants,
439
- // meaning that we do not look into associated constants. I(@lcnr) am not yet sure whether
440
- // we want to look into them or treat them as opaque projections.
441
- //
442
- // Right now we do neither of that and simply always fail to unify them.
443
- DefKind :: AnonConst => ( ) ,
444
- _ => return Ok ( None ) ,
445
- }
436
+ if tcx. lazy_normalization ( ) == false {
437
+ return Ok ( None ) ;
438
+ }
446
439
447
- let body = tcx. thir_body ( def) ;
448
- if body. 0 . borrow ( ) . exprs . is_empty ( ) {
449
- // type error in constant, there is no thir
450
- return Err ( ErrorReported ) ;
451
- }
440
+ match tcx. def_kind ( def. did ) {
441
+ // FIXME(generic_const_exprs): We currently only do this for anonymous constants,
442
+ // meaning that we do not look into associated constants. I(@lcnr) am not yet sure whether
443
+ // we want to look into them or treat them as opaque projections.
444
+ //
445
+ // Right now we do neither of that and simply always fail to unify them.
446
+ DefKind :: AnonConst => ( ) ,
447
+ _ => return Ok ( None ) ,
448
+ }
449
+ debug ! ( "thir_abstract_const: def={:?}" , def. did) ;
450
+
451
+ // If the anon const is a fully qualified assoc const i.e. `{ <T as Trait<U>>::ASSOC }`
452
+ // we lower it to an abstract const without typeck'ing which helps to avoid cycles when
453
+ // equating consts in where clauses
454
+ if let Some ( opt_unevaluated) = tcx. abstract_const_from_fully_qualif_assoc ( def) {
455
+ return Ok ( opt_unevaluated) ;
456
+ }
452
457
453
- AbstractConstBuilder :: new ( tcx, ( & * body. 0 . borrow ( ) , body. 1 ) ) ?
454
- . map ( AbstractConstBuilder :: build)
455
- . transpose ( )
456
- } else {
457
- Ok ( None )
458
+ let body = tcx. thir_body ( def) ;
459
+ if body. 0 . borrow ( ) . exprs . is_empty ( ) {
460
+ // type error in constant, there is no thir
461
+ return Err ( ErrorReported ) ;
458
462
}
463
+
464
+ AbstractConstBuilder :: new ( tcx, ( & * body. 0 . borrow ( ) , body. 1 ) ) ?
465
+ . map ( AbstractConstBuilder :: build)
466
+ . transpose ( )
459
467
}
460
468
461
469
pub ( super ) fn try_unify_abstract_consts < ' tcx > (
0 commit comments