@@ -266,73 +266,69 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
266
266
267
267
// Only check this for TAIT. RPIT already supports `src/test/ui/impl-trait/nested-return-type2.rs`
268
268
// on stable and we'd break that.
269
- if let OpaqueTyOrigin :: TyAlias = origin {
270
- // This logic duplicates most of `check_opaque_meets_bounds`.
271
- // FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
272
- let param_env = self . tcx . param_env ( def_id) ;
273
- let body_id = self . tcx . local_def_id_to_hir_id ( def_id) ;
274
- // HACK This bubble is required for this tests to pass:
275
- // type-alias-impl-trait/issue-67844-nested-opaque.rs
276
- self . tcx . infer_ctxt ( ) . with_opaque_type_inference ( DefiningAnchor :: Bubble ) . enter (
277
- move |infcx| {
278
- // Require the hidden type to be well-formed with only the generics of the opaque type.
279
- // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
280
- // hidden type is well formed even without those bounds.
281
- let predicate =
282
- ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( definition_ty. into ( ) ) )
283
- . to_predicate ( infcx. tcx ) ;
284
- let mut fulfillment_cx = <dyn TraitEngine < ' tcx > >:: new ( infcx. tcx ) ;
285
-
286
- // Require that the hidden type actually fulfills all the bounds of the opaque type, even without
287
- // the bounds that the function supplies.
288
- match infcx. register_hidden_type (
289
- OpaqueTypeKey { def_id, substs : id_substs } ,
290
- ObligationCause :: misc ( instantiated_ty. span , body_id) ,
291
- param_env,
269
+ let OpaqueTyOrigin :: TyAlias = origin else {
270
+ return definition_ty;
271
+ } ;
272
+ // This logic duplicates most of `check_opaque_meets_bounds`.
273
+ // FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
274
+ let param_env = self . tcx . param_env ( def_id) ;
275
+ let body_id = self . tcx . local_def_id_to_hir_id ( def_id) ;
276
+ // HACK This bubble is required for this tests to pass:
277
+ // type-alias-impl-trait/issue-67844-nested-opaque.rs
278
+ let infcx =
279
+ self . tcx . infer_ctxt ( ) . with_opaque_type_inference ( DefiningAnchor :: Bubble ) . build ( ) ;
280
+ // Require the hidden type to be well-formed with only the generics of the opaque type.
281
+ // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
282
+ // hidden type is well formed even without those bounds.
283
+ let predicate = ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( definition_ty. into ( ) ) )
284
+ . to_predicate ( infcx. tcx ) ;
285
+ let mut fulfillment_cx = <dyn TraitEngine < ' tcx > >:: new ( infcx. tcx ) ;
286
+
287
+ // Require that the hidden type actually fulfills all the bounds of the opaque type, even without
288
+ // the bounds that the function supplies.
289
+ match infcx. register_hidden_type (
290
+ OpaqueTypeKey { def_id, substs : id_substs } ,
291
+ ObligationCause :: misc ( instantiated_ty. span , body_id) ,
292
+ param_env,
293
+ definition_ty,
294
+ origin,
295
+ ) {
296
+ Ok ( infer_ok) => {
297
+ for obligation in infer_ok. obligations {
298
+ fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
299
+ }
300
+ }
301
+ Err ( err) => {
302
+ infcx
303
+ . err_ctxt ( )
304
+ . report_mismatched_types (
305
+ & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
306
+ self . tcx . mk_opaque ( def_id. to_def_id ( ) , id_substs) ,
292
307
definition_ty,
293
- origin,
294
- ) {
295
- Ok ( infer_ok) => {
296
- for obligation in infer_ok. obligations {
297
- fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
298
- }
299
- }
300
- Err ( err) => {
301
- infcx
302
- . err_ctxt ( )
303
- . report_mismatched_types (
304
- & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
305
- self . tcx . mk_opaque ( def_id. to_def_id ( ) , id_substs) ,
306
- definition_ty,
307
- err,
308
- )
309
- . emit ( ) ;
310
- }
311
- }
308
+ err,
309
+ )
310
+ . emit ( ) ;
311
+ }
312
+ }
312
313
313
- fulfillment_cx. register_predicate_obligation (
314
- & infcx,
315
- Obligation :: misc ( instantiated_ty. span , body_id, param_env, predicate) ,
316
- ) ;
314
+ fulfillment_cx. register_predicate_obligation (
315
+ & infcx,
316
+ Obligation :: misc ( instantiated_ty. span , body_id, param_env, predicate) ,
317
+ ) ;
317
318
318
- // Check that all obligations are satisfied by the implementation's
319
- // version.
320
- let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
319
+ // Check that all obligations are satisfied by the implementation's
320
+ // version.
321
+ let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
321
322
322
- // This is still required for many(half of the tests in ui/type-alias-impl-trait)
323
- // tests to pass
324
- let _ = infcx. inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ;
323
+ // This is still required for many(half of the tests in ui/type-alias-impl-trait)
324
+ // tests to pass
325
+ let _ = infcx. inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ;
325
326
326
- if errors. is_empty ( ) {
327
- definition_ty
328
- } else {
329
- infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors, None , false ) ;
330
- self . tcx . ty_error ( )
331
- }
332
- } ,
333
- )
334
- } else {
327
+ if errors. is_empty ( ) {
335
328
definition_ty
329
+ } else {
330
+ infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors, None , false ) ;
331
+ self . tcx . ty_error ( )
336
332
}
337
333
}
338
334
}
0 commit comments