@@ -173,6 +173,39 @@ pub fn query_ensure<'tcx, Cache>(
173
173
}
174
174
}
175
175
176
+ #[ inline]
177
+ pub fn query_ensure_error_guaranteed < ' tcx , Cache > (
178
+ tcx : TyCtxt < ' tcx > ,
179
+ execute_query : fn ( TyCtxt < ' tcx > , Span , Cache :: Key , QueryMode ) -> Option < Cache :: Value > ,
180
+ query_cache : & Cache ,
181
+ key : Cache :: Key ,
182
+ check_cache : bool ,
183
+ ) -> Result < ( ) , ErrorGuaranteed >
184
+ where
185
+ Cache : QueryCache < Value = super :: erase:: Erase < Result < ( ) , ErrorGuaranteed > > > ,
186
+ {
187
+ let key = key. into_query_param ( ) ;
188
+ if let Some ( res) = try_get_cached ( tcx, query_cache, & key) {
189
+ super :: erase:: restore ( res)
190
+ } else {
191
+ execute_query ( tcx, DUMMY_SP , key, QueryMode :: Ensure { check_cache } )
192
+ . map ( super :: erase:: restore)
193
+ . unwrap_or ( Ok ( ( ) ) )
194
+ }
195
+ }
196
+
197
+ macro_rules! query_ensure {
198
+ ( [ ] $( $args: tt) * ) => {
199
+ query_ensure( $( $args) * )
200
+ } ;
201
+ ( [ ( ensure_forwards_result_if_red) $( $rest: tt) * ] $( $args: tt) * ) => {
202
+ query_ensure_error_guaranteed( $( $args) * )
203
+ } ;
204
+ ( [ $other: tt $( $modifiers: tt) * ] $( $args: tt) * ) => {
205
+ query_ensure!( [ $( $modifiers) * ] $( $args) * )
206
+ } ;
207
+ }
208
+
176
209
macro_rules! query_helper_param_ty {
177
210
( DefId ) => { impl IntoQueryParam <DefId > } ;
178
211
( LocalDefId ) => { impl IntoQueryParam <LocalDefId > } ;
@@ -220,6 +253,18 @@ macro_rules! separate_provide_extern_decl {
220
253
} ;
221
254
}
222
255
256
+ macro_rules! ensure_result {
257
+ ( [ ] [ $ty: ty] ) => {
258
+ ( )
259
+ } ;
260
+ ( [ ( ensure_forwards_result_if_red) $( $rest: tt) * ] [ $ty: ty] ) => {
261
+ Result <( ) , ErrorGuaranteed >
262
+ } ;
263
+ ( [ $other: tt $( $modifiers: tt) * ] [ $( $args: tt) * ] ) => {
264
+ ensure_result!( [ $( $modifiers) * ] [ $( $args) * ] )
265
+ } ;
266
+ }
267
+
223
268
macro_rules! separate_provide_extern_default {
224
269
( [ ] [ $name: ident] ) => {
225
270
( )
@@ -343,14 +388,15 @@ macro_rules! define_callbacks {
343
388
impl <' tcx> TyCtxtEnsure <' tcx> {
344
389
$( $( #[ $attr] ) *
345
390
#[ inline( always) ]
346
- pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) {
347
- query_ensure(
391
+ pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) -> ensure_result!( [ $( $modifiers) * ] [ $V] ) {
392
+ query_ensure!(
393
+ [ $( $modifiers) * ]
348
394
self . tcx,
349
395
self . tcx. query_system. fns. engine. $name,
350
396
& self . tcx. query_system. caches. $name,
351
397
key. into_query_param( ) ,
352
398
false ,
353
- ) ;
399
+ )
354
400
} ) *
355
401
}
356
402
0 commit comments