@@ -3,8 +3,8 @@ use rustc_data_structures::vec_map::VecMap;
3
3
use rustc_hir:: def_id:: LocalDefId ;
4
4
use rustc_hir:: OpaqueTyOrigin ;
5
5
use rustc_infer:: infer:: error_reporting:: unexpected_hidden_region_diagnostic;
6
- use rustc_infer:: infer:: InferCtxt ;
7
6
use rustc_infer:: infer:: TyCtxtInferExt as _;
7
+ use rustc_infer:: infer:: { DefiningAnchor , InferCtxt } ;
8
8
use rustc_infer:: traits:: { Obligation , ObligationCause , TraitEngine } ;
9
9
use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
10
10
use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts } ;
@@ -269,59 +269,65 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
269
269
// FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
270
270
let param_env = self . tcx . param_env ( def_id) ;
271
271
let body_id = self . tcx . local_def_id_to_hir_id ( def_id) ;
272
- self . tcx . infer_ctxt ( ) . enter ( move |infcx| {
273
- // Require the hidden type to be well-formed with only the generics of the opaque type.
274
- // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
275
- // hidden type is well formed even without those bounds.
276
- let predicate =
277
- ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( definition_ty. into ( ) ) )
278
- . to_predicate ( infcx. tcx ) ;
279
- let mut fulfillment_cx = <dyn TraitEngine < ' tcx > >:: new ( infcx. tcx ) ;
280
-
281
- // Require that the hidden type actually fulfills all the bounds of the opaque type, even without
282
- // the bounds that the function supplies.
283
- match infcx. register_hidden_type (
284
- OpaqueTypeKey { def_id, substs : id_substs } ,
285
- ObligationCause :: misc ( instantiated_ty. span , body_id) ,
286
- param_env,
287
- definition_ty,
288
- origin,
289
- ) {
290
- Ok ( infer_ok) => {
291
- for obligation in infer_ok. obligations {
292
- fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
272
+ // HACK This bubble is required for this tests to pass:
273
+ // type-alias-impl-trait/issue-67844-nested-opaque.rs
274
+ self . tcx . infer_ctxt ( ) . with_opaque_type_inference ( DefiningAnchor :: Bubble ) . enter (
275
+ move |infcx| {
276
+ // Require the hidden type to be well-formed with only the generics of the opaque type.
277
+ // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
278
+ // hidden type is well formed even without those bounds.
279
+ let predicate =
280
+ ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( definition_ty. into ( ) ) )
281
+ . to_predicate ( infcx. tcx ) ;
282
+ let mut fulfillment_cx = <dyn TraitEngine < ' tcx > >:: new ( infcx. tcx ) ;
283
+
284
+ // Require that the hidden type actually fulfills all the bounds of the opaque type, even without
285
+ // the bounds that the function supplies.
286
+ match infcx. register_hidden_type (
287
+ OpaqueTypeKey { def_id, substs : id_substs } ,
288
+ ObligationCause :: misc ( instantiated_ty. span , body_id) ,
289
+ param_env,
290
+ definition_ty,
291
+ origin,
292
+ ) {
293
+ Ok ( infer_ok) => {
294
+ for obligation in infer_ok. obligations {
295
+ fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
296
+ }
297
+ }
298
+ Err ( err) => {
299
+ infcx
300
+ . report_mismatched_types (
301
+ & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
302
+ self . tcx . mk_opaque ( def_id. to_def_id ( ) , id_substs) ,
303
+ definition_ty,
304
+ err,
305
+ )
306
+ . emit ( ) ;
293
307
}
294
308
}
295
- Err ( err) => {
296
- infcx
297
- . report_mismatched_types (
298
- & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
299
- self . tcx . mk_opaque ( def_id. to_def_id ( ) , id_substs) ,
300
- definition_ty,
301
- err,
302
- )
303
- . emit ( ) ;
304
- }
305
- }
306
309
307
- fulfillment_cx. register_predicate_obligation (
308
- & infcx,
309
- Obligation :: misc ( instantiated_ty. span , body_id, param_env, predicate) ,
310
- ) ;
310
+ fulfillment_cx. register_predicate_obligation (
311
+ & infcx,
312
+ Obligation :: misc ( instantiated_ty. span , body_id, param_env, predicate) ,
313
+ ) ;
311
314
312
- // Check that all obligations are satisfied by the implementation's
313
- // version.
314
- let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
315
+ // Check that all obligations are satisfied by the implementation's
316
+ // version.
317
+ let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
315
318
316
- let _ = infcx. inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ;
319
+ // This is still required for many(half of the tests in ui/type-alias-impl-trait)
320
+ // tests to pass
321
+ let _ = infcx. inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ;
317
322
318
- if errors. is_empty ( ) {
319
- definition_ty
320
- } else {
321
- infcx. report_fulfillment_errors ( & errors, None , false ) ;
322
- self . tcx . ty_error ( )
323
- }
324
- } )
323
+ if errors. is_empty ( ) {
324
+ definition_ty
325
+ } else {
326
+ infcx. report_fulfillment_errors ( & errors, None , false ) ;
327
+ self . tcx . ty_error ( )
328
+ }
329
+ } ,
330
+ )
325
331
} else {
326
332
definition_ty
327
333
}
0 commit comments