diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2021-06-07 18:12:43 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2021-06-07 19:10:12 -0300 |
| commit | 9e547b446433d63e3fe99bacfdaedf97fed31a8a (patch) | |
| tree | 2df6a2063ec89a78e3b18621074d988777279271 /compiler/rustc_trait_selection | |
| parent | e3863735144095312ab6486191fc8666d7c54e4b (diff) | |
| download | rust-9e547b446433d63e3fe99bacfdaedf97fed31a8a.tar.gz rust-9e547b446433d63e3fe99bacfdaedf97fed31a8a.zip | |
Differentiate different defining uses of taits when they reference distinct generic parameters
Diffstat (limited to 'compiler/rustc_trait_selection')
| -rw-r--r-- | compiler/rustc_trait_selection/src/opaque_types.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 8b864d67536..89ec211f262 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -11,7 +11,7 @@ use rustc_infer::infer::free_regions::FreeRegionRelations; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{self, InferCtxt, InferOk}; use rustc_middle::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor}; -use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef}; +use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst}; use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt}; use rustc_span::Span; @@ -1007,7 +1007,9 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { ), }; if in_definition_scope { - return self.fold_opaque_ty(ty, def_id.to_def_id(), substs, origin); + let opaque_type_key = + OpaqueTypeKey { def_id: def_id.to_def_id(), substs }; + return self.fold_opaque_ty(ty, opaque_type_key, origin); } debug!( @@ -1029,23 +1031,18 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { fn fold_opaque_ty( &mut self, ty: Ty<'tcx>, - def_id: DefId, - substs: SubstsRef<'tcx>, + opaque_type_key: OpaqueTypeKey<'tcx>, origin: hir::OpaqueTyOrigin, ) -> Ty<'tcx> { let infcx = self.infcx; let tcx = infcx.tcx; + let OpaqueTypeKey { def_id, substs } = opaque_type_key; debug!("instantiate_opaque_types: Opaque(def_id={:?}, substs={:?})", def_id, substs); // Use the same type variable if the exact same opaque type appears more // than once in the return type (e.g., if it's passed to a type alias). - if let Some(opaque_defn) = self - .opaque_types - .iter() - .find(|(opaque_type_key, _)| opaque_type_key.def_id == def_id) - .map(|(_, opaque_defn)| opaque_defn) - { + if let Some(opaque_defn) = self.opaque_types.get(&opaque_type_key) { debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty); return opaque_defn.concrete_ty; } |
