@@ -1545,21 +1545,27 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
1545
1545
if let Some ( assoc_item) = tcx. opt_associated_item ( fn_def_id. to_def_id ( ) )
1546
1546
&& assoc_item. container == ty:: AssocItemContainer :: TraitContainer
1547
1547
{
1548
+ // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): Even with the new lowering
1549
+ // strategy, we can't just call `check_associated_item` on the new RPITITs,
1550
+ // because tests like `tests/ui/async-await/in-trait/implied-bounds.rs` will fail.
1551
+ // That's because we need to check that the bounds of the RPITIT hold using
1552
+ // the special substs that we create during opaque type lowering, otherwise we're
1553
+ // getting a bunch of early bound and free regions mixed up... Haven't looked too
1554
+ // deep into this, though.
1548
1555
for arg in fn_output. walk ( ) {
1549
1556
if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( )
1550
- && let ty:: Alias ( ty:: Opaque , proj) = ty. kind ( )
1551
- // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) we should just check
1552
- // `tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder`. Right now
1553
- // `check_associated_type_bounds` is not called for RPITITs synthesized as
1554
- // associated types. See `check_mod_type_wf` to see how synthesized associated
1555
- // types are missed due to iterating over HIR.
1556
- && tcx. is_impl_trait_in_trait ( proj. def_id )
1557
- && tcx. impl_trait_in_trait_parent_fn ( proj. def_id ) == fn_def_id. to_def_id ( )
1557
+ // RPITITs are always eagerly normalized into opaques, so always look for an
1558
+ // opaque here.
1559
+ && let ty:: Alias ( ty:: Opaque , opaque_ty) = ty. kind ( )
1560
+ && let Some ( opaque_def_id) = opaque_ty. def_id . as_local ( )
1561
+ && let opaque = tcx. hir ( ) . expect_item ( opaque_def_id) . expect_opaque_ty ( )
1562
+ && let hir:: OpaqueTyOrigin :: FnReturn ( source) | hir:: OpaqueTyOrigin :: AsyncFn ( source) = opaque. origin
1563
+ && source == fn_def_id
1558
1564
{
1559
- let span = tcx. def_span ( proj . def_id ) ;
1560
- let bounds = wfcx. tcx ( ) . explicit_item_bounds ( proj . def_id ) ;
1565
+ let span = tcx. def_span ( opaque_ty . def_id ) ;
1566
+ let bounds = wfcx. tcx ( ) . explicit_item_bounds ( opaque_ty . def_id ) ;
1561
1567
let wf_obligations = bounds. iter ( ) . flat_map ( |& ( bound, bound_span) | {
1562
- let bound = ty:: EarlyBinder ( bound) . subst ( tcx, proj . substs ) ;
1568
+ let bound = ty:: EarlyBinder ( bound) . subst ( tcx, opaque_ty . substs ) ;
1563
1569
let normalized_bound = wfcx. normalize ( span, None , bound) ;
1564
1570
traits:: wf:: predicate_obligations (
1565
1571
wfcx. infcx ,
0 commit comments