@@ -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,20 @@ 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 (
26+ tcx : TyCtxt < ' tcx > ,
27+ cycle_error : CycleError ,
28+ guar : ErrorGuaranteed ,
29+ key_def_id : Option < DefId > ,
30+ ) -> Self ;
2631}
2732
2833impl < ' tcx , T > FromCycleError < ' tcx > for T {
2934 default fn from_cycle_error (
3035 tcx : TyCtxt < ' tcx > ,
3136 cycle_error : CycleError ,
3237 _guar : ErrorGuaranteed ,
38+ _key_def_id : Option < DefId > ,
3339 ) -> T {
3440 let Some ( guar) = tcx. sess . dcx ( ) . has_errors ( ) else {
3541 bug ! (
@@ -43,26 +49,39 @@ impl<'tcx, T> FromCycleError<'tcx> for T {
4349}
4450
4551impl < ' tcx > FromCycleError < ' tcx > for Ty < ' _ > {
46- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed ) -> Self {
52+ fn from_cycle_error (
53+ tcx : TyCtxt < ' tcx > ,
54+ _: CycleError ,
55+ guar : ErrorGuaranteed ,
56+ _key_def_id : Option < DefId > ,
57+ ) -> Self {
4758 // SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
4859 // FIXME: Represent the above fact in the trait system somehow.
4960 unsafe { std:: mem:: transmute :: < Ty < ' tcx > , Ty < ' _ > > ( Ty :: new_error ( tcx, guar) ) }
5061 }
5162}
5263
5364impl < ' tcx > FromCycleError < ' tcx > for Result < ty:: EarlyBinder < ' _ , Ty < ' _ > > , CyclePlaceholder > {
54- fn from_cycle_error ( _tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed ) -> Self {
65+ fn from_cycle_error (
66+ _tcx : TyCtxt < ' tcx > ,
67+ _: CycleError ,
68+ guar : ErrorGuaranteed ,
69+ _key_def_id : Option < DefId > ,
70+ ) -> Self {
5571 Err ( CyclePlaceholder ( guar) )
5672 }
5773}
5874
5975impl < ' tcx > FromCycleError < ' tcx > for ty:: Binder < ' _ , ty:: FnSig < ' _ > > {
60- fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
76+ fn from_cycle_error (
77+ tcx : TyCtxt < ' tcx > ,
78+ _cycle_error : CycleError ,
79+ guar : ErrorGuaranteed ,
80+ key_def_id : Option < DefId > ,
81+ ) -> Self {
6182 let err = Ty :: new_error ( tcx, guar) ;
6283
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
84+ let arity = if let Some ( def_id) = key_def_id
6685 && let Some ( node) = tcx. hir_get_if_local ( def_id)
6786 && let Some ( sig) = node. fn_sig ( )
6887 {
@@ -91,6 +110,7 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
91110 tcx : TyCtxt < ' tcx > ,
92111 cycle_error : CycleError ,
93112 _guar : ErrorGuaranteed ,
113+ _key_def_id : Option < DefId > ,
94114 ) -> Self {
95115 let mut item_and_field_ids = Vec :: new ( ) ;
96116 let mut representable_ids = FxHashSet :: default ( ) ;
@@ -125,14 +145,24 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
125145}
126146
127147impl < ' 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) )
148+ fn from_cycle_error (
149+ tcx : TyCtxt < ' tcx > ,
150+ cycle_error : CycleError ,
151+ guar : ErrorGuaranteed ,
152+ key_def_id : Option < DefId > ,
153+ ) -> Self {
154+ ty:: EarlyBinder :: bind ( Ty :: from_cycle_error ( tcx, cycle_error, guar, key_def_id) )
130155 }
131156}
132157
133158impl < ' 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) )
159+ fn from_cycle_error (
160+ tcx : TyCtxt < ' tcx > ,
161+ cycle_error : CycleError ,
162+ guar : ErrorGuaranteed ,
163+ key_def_id : Option < DefId > ,
164+ ) -> Self {
165+ ty:: EarlyBinder :: bind ( ty:: Binder :: from_cycle_error ( tcx, cycle_error, guar, key_def_id) )
136166 }
137167}
138168
@@ -141,6 +171,7 @@ impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] {
141171 tcx : TyCtxt < ' tcx > ,
142172 cycle_error : CycleError ,
143173 _guar : ErrorGuaranteed ,
174+ _key_def_id : Option < DefId > ,
144175 ) -> Self {
145176 search_for_cycle_permutation (
146177 & cycle_error. cycle ,
@@ -189,6 +220,7 @@ impl<'tcx, T> FromCycleError<'tcx> for Result<T, &'_ ty::layout::LayoutError<'_>
189220 tcx : TyCtxt < ' tcx > ,
190221 cycle_error : CycleError ,
191222 _guar : ErrorGuaranteed ,
223+ _key_def_id : Option < DefId > ,
192224 ) -> Self {
193225 let diag = search_for_cycle_permutation (
194226 & cycle_error. cycle ,
0 commit comments