@@ -5,14 +5,14 @@ use std::ops::ControlFlow;
55
66use rustc_data_structures:: fx:: FxHashSet ;
77use rustc_errors:: codes:: * ;
8- use rustc_errors:: { Applicability , MultiSpan , pluralize, struct_span_code_err} ;
8+ use rustc_errors:: { Applicability , Diag , MultiSpan , pluralize, struct_span_code_err} ;
99use rustc_hir as hir;
1010use rustc_hir:: def:: { DefKind , Res } ;
1111use rustc_middle:: dep_graph:: DepKind ;
1212use rustc_middle:: queries:: QueryVTables ;
1313use rustc_middle:: query:: CycleError ;
1414use rustc_middle:: query:: erase:: erase_val;
15- use rustc_middle:: ty:: layout:: { LayoutError , TyAndLayout } ;
15+ use rustc_middle:: ty:: layout:: LayoutError ;
1616use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1717use rustc_middle:: { bug, span_bug} ;
1818use rustc_span:: def_id:: { DefId , LocalDefId } ;
@@ -21,37 +21,45 @@ use rustc_span::{ErrorGuaranteed, Span};
2121use crate :: job:: report_cycle;
2222
2323pub ( crate ) fn specialize_query_vtables < ' tcx > ( vtables : & mut QueryVTables < ' tcx > ) {
24- vtables. type_of . value_from_cycle_error =
25- |tcx, _, _, guar| erase_val ( ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, guar) ) ) ;
24+ vtables. type_of . value_from_cycle_error = |tcx, _, _, err| {
25+ let guar = err. emit ( ) ;
26+ erase_val ( ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, guar) ) )
27+ } ;
2628
27- vtables. type_of_opaque_hir_typeck . value_from_cycle_error =
28- |tcx, _, _, guar| erase_val ( ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, guar) ) ) ;
29+ vtables. type_of_opaque_hir_typeck . value_from_cycle_error = |tcx, _, _, err| {
30+ let guar = err. emit ( ) ;
31+ erase_val ( ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, guar) ) )
32+ } ;
2933
30- vtables. erase_and_anonymize_regions_ty . value_from_cycle_error =
31- |tcx, _, _, guar| erase_val ( Ty :: new_error ( tcx, guar) ) ;
34+ vtables. erase_and_anonymize_regions_ty . value_from_cycle_error = |tcx, _, _, err| {
35+ let guar = err. emit ( ) ;
36+ erase_val ( Ty :: new_error ( tcx, guar) )
37+ } ;
3238
33- vtables. fn_sig . value_from_cycle_error = |tcx, key, _, guar| erase_val ( fn_sig ( tcx, key, guar) ) ;
39+ vtables. fn_sig . value_from_cycle_error = |tcx, key, _, err| {
40+ let guar = err. delay_as_bug ( ) ;
41+ erase_val ( fn_sig ( tcx, key, guar) )
42+ } ;
3443
3544 vtables. check_representability . value_from_cycle_error =
36- |tcx, _, cycle, guar | check_representability ( tcx, cycle, guar ) ;
45+ |tcx, _, cycle, _err | check_representability ( tcx, cycle) ;
3746
3847 vtables. check_representability_adt_ty . value_from_cycle_error =
39- |tcx, _, cycle, guar | check_representability ( tcx, cycle, guar ) ;
48+ |tcx, _, cycle, _err | check_representability ( tcx, cycle) ;
4049
41- vtables. variances_of . value_from_cycle_error =
42- |tcx, _, cycle, guar| erase_val ( variances_of ( tcx, cycle, guar) ) ;
50+ vtables. variances_of . value_from_cycle_error = |tcx, _, cycle, err| {
51+ let _guar = err. delay_as_bug ( ) ;
52+ erase_val ( variances_of ( tcx, cycle) )
53+ } ;
4354
44- vtables. layout_of . value_from_cycle_error =
45- |tcx, _, cycle, guar| erase_val ( layout_of ( tcx, cycle, guar) ) ;
55+ vtables. layout_of . value_from_cycle_error = |tcx, _, cycle, err| {
56+ let _guar = err. delay_as_bug ( ) ;
57+ erase_val ( Err ( layout_of ( tcx, cycle) ) )
58+ }
4659}
4760
48- pub ( crate ) fn default < ' tcx > ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError , query_name : & str ) -> ! {
49- let Some ( guar) = tcx. sess . dcx ( ) . has_errors ( ) else {
50- bug ! (
51- "`from_cycle_error_default` on query `{query_name}` called without errors: {:#?}" ,
52- cycle_error. cycle,
53- ) ;
54- } ;
61+ pub ( crate ) fn default ( err : Diag < ' _ > ) -> ! {
62+ let guar = err. emit ( ) ;
5563 guar. raise_fatal ( )
5664}
5765
@@ -80,11 +88,7 @@ fn fn_sig<'tcx>(
8088 ) ) )
8189}
8290
83- fn check_representability < ' tcx > (
84- tcx : TyCtxt < ' tcx > ,
85- cycle_error : CycleError ,
86- _guar : ErrorGuaranteed ,
87- ) -> ! {
91+ fn check_representability < ' tcx > ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError ) -> ! {
8892 let mut item_and_field_ids = Vec :: new ( ) ;
8993 let mut representable_ids = FxHashSet :: default ( ) ;
9094 for info in & cycle_error. cycle {
@@ -116,11 +120,7 @@ fn check_representability<'tcx>(
116120 guar. raise_fatal ( )
117121}
118122
119- fn variances_of < ' tcx > (
120- tcx : TyCtxt < ' tcx > ,
121- cycle_error : CycleError ,
122- _guar : ErrorGuaranteed ,
123- ) -> & ' tcx [ ty:: Variance ] {
123+ fn variances_of < ' tcx > ( tcx : TyCtxt < ' tcx > , cycle_error : CycleError ) -> & ' tcx [ ty:: Variance ] {
124124 search_for_cycle_permutation (
125125 & cycle_error. cycle ,
126126 |cycle| {
@@ -165,8 +165,7 @@ fn search_for_cycle_permutation<Q, T>(
165165fn layout_of < ' tcx > (
166166 tcx : TyCtxt < ' tcx > ,
167167 cycle_error : CycleError ,
168- _guar : ErrorGuaranteed ,
169- ) -> Result < TyAndLayout < ' tcx > , & ' tcx ty:: layout:: LayoutError < ' tcx > > {
168+ ) -> & ' tcx ty:: layout:: LayoutError < ' tcx > {
170169 let diag = search_for_cycle_permutation (
171170 & cycle_error. cycle ,
172171 |cycle| {
@@ -243,7 +242,7 @@ fn layout_of<'tcx>(
243242 ) ;
244243
245244 let guar = diag. emit ( ) ;
246- Err ( tcx. arena . alloc ( LayoutError :: Cycle ( guar) ) )
245+ tcx. arena . alloc ( LayoutError :: Cycle ( guar) )
247246}
248247
249248// item_and_field_ids should form a cycle where each field contains the
0 commit comments