@@ -901,6 +901,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
901
901
)
902
902
}
903
903
904
+ /// Try to relate `sub <: sup`; if this fails, instantiate opaque
905
+ /// variables in `sub` with their inferred definitions and try
906
+ /// again. This is used for opaque types in places (e.g., `let x:
907
+ /// impl Foo = ..`).
904
908
fn sub_types_or_anon (
905
909
& mut self ,
906
910
sub : Ty < ' tcx > ,
@@ -910,7 +914,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
910
914
) -> Fallible < ( ) > {
911
915
if let Err ( terr) = self . sub_types ( sub, sup, locations, category) {
912
916
if let TyKind :: Opaque ( ..) = sup. sty {
913
- return self . eq_opaque_type_and_type ( sub, sup, locations, category) ;
917
+ // When you have `let x: impl Foo = ...` in a closure,
918
+ // the resulting inferend values are stored with the
919
+ // def-id of the base function.
920
+ let parent_def_id = self . tcx ( ) . closure_base_def_id ( self . mir_def_id ) ;
921
+ return self . eq_opaque_type_and_type ( sub, sup, parent_def_id, locations, category) ;
914
922
} else {
915
923
return Err ( terr) ;
916
924
}
@@ -958,13 +966,20 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
958
966
& mut self ,
959
967
revealed_ty : Ty < ' tcx > ,
960
968
anon_ty : Ty < ' tcx > ,
969
+ anon_owner_def_id : DefId ,
961
970
locations : Locations ,
962
971
category : ConstraintCategory ,
963
972
) -> Fallible < ( ) > {
973
+ debug ! (
974
+ "eq_opaque_type_and_type( \
975
+ revealed_ty={:?}, \
976
+ anon_ty={:?})",
977
+ revealed_ty, anon_ty
978
+ ) ;
964
979
let infcx = self . infcx ;
965
980
let tcx = infcx. tcx ;
966
981
let param_env = self . param_env ;
967
- let parent_def_id = infcx . tcx . closure_base_def_id ( self . mir_def_id ) ;
982
+ debug ! ( "eq_opaque_type_and_type: mir_def_id={:?}" , self . mir_def_id) ;
968
983
let opaque_type_map = self . fully_perform_op (
969
984
locations,
970
985
category,
@@ -975,7 +990,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
975
990
let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
976
991
let ( output_ty, opaque_type_map) =
977
992
obligations. add ( infcx. instantiate_opaque_types (
978
- parent_def_id ,
993
+ anon_owner_def_id ,
979
994
dummy_body_id,
980
995
param_env,
981
996
& anon_ty,
@@ -996,8 +1011,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
996
1011
let opaque_defn_ty = opaque_defn_ty. subst ( tcx, opaque_decl. substs ) ;
997
1012
let opaque_defn_ty = renumber:: renumber_regions ( infcx, & opaque_defn_ty) ;
998
1013
debug ! (
999
- "eq_opaque_type_and_type: concrete_ty={:?} opaque_defn_ty={:?}" ,
1000
- opaque_decl. concrete_ty, opaque_defn_ty
1014
+ "eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}" ,
1015
+ opaque_decl. concrete_ty,
1016
+ infcx. resolve_type_vars_if_possible( & opaque_decl. concrete_ty) ,
1017
+ opaque_defn_ty
1001
1018
) ;
1002
1019
obligations. add ( infcx
1003
1020
. at ( & ObligationCause :: dummy ( ) , param_env)
0 commit comments