@@ -503,7 +503,7 @@ impl<'a> InferenceContext<'a> {
503503 result : InferenceResult :: default ( ) ,
504504 table : unify:: InferenceTable :: new ( db, trait_env. clone ( ) ) ,
505505 trait_env,
506- return_ty : TyKind :: Error . intern ( Interner ) , // set in collect_fn_signature
506+ return_ty : TyKind :: Error . intern ( Interner ) , // set in collect_* calls
507507 resume_yield_tys : None ,
508508 db,
509509 owner,
@@ -582,14 +582,17 @@ impl<'a> InferenceContext<'a> {
582582 } else {
583583 & * data. ret_type
584584 } ;
585- let return_ty = self . make_ty_with_mode ( return_ty, ImplTraitLoweringMode :: Opaque ) ;
586- self . return_ty = return_ty;
587585
588- if let Some ( rpits) = self . db . return_type_impl_traits ( func) {
586+ let ctx = crate :: lower:: TyLoweringContext :: new ( self . db , & self . resolver )
587+ . with_impl_trait_mode ( ImplTraitLoweringMode :: Opaque ) ;
588+ let return_ty = ctx. lower_ty ( return_ty) ;
589+ let return_ty = self . insert_type_vars ( return_ty) ;
590+
591+ let return_ty = if let Some ( rpits) = self . db . return_type_impl_traits ( func) {
589592 // RPIT opaque types use substitution of their parent function.
590593 let fn_placeholders = TyBuilder :: placeholder_subst ( self . db , func) ;
591- self . return_ty = fold_tys (
592- self . return_ty . clone ( ) ,
594+ fold_tys (
595+ return_ty,
593596 |ty, _| {
594597 let opaque_ty_id = match ty. kind ( Interner ) {
595598 TyKind :: OpaqueType ( opaque_ty_id, _) => * opaque_ty_id,
@@ -610,14 +613,18 @@ impl<'a> InferenceContext<'a> {
610613 let ( var_predicate, binders) = predicate
611614 . substitute ( Interner , & var_subst)
612615 . into_value_and_skipped_binders ( ) ;
613- always ! ( binders. len ( Interner ) == 0 ) ; // quantified where clauses not yet handled
616+ always ! ( binders. is_empty ( Interner ) ) ; // quantified where clauses not yet handled
614617 self . push_obligation ( var_predicate. cast ( Interner ) ) ;
615618 }
616619 var
617620 } ,
618621 DebruijnIndex :: INNERMOST ,
619- ) ;
620- }
622+ )
623+ } else {
624+ return_ty
625+ } ;
626+
627+ self . return_ty = self . normalize_associated_types_in ( return_ty) ;
621628 }
622629
623630 fn infer_body ( & mut self ) {
@@ -652,23 +659,14 @@ impl<'a> InferenceContext<'a> {
652659 self . result . diagnostics . push ( diagnostic) ;
653660 }
654661
655- fn make_ty_with_mode (
656- & mut self ,
657- type_ref : & TypeRef ,
658- impl_trait_mode : ImplTraitLoweringMode ,
659- ) -> Ty {
662+ fn make_ty ( & mut self , type_ref : & TypeRef ) -> Ty {
660663 // FIXME use right resolver for block
661- let ctx = crate :: lower:: TyLoweringContext :: new ( self . db , & self . resolver )
662- . with_impl_trait_mode ( impl_trait_mode) ;
664+ let ctx = crate :: lower:: TyLoweringContext :: new ( self . db , & self . resolver ) ;
663665 let ty = ctx. lower_ty ( type_ref) ;
664666 let ty = self . insert_type_vars ( ty) ;
665667 self . normalize_associated_types_in ( ty)
666668 }
667669
668- fn make_ty ( & mut self , type_ref : & TypeRef ) -> Ty {
669- self . make_ty_with_mode ( type_ref, ImplTraitLoweringMode :: Disallowed )
670- }
671-
672670 fn err_ty ( & self ) -> Ty {
673671 self . result . standard_types . unknown . clone ( )
674672 }
0 commit comments