@@ -12,7 +12,7 @@ use rustc_middle::query::CycleError;
1212use rustc_middle:: query:: plumbing:: CyclePlaceholder ;
1313use rustc_middle:: ty:: { self , Representability , Ty , TyCtxt } ;
1414use rustc_middle:: { bug, span_bug} ;
15- use rustc_span:: def_id:: LocalDefId ;
15+ use rustc_span:: def_id:: { DefId , LocalDefId } ;
1616use rustc_span:: { ErrorGuaranteed , Span } ;
1717
1818use crate :: job:: report_cycle;
@@ -22,14 +22,15 @@ pub(crate) trait FromCycleError<'tcx>: Sized {
2222 ///
2323 /// Note: the default impl calls `raise_fatal`, ending compilation immediately! Only a few
2424 /// types override this with a non-fatal impl.
25- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self ;
25+ fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed , key_def_id : Option < DefId > ) -> Self ;
2626}
2727
2828impl < ' tcx , T > FromCycleError < ' tcx > for T {
2929 default fn from_cycle_error (
3030 tcx : TyCtxt < ' tcx > ,
3131 cycle_error : CycleError ,
3232 _guar : ErrorGuaranteed ,
33+ _key_def_id : Option < DefId > ,
3334 ) -> T {
3435 let Some ( guar) = tcx. sess . dcx ( ) . has_errors ( ) else {
3536 bug ! (
@@ -43,26 +44,24 @@ impl<'tcx, T> FromCycleError<'tcx> for T {
4344}
4445
4546impl < ' tcx > FromCycleError < ' tcx > for Ty < ' _ > {
46- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed ) -> Self {
47+ fn from_cycle_error ( tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed , _key_def_id : Option < DefId > ) -> Self {
4748 // SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
4849 // FIXME: Represent the above fact in the trait system somehow.
4950 unsafe { std:: mem:: transmute :: < Ty < ' tcx > , Ty < ' _ > > ( Ty :: new_error ( tcx, guar) ) }
5051 }
5152}
5253
5354impl < ' tcx > FromCycleError < ' tcx > for Result < ty:: EarlyBinder < ' _ , Ty < ' _ > > , CyclePlaceholder > {
54- fn from_cycle_error ( _tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed ) -> Self {
55+ fn from_cycle_error ( _tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed , _key_def_id : Option < DefId > ) -> Self {
5556 Err ( CyclePlaceholder ( guar) )
5657 }
5758}
5859
5960impl < ' tcx > FromCycleError < ' tcx > for ty:: Binder < ' _ , ty:: FnSig < ' _ > > {
60- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
61+ fn from_cycle_error ( tcx : TyCtxt < ' tcx > , _cycle_error : CycleError , guar : ErrorGuaranteed , key_def_id : Option < DefId > ) -> Self {
6162 let err = Ty :: new_error ( tcx, guar) ;
6263
63- let arity = if let Some ( info) = cycle_error. cycle . get ( 0 )
64- && info. frame . dep_kind == DepKind :: fn_sig
65- && let Some ( def_id) = info. frame . def_id
64+ let arity = if let Some ( def_id) = key_def_id
6665 && let Some ( node) = tcx. hir_get_if_local ( def_id)
6766 && let Some ( sig) = node. fn_sig ( )
6867 {
@@ -91,6 +90,7 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
9190 tcx : TyCtxt < ' tcx > ,
9291 cycle_error : CycleError ,
9392 _guar : ErrorGuaranteed ,
93+ _key_def_id : Option < DefId > ,
9494 ) -> Self {
9595 let mut item_and_field_ids = Vec :: new ( ) ;
9696 let mut representable_ids = FxHashSet :: default ( ) ;
@@ -125,14 +125,14 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
125125}
126126
127127impl < ' tcx > FromCycleError < ' tcx > for ty:: EarlyBinder < ' _ , Ty < ' _ > > {
128- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
129- ty:: EarlyBinder :: bind ( Ty :: from_cycle_error ( tcx, cycle_error, guar) )
128+ fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed , key_def_id : Option < DefId > ) -> Self {
129+ ty:: EarlyBinder :: bind ( Ty :: from_cycle_error ( tcx, cycle_error, guar, key_def_id ) )
130130 }
131131}
132132
133133impl < ' tcx > FromCycleError < ' tcx > for ty:: EarlyBinder < ' _ , ty:: Binder < ' _ , ty:: FnSig < ' _ > > > {
134- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
135- ty:: EarlyBinder :: bind ( ty:: Binder :: from_cycle_error ( tcx, cycle_error, guar) )
134+ fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed , key_def_id : Option < DefId > ) -> Self {
135+ ty:: EarlyBinder :: bind ( ty:: Binder :: from_cycle_error ( tcx, cycle_error, guar, key_def_id ) )
136136 }
137137}
138138
@@ -141,6 +141,7 @@ impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] {
141141 tcx : TyCtxt < ' tcx > ,
142142 cycle_error : CycleError ,
143143 _guar : ErrorGuaranteed ,
144+ _key_def_id : Option < DefId > ,
144145 ) -> Self {
145146 search_for_cycle_permutation (
146147 & cycle_error. cycle ,
@@ -189,6 +190,7 @@ impl<'tcx, T> FromCycleError<'tcx> for Result<T, &'_ ty::layout::LayoutError<'_>
189190 tcx : TyCtxt < ' tcx > ,
190191 cycle_error : CycleError ,
191192 _guar : ErrorGuaranteed ,
193+ _key_def_id : Option < DefId > ,
192194 ) -> Self {
193195 let diag = search_for_cycle_permutation (
194196 & cycle_error. cycle ,
0 commit comments