@@ -7,9 +7,10 @@ use either::Either;
77
88use rustc_data_structures:: frozen:: Frozen ;
99use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
10+ use rustc_data_structures:: vec_map:: VecMap ;
1011use rustc_errors:: struct_span_err;
1112use rustc_hir as hir;
12- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
13+ use rustc_hir:: def_id:: LocalDefId ;
1314use rustc_hir:: lang_items:: LangItem ;
1415use rustc_index:: vec:: { Idx , IndexVec } ;
1516use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
@@ -27,8 +28,8 @@ use rustc_middle::ty::cast::CastTy;
2728use rustc_middle:: ty:: fold:: TypeFoldable ;
2829use rustc_middle:: ty:: subst:: { GenericArgKind , Subst , SubstsRef , UserSubsts } ;
2930use rustc_middle:: ty:: {
30- self , CanonicalUserTypeAnnotation , CanonicalUserTypeAnnotations , RegionVid , ToPredicate , Ty ,
31- TyCtxt , UserType , UserTypeAnnotationIndex , WithConstness ,
31+ self , CanonicalUserTypeAnnotation , CanonicalUserTypeAnnotations , OpaqueTypeKey , RegionVid ,
32+ ToPredicate , Ty , TyCtxt , UserType , UserTypeAnnotationIndex , WithConstness ,
3233} ;
3334use rustc_span:: { Span , DUMMY_SP } ;
3435use rustc_target:: abi:: VariantIdx ;
@@ -818,7 +819,7 @@ struct TypeChecker<'a, 'tcx> {
818819 reported_errors : FxHashSet < ( Ty < ' tcx > , Span ) > ,
819820 borrowck_context : & ' a mut BorrowCheckContext < ' a , ' tcx > ,
820821 universal_region_relations : & ' a UniversalRegionRelations < ' tcx > ,
821- opaque_type_values : FxHashMap < DefId , ty:: ResolvedOpaqueTy < ' tcx > > ,
822+ opaque_type_values : VecMap < OpaqueTypeKey < ' tcx > , ty:: ResolvedOpaqueTy < ' tcx > > ,
822823}
823824
824825struct BorrowCheckContext < ' a , ' tcx > {
@@ -833,7 +834,7 @@ struct BorrowCheckContext<'a, 'tcx> {
833834crate struct MirTypeckResults < ' tcx > {
834835 crate constraints : MirTypeckRegionConstraints < ' tcx > ,
835836 pub ( in crate :: borrow_check) universal_region_relations : Frozen < UniversalRegionRelations < ' tcx > > ,
836- crate opaque_type_values : FxHashMap < DefId , ty:: ResolvedOpaqueTy < ' tcx > > ,
837+ crate opaque_type_values : VecMap < OpaqueTypeKey < ' tcx > , ty:: ResolvedOpaqueTy < ' tcx > > ,
837838}
838839
839840/// A collection of region constraints that must be satisfied for the
@@ -978,7 +979,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
978979 borrowck_context,
979980 reported_errors : Default :: default ( ) ,
980981 universal_region_relations,
981- opaque_type_values : FxHashMap :: default ( ) ,
982+ opaque_type_values : VecMap :: default ( ) ,
982983 } ;
983984 checker. check_user_type_annotations ( ) ;
984985 checker
@@ -1240,7 +1241,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12401241 let param_env = self . param_env ;
12411242 let body = self . body ;
12421243 let concrete_opaque_types = & tcx. typeck ( anon_owner_def_id) . concrete_opaque_types ;
1243- let mut opaque_type_values = Vec :: new ( ) ;
1244+ let mut opaque_type_values = VecMap :: new ( ) ;
12441245
12451246 debug ! ( "eq_opaque_type_and_type: mir_def_id={:?}" , body. source. def_id( ) ) ;
12461247 let opaque_type_map = self . fully_perform_op (
@@ -1288,7 +1289,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12881289 } else {
12891290 false
12901291 } ;
1291- let opaque_defn_ty = match concrete_opaque_types. get ( & opaque_def_id) {
1292+
1293+ let opaque_type_key =
1294+ OpaqueTypeKey { def_id : opaque_def_id, substs : opaque_decl. substs } ;
1295+ let opaque_defn_ty = match concrete_opaque_types
1296+ . iter ( )
1297+ . find ( |( opaque_type_key, _) | opaque_type_key. def_id == opaque_def_id)
1298+ . map ( |( _, resolved_opaque_ty) | resolved_opaque_ty)
1299+ {
12921300 None => {
12931301 if !concrete_is_opaque {
12941302 tcx. sess . delay_span_bug (
@@ -1322,13 +1330,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13221330 . at ( & ObligationCause :: dummy ( ) , param_env)
13231331 . eq ( opaque_decl. concrete_ty , renumbered_opaque_defn_ty) ?,
13241332 ) ;
1325- opaque_type_values. push ( (
1326- opaque_def_id ,
1333+ opaque_type_values. insert (
1334+ opaque_type_key ,
13271335 ty:: ResolvedOpaqueTy {
13281336 concrete_type : renumbered_opaque_defn_ty,
13291337 substs : opaque_decl. substs ,
13301338 } ,
1331- ) ) ;
1339+ ) ;
13321340 } else {
13331341 // We're using an opaque `impl Trait` type without
13341342 // 'revealing' it. For example, code like this:
0 commit comments