@@ -9,48 +9,29 @@ use rustc_errors::{Applicability, Diag, MultiSpan, pluralize, struct_span_code_e
99use rustc_hir as hir;
1010use rustc_hir:: def:: { DefKind , Res } ;
1111use rustc_middle:: bug;
12- use rustc_middle:: queries:: { QueryVTables , TaggedQueryKey } ;
12+ use rustc_middle:: queries:: TaggedQueryKey ;
1313use rustc_middle:: query:: Cycle ;
14- use rustc_middle:: query:: erase:: erase_val;
1514use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1615use rustc_span:: def_id:: { DefId , LocalDefId } ;
1716use rustc_span:: { ErrorGuaranteed , Span } ;
1817
1918use crate :: job:: create_cycle_error;
2019
21- pub ( crate ) fn specialize_query_vtables < ' tcx > ( vtables : & mut QueryVTables < ' tcx > ) {
22- vtables. fn_sig . handle_cycle_error_fn = |tcx, key, _, err| {
23- let guar = err. delay_as_bug ( ) ;
24- erase_val ( fn_sig ( tcx, key, guar) )
25- } ;
26-
27- vtables. check_representability . handle_cycle_error_fn =
28- |tcx, _, cycle, _err| check_representability ( tcx, cycle) ;
29-
30- vtables. check_representability_adt_ty . handle_cycle_error_fn =
31- |tcx, _, cycle, _err| check_representability ( tcx, cycle) ;
32-
33- vtables. variances_of . handle_cycle_error_fn = |tcx, key, _, err| {
34- let _guar = err. delay_as_bug ( ) ;
35- erase_val ( variances_of ( tcx, key) )
36- } ;
37-
38- vtables. layout_of . handle_cycle_error_fn = |tcx, _, cycle, err| {
39- let _guar = err. delay_as_bug ( ) ;
40- erase_val ( Err ( layout_of ( tcx, cycle) ) )
41- }
42- }
43-
20+ // Default cycle handler used for all queries that don't use the `handle_cycle_error` query
21+ // modifier.
4422pub ( crate ) fn default ( err : Diag < ' _ > ) -> ! {
4523 let guar = err. emit ( ) ;
4624 guar. raise_fatal ( )
4725}
4826
49- fn fn_sig < ' tcx > (
27+ pub ( crate ) fn fn_sig < ' tcx > (
5028 tcx : TyCtxt < ' tcx > ,
5129 def_id : DefId ,
52- guar : ErrorGuaranteed ,
30+ _: Cycle < ' tcx > ,
31+ err : Diag < ' _ > ,
5332) -> ty:: EarlyBinder < ' tcx , ty:: PolyFnSig < ' tcx > > {
33+ let guar = err. delay_as_bug ( ) ;
34+
5435 let err = Ty :: new_error ( tcx, guar) ;
5536
5637 let arity = if let Some ( node) = tcx. hir_get_if_local ( def_id)
@@ -71,7 +52,25 @@ fn fn_sig<'tcx>(
7152 ) ) )
7253}
7354
74- fn check_representability < ' tcx > ( tcx : TyCtxt < ' tcx > , cycle : Cycle < ' tcx > ) -> ! {
55+ pub ( crate ) fn check_representability < ' tcx > (
56+ tcx : TyCtxt < ' tcx > ,
57+ _key : LocalDefId ,
58+ cycle : Cycle < ' tcx > ,
59+ _err : Diag < ' _ > ,
60+ ) {
61+ check_representability_inner ( tcx, cycle) ;
62+ }
63+
64+ pub ( crate ) fn check_representability_adt_ty < ' tcx > (
65+ tcx : TyCtxt < ' tcx > ,
66+ _key : Ty < ' tcx > ,
67+ cycle : Cycle < ' tcx > ,
68+ _err : Diag < ' _ > ,
69+ ) {
70+ check_representability_inner ( tcx, cycle) ;
71+ }
72+
73+ fn check_representability_inner < ' tcx > ( tcx : TyCtxt < ' tcx > , cycle : Cycle < ' tcx > ) -> ! {
7574 let mut item_and_field_ids = Vec :: new ( ) ;
7675 let mut representable_ids = FxHashSet :: default ( ) ;
7776 for frame in & cycle. frames {
@@ -102,7 +101,13 @@ fn check_representability<'tcx>(tcx: TyCtxt<'tcx>, cycle: Cycle<'tcx>) -> ! {
102101 guar. raise_fatal ( )
103102}
104103
105- fn variances_of < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> & ' tcx [ ty:: Variance ] {
104+ pub ( crate ) fn variances_of < ' tcx > (
105+ tcx : TyCtxt < ' tcx > ,
106+ def_id : DefId ,
107+ _cycle : Cycle < ' tcx > ,
108+ err : Diag < ' _ > ,
109+ ) -> & ' tcx [ ty:: Variance ] {
110+ let _guar = err. delay_as_bug ( ) ;
106111 let n = tcx. generics_of ( def_id) . own_params . len ( ) ;
107112 tcx. arena . alloc_from_iter ( iter:: repeat_n ( ty:: Bivariant , n) )
108113}
@@ -126,7 +131,13 @@ fn search_for_cycle_permutation<Q, T>(
126131 otherwise ( )
127132}
128133
129- fn layout_of < ' tcx > ( tcx : TyCtxt < ' tcx > , cycle : Cycle < ' tcx > ) -> & ' tcx ty:: layout:: LayoutError < ' tcx > {
134+ pub ( crate ) fn layout_of < ' tcx > (
135+ tcx : TyCtxt < ' tcx > ,
136+ _key : ty:: PseudoCanonicalInput < ' tcx , Ty < ' tcx > > ,
137+ cycle : Cycle < ' tcx > ,
138+ err : Diag < ' _ > ,
139+ ) -> Result < ty:: layout:: TyAndLayout < ' tcx > , & ' tcx ty:: layout:: LayoutError < ' tcx > > {
140+ let _guar = err. delay_as_bug ( ) ;
130141 let diag = search_for_cycle_permutation (
131142 & cycle. frames ,
132143 |frames| {
0 commit comments