@@ -3,8 +3,8 @@ use rustc_data_structures::vec_map::VecMap;
33use rustc_hir:: def_id:: LocalDefId ;
44use rustc_hir:: OpaqueTyOrigin ;
55use rustc_infer:: infer:: error_reporting:: unexpected_hidden_region_diagnostic;
6- use rustc_infer:: infer:: InferCtxt ;
76use rustc_infer:: infer:: TyCtxtInferExt as _;
7+ use rustc_infer:: infer:: { DefiningAnchor , InferCtxt } ;
88use rustc_infer:: traits:: { Obligation , ObligationCause , TraitEngine } ;
99use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
1010use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts } ;
@@ -269,59 +269,65 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
269269 // FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
270270 let param_env = self . tcx . param_env ( def_id) ;
271271 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 ( ) ;
293307 }
294308 }
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- }
306309
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+ ) ;
311314
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) ;
315318
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 ( ) ;
317322
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+ )
325331 } else {
326332 definition_ty
327333 }
0 commit comments