@@ -17,19 +17,23 @@ use rustc_span::{ErrorGuaranteed, Span};
1717
1818use crate :: job:: report_cycle;
1919
20- pub ( crate ) trait Value < ' tcx > : Sized {
20+ pub ( crate ) trait FromCycleError < ' tcx > : Sized {
21+ /// Try to produce a `Self` value that represents an error form (e.g. `TyKind::Error`).
22+ ///
23+ /// Note: the default impl calls `raise_fatal`, ending compilation immediately! Only a few
24+ /// types override this with a non-fatal impl.
2125 fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self ;
2226}
2327
24- impl < ' tcx , T > Value < ' tcx > for T {
28+ impl < ' tcx , T > FromCycleError < ' tcx > for T {
2529 default fn from_cycle_error (
2630 tcx : TyCtxt < ' tcx > ,
2731 cycle_error : CycleError ,
2832 _guar : ErrorGuaranteed ,
2933 ) -> T {
3034 let Some ( guar) = tcx. sess . dcx ( ) . has_errors ( ) else {
3135 bug ! (
32- "<{} as Value >::from_cycle_error called without errors: {:#?}" ,
36+ "<{} as FromCycleError >::from_cycle_error called without errors: {:#?}" ,
3337 std:: any:: type_name:: <T >( ) ,
3438 cycle_error. cycle,
3539 ) ;
@@ -38,21 +42,21 @@ impl<'tcx, T> Value<'tcx> for T {
3842 }
3943}
4044
41- impl < ' tcx > Value < ' tcx > for Ty < ' _ > {
45+ impl < ' tcx > FromCycleError < ' tcx > for Ty < ' _ > {
4246 fn from_cycle_error ( tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed ) -> Self {
4347 // SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
4448 // FIXME: Represent the above fact in the trait system somehow.
4549 unsafe { std:: mem:: transmute :: < Ty < ' tcx > , Ty < ' _ > > ( Ty :: new_error ( tcx, guar) ) }
4650 }
4751}
4852
49- impl < ' tcx > Value < ' tcx > for Result < ty:: EarlyBinder < ' _ , Ty < ' _ > > , CyclePlaceholder > {
53+ impl < ' tcx > FromCycleError < ' tcx > for Result < ty:: EarlyBinder < ' _ , Ty < ' _ > > , CyclePlaceholder > {
5054 fn from_cycle_error ( _tcx : TyCtxt < ' tcx > , _: CycleError , guar : ErrorGuaranteed ) -> Self {
5155 Err ( CyclePlaceholder ( guar) )
5256 }
5357}
5458
55- impl < ' tcx > Value < ' tcx > for ty:: SymbolName < ' _ > {
59+ impl < ' tcx > FromCycleError < ' tcx > for ty:: SymbolName < ' _ > {
5660 fn from_cycle_error ( tcx : TyCtxt < ' tcx > , _: CycleError , _guar : ErrorGuaranteed ) -> Self {
5761 // SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`.
5862 // FIXME: Represent the above fact in the trait system somehow.
@@ -64,7 +68,7 @@ impl<'tcx> Value<'tcx> for ty::SymbolName<'_> {
6468 }
6569}
6670
67- impl < ' tcx > Value < ' tcx > for ty:: Binder < ' _ , ty:: FnSig < ' _ > > {
71+ impl < ' tcx > FromCycleError < ' tcx > for ty:: Binder < ' _ , ty:: FnSig < ' _ > > {
6872 fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
6973 let err = Ty :: new_error ( tcx, guar) ;
7074
@@ -94,7 +98,7 @@ impl<'tcx> Value<'tcx> for ty::Binder<'_, ty::FnSig<'_>> {
9498 }
9599}
96100
97- impl < ' tcx > Value < ' tcx > for Representability {
101+ impl < ' tcx > FromCycleError < ' tcx > for Representability {
98102 fn from_cycle_error (
99103 tcx : TyCtxt < ' tcx > ,
100104 cycle_error : CycleError ,
@@ -130,19 +134,19 @@ impl<'tcx> Value<'tcx> for Representability {
130134 }
131135}
132136
133- impl < ' tcx > Value < ' tcx > for ty:: EarlyBinder < ' _ , Ty < ' _ > > {
137+ impl < ' tcx > FromCycleError < ' tcx > for ty:: EarlyBinder < ' _ , Ty < ' _ > > {
134138 fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
135139 ty:: EarlyBinder :: bind ( Ty :: from_cycle_error ( tcx, cycle_error, guar) )
136140 }
137141}
138142
139- impl < ' tcx > Value < ' tcx > for ty:: EarlyBinder < ' _ , ty:: Binder < ' _ , ty:: FnSig < ' _ > > > {
143+ impl < ' tcx > FromCycleError < ' tcx > for ty:: EarlyBinder < ' _ , ty:: Binder < ' _ , ty:: FnSig < ' _ > > > {
140144 fn from_cycle_error ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , guar : ErrorGuaranteed ) -> Self {
141145 ty:: EarlyBinder :: bind ( ty:: Binder :: from_cycle_error ( tcx, cycle_error, guar) )
142146 }
143147}
144148
145- impl < ' tcx > Value < ' tcx > for & [ ty:: Variance ] {
149+ impl < ' tcx > FromCycleError < ' tcx > for & [ ty:: Variance ] {
146150 fn from_cycle_error (
147151 tcx : TyCtxt < ' tcx > ,
148152 cycle_error : CycleError ,
@@ -190,7 +194,7 @@ fn search_for_cycle_permutation<Q, T>(
190194 otherwise ( )
191195}
192196
193- impl < ' tcx , T > Value < ' tcx > for Result < T , & ' _ ty:: layout:: LayoutError < ' _ > > {
197+ impl < ' tcx , T > FromCycleError < ' tcx > for Result < T , & ' _ ty:: layout:: LayoutError < ' _ > > {
194198 fn from_cycle_error (
195199 tcx : TyCtxt < ' tcx > ,
196200 cycle_error : CycleError ,
0 commit comments