@@ -503,7 +503,7 @@ impl<'a> InferenceContext<'a> {
503
503
result : InferenceResult :: default ( ) ,
504
504
table : unify:: InferenceTable :: new ( db, trait_env. clone ( ) ) ,
505
505
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
507
507
resume_yield_tys : None ,
508
508
db,
509
509
owner,
@@ -582,14 +582,17 @@ impl<'a> InferenceContext<'a> {
582
582
} else {
583
583
& * data. ret_type
584
584
} ;
585
- let return_ty = self . make_ty_with_mode ( return_ty, ImplTraitLoweringMode :: Opaque ) ;
586
- self . return_ty = return_ty;
587
585
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) {
589
592
// RPIT opaque types use substitution of their parent function.
590
593
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,
593
596
|ty, _| {
594
597
let opaque_ty_id = match ty. kind ( Interner ) {
595
598
TyKind :: OpaqueType ( opaque_ty_id, _) => * opaque_ty_id,
@@ -610,14 +613,18 @@ impl<'a> InferenceContext<'a> {
610
613
let ( var_predicate, binders) = predicate
611
614
. substitute ( Interner , & var_subst)
612
615
. 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
614
617
self . push_obligation ( var_predicate. cast ( Interner ) ) ;
615
618
}
616
619
var
617
620
} ,
618
621
DebruijnIndex :: INNERMOST ,
619
- ) ;
620
- }
622
+ )
623
+ } else {
624
+ return_ty
625
+ } ;
626
+
627
+ self . return_ty = self . normalize_associated_types_in ( return_ty) ;
621
628
}
622
629
623
630
fn infer_body ( & mut self ) {
@@ -652,23 +659,14 @@ impl<'a> InferenceContext<'a> {
652
659
self . result . diagnostics . push ( diagnostic) ;
653
660
}
654
661
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 {
660
663
// 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 ) ;
663
665
let ty = ctx. lower_ty ( type_ref) ;
664
666
let ty = self . insert_type_vars ( ty) ;
665
667
self . normalize_associated_types_in ( ty)
666
668
}
667
669
668
- fn make_ty ( & mut self , type_ref : & TypeRef ) -> Ty {
669
- self . make_ty_with_mode ( type_ref, ImplTraitLoweringMode :: Disallowed )
670
- }
671
-
672
670
fn err_ty ( & self ) -> Ty {
673
671
self . result . standard_types . unknown . clone ( )
674
672
}
0 commit comments