@@ -403,16 +403,6 @@ fn check_opaque_meets_bounds<'tcx>(
403
403
return Err ( guar) ;
404
404
}
405
405
match origin {
406
- // Checked when type checking the function containing them.
407
- hir:: OpaqueTyOrigin :: FnReturn ( ..) | hir:: OpaqueTyOrigin :: AsyncFn ( ..) => {
408
- // HACK: this should also fall through to the hidden type check below, but the original
409
- // implementation had a bug where equivalent lifetimes are not identical. This caused us
410
- // to reject existing stable code that is otherwise completely fine. The real fix is to
411
- // compare the hidden types via our type equivalence/relation infra instead of doing an
412
- // identity check.
413
- let _ = infcx. take_opaque_types ( ) ;
414
- return Ok ( ( ) ) ;
415
- }
416
406
// Nested opaque types occur only in associated types:
417
407
// ` type Opaque<T> = impl Trait<&'static T, AssocTy = impl Nested>; `
418
408
// They can only be referenced as `<Opaque<T> as Trait<&'static T>>::AssocTy`.
@@ -421,20 +411,33 @@ fn check_opaque_meets_bounds<'tcx>(
421
411
hir:: OpaqueTyOrigin :: TyAlias { .. }
422
412
if tcx. def_kind ( tcx. parent ( def_id. to_def_id ( ) ) ) == DefKind :: OpaqueTy => { }
423
413
// Can have different predicates to their defining use
424
- hir:: OpaqueTyOrigin :: TyAlias { .. } => {
425
- let wf_tys = ocx. assumed_wf_types_and_report_errors ( param_env, def_id) ?;
414
+ hir:: OpaqueTyOrigin :: TyAlias { .. }
415
+ | hir:: OpaqueTyOrigin :: FnReturn ( ..)
416
+ | hir:: OpaqueTyOrigin :: AsyncFn ( ..) => {
417
+ let wf_tys = ocx. assumed_wf_types_and_report_errors ( param_env, defining_use_anchor) ?;
426
418
let implied_bounds = infcx. implied_bounds_tys ( param_env, def_id, & wf_tys) ;
427
419
let outlives_env = OutlivesEnvironment :: with_bounds ( param_env, implied_bounds) ;
428
420
ocx. resolve_regions_and_report_errors ( defining_use_anchor, & outlives_env) ?;
429
421
}
430
422
}
431
- // Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
432
- for ( mut key, mut ty) in infcx. take_opaque_types ( ) {
433
- ty. hidden_type . ty = infcx. resolve_vars_if_possible ( ty. hidden_type . ty ) ;
434
- key = infcx. resolve_vars_if_possible ( key) ;
435
- sanity_check_found_hidden_type ( tcx, key, ty. hidden_type ) ?;
423
+
424
+ if let hir:: OpaqueTyOrigin :: FnReturn ( ..) | hir:: OpaqueTyOrigin :: AsyncFn ( ..) = origin {
425
+ // HACK: this should also fall through to the hidden type check below, but the original
426
+ // implementation had a bug where equivalent lifetimes are not identical. This caused us
427
+ // to reject existing stable code that is otherwise completely fine. The real fix is to
428
+ // compare the hidden types via our type equivalence/relation infra instead of doing an
429
+ // identity check.
430
+ let _ = infcx. take_opaque_types ( ) ;
431
+ Ok ( ( ) )
432
+ } else {
433
+ // Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
434
+ for ( mut key, mut ty) in infcx. take_opaque_types ( ) {
435
+ ty. hidden_type . ty = infcx. resolve_vars_if_possible ( ty. hidden_type . ty ) ;
436
+ key = infcx. resolve_vars_if_possible ( key) ;
437
+ sanity_check_found_hidden_type ( tcx, key, ty. hidden_type ) ?;
438
+ }
439
+ Ok ( ( ) )
436
440
}
437
- Ok ( ( ) )
438
441
}
439
442
440
443
fn sanity_check_found_hidden_type < ' tcx > (
0 commit comments