@@ -883,6 +883,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
883
883
)
884
884
}
885
885
886
+ /// Try to relate `sub <: sup`; if this fails, instantiate opaque
887
+ /// variables in `sub` with their inferred definitions and try
888
+ /// again. This is used for opaque types in places (e.g., `let x:
889
+ /// impl Foo = ..`).
886
890
fn sub_types_or_anon (
887
891
& mut self ,
888
892
sub : Ty < ' tcx > ,
@@ -892,7 +896,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
892
896
) -> Fallible < ( ) > {
893
897
if let Err ( terr) = self . sub_types ( sub, sup, locations, category) {
894
898
if let TyKind :: Opaque ( ..) = sup. sty {
895
- return self . eq_opaque_type_and_type ( sub, sup, locations, category) ;
899
+ // When you have `let x: impl Foo = ...` in a closure,
900
+ // the resulting inferend values are stored with the
901
+ // def-id of the base function.
902
+ let parent_def_id = self . tcx ( ) . closure_base_def_id ( self . mir_def_id ) ;
903
+ return self . eq_opaque_type_and_type ( sub, sup, parent_def_id, locations, category) ;
896
904
} else {
897
905
return Err ( terr) ;
898
906
}
@@ -940,13 +948,20 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
940
948
& mut self ,
941
949
revealed_ty : Ty < ' tcx > ,
942
950
anon_ty : Ty < ' tcx > ,
951
+ anon_owner_def_id : DefId ,
943
952
locations : Locations ,
944
953
category : ConstraintCategory ,
945
954
) -> Fallible < ( ) > {
955
+ debug ! (
956
+ "eq_opaque_type_and_type( \
957
+ revealed_ty={:?}, \
958
+ anon_ty={:?})",
959
+ revealed_ty, anon_ty
960
+ ) ;
946
961
let infcx = self . infcx ;
947
962
let tcx = infcx. tcx ;
948
963
let param_env = self . param_env ;
949
- let parent_def_id = infcx . tcx . closure_base_def_id ( self . mir_def_id ) ;
964
+ debug ! ( "eq_opaque_type_and_type: mir_def_id={:?}" , self . mir_def_id) ;
950
965
let opaque_type_map = self . fully_perform_op (
951
966
locations,
952
967
category,
@@ -957,7 +972,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
957
972
let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
958
973
let ( output_ty, opaque_type_map) =
959
974
obligations. add ( infcx. instantiate_opaque_types (
960
- parent_def_id ,
975
+ anon_owner_def_id ,
961
976
dummy_body_id,
962
977
param_env,
963
978
& anon_ty,
@@ -978,8 +993,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
978
993
let opaque_defn_ty = opaque_defn_ty. subst ( tcx, opaque_decl. substs ) ;
979
994
let opaque_defn_ty = renumber:: renumber_regions ( infcx, & opaque_defn_ty) ;
980
995
debug ! (
981
- "eq_opaque_type_and_type: concrete_ty={:?} opaque_defn_ty={:?}" ,
982
- opaque_decl. concrete_ty, opaque_defn_ty
996
+ "eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}" ,
997
+ opaque_decl. concrete_ty,
998
+ infcx. resolve_type_vars_if_possible( & opaque_decl. concrete_ty) ,
999
+ opaque_defn_ty
983
1000
) ;
984
1001
obligations. add ( infcx
985
1002
. at ( & ObligationCause :: dummy ( ) , param_env)
0 commit comments