@@ -284,6 +284,17 @@ fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
284284 } ;
285285 check_object_unsafe_self_trait_by_name ( tcx, trait_item) ;
286286 check_associated_item ( tcx, def_id, span, method_sig) ;
287+
288+ if matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) ) {
289+ for & assoc_ty_def_id in tcx. associated_types_for_impl_traits_in_associated_fn ( def_id) {
290+ check_associated_item (
291+ tcx,
292+ assoc_ty_def_id. expect_local ( ) ,
293+ tcx. def_span ( assoc_ty_def_id) ,
294+ None ,
295+ ) ;
296+ }
297+ }
287298}
288299
289300/// Require that the user writes where clauses on GATs for the implicit
@@ -1466,13 +1477,6 @@ fn check_fn_or_method<'tcx>(
14661477
14671478 check_where_clauses ( wfcx, span, def_id) ;
14681479
1469- check_return_position_impl_trait_in_trait_bounds (
1470- wfcx,
1471- def_id,
1472- sig. output ( ) ,
1473- hir_decl. output . span ( ) ,
1474- ) ;
1475-
14761480 if sig. abi == Abi :: RustCall {
14771481 let span = tcx. def_span ( def_id) ;
14781482 let has_implicit_self = hir_decl. implicit_self != hir:: ImplicitSelfKind :: None ;
@@ -1507,87 +1511,6 @@ fn check_fn_or_method<'tcx>(
15071511 }
15081512}
15091513
1510- /// Basically `check_associated_type_bounds`, but separated for now and should be
1511- /// deduplicated when RPITITs get lowered into real associated items.
1512- #[ tracing:: instrument( level = "trace" , skip( wfcx) ) ]
1513- fn check_return_position_impl_trait_in_trait_bounds < ' tcx > (
1514- wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
1515- fn_def_id : LocalDefId ,
1516- fn_output : Ty < ' tcx > ,
1517- span : Span ,
1518- ) {
1519- let tcx = wfcx. tcx ( ) ;
1520- let Some ( assoc_item) = tcx. opt_associated_item ( fn_def_id. to_def_id ( ) ) else {
1521- return ;
1522- } ;
1523- if assoc_item. container != ty:: AssocItemContainer :: TraitContainer {
1524- return ;
1525- }
1526- fn_output. visit_with ( & mut ImplTraitInTraitFinder {
1527- wfcx,
1528- fn_def_id,
1529- depth : ty:: INNERMOST ,
1530- seen : FxHashSet :: default ( ) ,
1531- } ) ;
1532- }
1533-
1534- // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): Even with the new lowering
1535- // strategy, we can't just call `check_associated_item` on the new RPITITs,
1536- // because tests like `tests/ui/async-await/in-trait/implied-bounds.rs` will fail.
1537- // That's because we need to check that the bounds of the RPITIT hold using
1538- // the special args that we create during opaque type lowering, otherwise we're
1539- // getting a bunch of early bound and free regions mixed up... Haven't looked too
1540- // deep into this, though.
1541- struct ImplTraitInTraitFinder < ' a , ' tcx > {
1542- wfcx : & ' a WfCheckingCtxt < ' a , ' tcx > ,
1543- fn_def_id : LocalDefId ,
1544- depth : ty:: DebruijnIndex ,
1545- seen : FxHashSet < DefId > ,
1546- }
1547- impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for ImplTraitInTraitFinder < ' _ , ' tcx > {
1548- type BreakTy = !;
1549-
1550- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < !> {
1551- let tcx = self . wfcx . tcx ( ) ;
1552- if let ty:: Alias ( ty:: Opaque , unshifted_opaque_ty) = * ty. kind ( )
1553- && self . seen . insert ( unshifted_opaque_ty. def_id )
1554- && let Some ( opaque_def_id) = unshifted_opaque_ty. def_id . as_local ( )
1555- && let origin = tcx. opaque_type_origin ( opaque_def_id)
1556- && let hir:: OpaqueTyOrigin :: FnReturn ( source) | hir:: OpaqueTyOrigin :: AsyncFn ( source) = origin
1557- && source == self . fn_def_id
1558- {
1559- let opaque_ty = tcx. fold_regions ( unshifted_opaque_ty, |re, _depth| {
1560- match re. kind ( ) {
1561- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReError ( _) | ty:: ReStatic => re,
1562- r => bug ! ( "unexpected region: {r:?}" ) ,
1563- }
1564- } ) ;
1565- for ( bound, bound_span) in tcx
1566- . explicit_item_bounds ( opaque_ty. def_id )
1567- . iter_instantiated_copied ( tcx, opaque_ty. args )
1568- {
1569- let bound = self . wfcx . normalize ( bound_span, None , bound) ;
1570- self . wfcx . register_obligations ( traits:: wf:: predicate_obligations (
1571- self . wfcx . infcx ,
1572- self . wfcx . param_env ,
1573- self . wfcx . body_def_id ,
1574- bound. as_predicate ( ) ,
1575- bound_span,
1576- ) ) ;
1577- // Set the debruijn index back to innermost here, since we already eagerly
1578- // shifted the args that we use to generate these bounds. This is unfortunately
1579- // subtly different behavior than the `ImplTraitInTraitFinder` we use in `param_env`,
1580- // but that function doesn't actually need to normalize the bound it's visiting
1581- // (whereas we have to do so here)...
1582- let old_depth = std:: mem:: replace ( & mut self . depth , ty:: INNERMOST ) ;
1583- bound. visit_with ( self ) ;
1584- self . depth = old_depth;
1585- }
1586- }
1587- ty. super_visit_with ( self )
1588- }
1589- }
1590-
15911514const HELP_FOR_SELF_TYPE : & str = "consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, \
15921515 `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one \
15931516 of the previous types except `Self`)";
0 commit comments