@@ -2,7 +2,7 @@ use crate::infer::canonical::{
2
2
Canonical , CanonicalQueryResponse , OriginalQueryValues , QueryRegionConstraints ,
3
3
} ;
4
4
use crate :: infer:: { InferCtxt , InferOk } ;
5
- use crate :: traits:: ObligationCause ;
5
+ use crate :: traits:: { ObligationCause , ObligationCtxt } ;
6
6
use rustc_errors:: ErrorGuaranteed ;
7
7
use rustc_infer:: infer:: canonical:: Certainty ;
8
8
use rustc_infer:: traits:: PredicateObligations ;
@@ -23,6 +23,8 @@ pub mod subtype;
23
23
24
24
pub use rustc_middle:: traits:: query:: type_op:: * ;
25
25
26
+ use self :: custom:: scrape_region_constraints;
27
+
26
28
/// "Type ops" are used in NLL to perform some particular action and
27
29
/// extract out the resulting region constraints (or an error if it
28
30
/// cannot be completed).
@@ -81,6 +83,17 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Copy + TypeFoldable<TyCtxt<'tcx>> + 't
81
83
canonicalized : Canonical < ' tcx , ParamEnvAnd < ' tcx , Self > > ,
82
84
) -> Result < CanonicalQueryResponse < ' tcx , Self :: QueryResponse > , NoSolution > ;
83
85
86
+ /// In the new trait solver, we already do caching in the solver itself,
87
+ /// so there's no need to canonicalize and cache via the query system.
88
+ /// Additionally, even if we were to canonicalize, we'd still need to
89
+ /// make sure to feed it predefined opaque types and the defining anchor
90
+ /// and that would require duplicating all of the tcx queries. Instead,
91
+ /// just perform these ops locally.
92
+ fn perform_locally_in_new_solver (
93
+ ocx : & ObligationCtxt < ' _ , ' tcx > ,
94
+ key : ParamEnvAnd < ' tcx , Self > ,
95
+ ) -> Result < Self :: QueryResponse , NoSolution > ;
96
+
84
97
fn fully_perform_into (
85
98
query_key : ParamEnvAnd < ' tcx , Self > ,
86
99
infcx : & InferCtxt < ' tcx > ,
@@ -133,6 +146,16 @@ where
133
146
infcx : & InferCtxt < ' tcx > ,
134
147
span : Span ,
135
148
) -> Result < TypeOpOutput < ' tcx , Self > , ErrorGuaranteed > {
149
+ if infcx. tcx . trait_solver_next ( ) {
150
+ return Ok ( scrape_region_constraints (
151
+ infcx,
152
+ |ocx| QueryTypeOp :: perform_locally_in_new_solver ( ocx, self ) ,
153
+ "query type op" ,
154
+ span,
155
+ ) ?
156
+ . 0 ) ;
157
+ }
158
+
136
159
let mut region_constraints = QueryRegionConstraints :: default ( ) ;
137
160
let ( output, error_info, mut obligations, _) =
138
161
Q :: fully_perform_into ( self , infcx, & mut region_constraints) . map_err ( |_| {
0 commit comments