@@ -454,15 +454,16 @@ pub fn print_query_stack<'tcx>(
454454pub ( crate ) fn create_cycle_error < ' tcx > (
455455 tcx : TyCtxt < ' tcx > ,
456456 Cycle { usage, frames } : & Cycle < ' tcx > ,
457+ nested : bool ,
457458) -> Diag < ' tcx > {
458459 assert ! ( !frames. is_empty( ) ) ;
459460
460- let span = frames[ 0 ] . tagged_key . default_span ( tcx, frames[ 1 % frames. len ( ) ] . span ) ;
461+ let span = frames[ 0 ] . tagged_key . catch_default_span ( tcx, frames[ 1 % frames. len ( ) ] . span ) ;
461462
462463 let mut cycle_stack = Vec :: new ( ) ;
463464
464465 use crate :: error:: StackCount ;
465- let stack_bottom = frames[ 0 ] . tagged_key . description ( tcx) ;
466+ let stack_bottom = frames[ 0 ] . tagged_key . catch_description ( tcx) ;
466467 let stack_count = if frames. len ( ) == 1 {
467468 StackCount :: Single { stack_bottom : stack_bottom. clone ( ) }
468469 } else {
@@ -471,14 +472,14 @@ pub(crate) fn create_cycle_error<'tcx>(
471472
472473 for i in 1 ..frames. len ( ) {
473474 let frame = & frames[ i] ;
474- let span = frame. tagged_key . default_span ( tcx, frames[ ( i + 1 ) % frames. len ( ) ] . span ) ;
475+ let span = frame. tagged_key . catch_default_span ( tcx, frames[ ( i + 1 ) % frames. len ( ) ] . span ) ;
475476 cycle_stack
476- . push ( crate :: error:: CycleStack { span, desc : frame. tagged_key . description ( tcx) } ) ;
477+ . push ( crate :: error:: CycleStack { span, desc : frame. tagged_key . catch_description ( tcx) } ) ;
477478 }
478479
479480 let cycle_usage = usage. as_ref ( ) . map ( |usage| crate :: error:: CycleUsage {
480- span : usage. tagged_key . default_span ( tcx, usage. span ) ,
481- usage : usage. tagged_key . description ( tcx) ,
481+ span : usage. tagged_key . catch_default_span ( tcx, usage. span ) ,
482+ usage : usage. tagged_key . catch_description ( tcx) ,
482483 } ) ;
483484
484485 let is_all_def_kind = |def_kind| {
@@ -495,23 +496,36 @@ pub(crate) fn create_cycle_error<'tcx>(
495496 } )
496497 } ;
497498
498- let alias = if is_all_def_kind ( DefKind :: TyAlias ) {
499- Some ( crate :: error:: Alias :: Ty )
500- } else if is_all_def_kind ( DefKind :: TraitAlias ) {
501- Some ( crate :: error:: Alias :: Trait )
499+ let alias = if !nested {
500+ if is_all_def_kind ( DefKind :: TyAlias ) {
501+ Some ( crate :: error:: Alias :: Ty )
502+ } else if is_all_def_kind ( DefKind :: TraitAlias ) {
503+ Some ( crate :: error:: Alias :: Trait )
504+ } else {
505+ None
506+ }
502507 } else {
503508 None
504509 } ;
505510
506- let cycle_diag = crate :: error:: Cycle {
507- span,
508- cycle_stack,
509- stack_bottom,
510- alias,
511- cycle_usage,
512- stack_count,
513- note_span : ( ) ,
514- } ;
515-
516- tcx. sess . dcx ( ) . create_err ( cycle_diag)
511+ if nested {
512+ tcx. sess . dcx ( ) . create_err ( crate :: error:: NestedCycle {
513+ span,
514+ cycle_stack,
515+ stack_bottom : crate :: error:: NestedCycleBottom { stack_bottom } ,
516+ cycle_usage,
517+ stack_count,
518+ note_span : ( ) ,
519+ } )
520+ } else {
521+ tcx. sess . dcx ( ) . create_err ( crate :: error:: Cycle {
522+ span,
523+ cycle_stack,
524+ stack_bottom,
525+ alias,
526+ cycle_usage,
527+ stack_count,
528+ note_span : ( ) ,
529+ } )
530+ }
517531}
0 commit comments