Skip to content

Commit 37ab718

Browse files
committed
Make opaque type map key be of type OpaqueTypeKey
1 parent 7294f49 commit 37ab718

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12821282
.eq(output_ty, revealed_ty)?,
12831283
);
12841284

1285-
for &(opaque_def_id, opaque_decl) in &opaque_type_map {
1285+
for &(opaque_type_key, opaque_decl) in &opaque_type_map {
1286+
let opaque_def_id = opaque_type_key.def_id;
12861287
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
12871288
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
12881289
*def_id == opaque_def_id
@@ -1377,7 +1378,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13771378
// prove that `T: Iterator` where `T` is the type we
13781379
// instantiated it with).
13791380
if let Some(opaque_type_map) = opaque_type_map {
1380-
for (opaque_def_id, opaque_decl) in opaque_type_map {
1381+
for (opaque_type_key, opaque_decl) in opaque_type_map {
1382+
let opaque_def_id = opaque_type_key.def_id;
13811383
self.fully_perform_op(
13821384
locations,
13831385
ConstraintCategory::OpaqueType,

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_span::Span;
1717

1818
use std::ops::ControlFlow;
1919

20-
pub type OpaqueTypeMap<'tcx> = VecMap<DefId, OpaqueTypeDecl<'tcx>>;
20+
pub type OpaqueTypeMap<'tcx> = VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
2121

2222
/// Information about the opaque types whose values we
2323
/// are inferring in this function (these are the `impl Trait` that
@@ -370,7 +370,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
370370
) {
371371
debug!("constrain_opaque_types()");
372372

373-
for &(def_id, opaque_defn) in opaque_types {
373+
for &(opaque_type_key, opaque_defn) in opaque_types {
374+
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
374375
self.constrain_opaque_type(
375376
def_id,
376377
&opaque_defn,
@@ -1041,7 +1042,12 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10411042

10421043
// Use the same type variable if the exact same opaque type appears more
10431044
// than once in the return type (e.g., if it's passed to a type alias).
1044-
if let Some(opaque_defn) = self.opaque_types.get(&def_id) {
1045+
if let Some(opaque_defn) = self
1046+
.opaque_types
1047+
.iter()
1048+
.find(|(opaque_type_key, _)| opaque_type_key.def_id == def_id)
1049+
.map(|(_, opaque_defn)| opaque_defn)
1050+
{
10451051
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
10461052
return opaque_defn.concrete_ty;
10471053
}
@@ -1079,7 +1085,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10791085
let definition_span = self.value_span;
10801086

10811087
self.opaque_types.insert(
1082-
def_id,
1088+
OpaqueTypeKey { def_id, substs },
10831089
OpaqueTypeDecl {
10841090
opaque_type: ty,
10851091
substs,

compiler/rustc_typeck/src/check/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,8 @@ fn check_opaque_meets_bounds<'tcx>(
716716
infcx.instantiate_opaque_types(def_id, hir_id, param_env, opaque_ty, span),
717717
);
718718

719-
for (def_id, opaque_defn) in opaque_type_map {
719+
for (opaque_type_key, opaque_defn) in opaque_type_map {
720+
let def_id = opaque_type_key.def_id;
720721
match infcx
721722
.at(&misc_cause, param_env)
722723
.eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, opaque_defn.substs))

compiler/rustc_typeck/src/check/inherited.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use super::MaybeInProgressTables;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_data_structures::vec_map::VecMap;
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
7+
use rustc_hir::def_id::{DefIdMap, LocalDefId};
88
use rustc_hir::HirIdMap;
99
use rustc_infer::infer;
1010
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
1111
use rustc_middle::ty::fold::TypeFoldable;
12-
use rustc_middle::ty::{self, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
1313
use rustc_span::{self, Span};
1414
use rustc_trait_selection::infer::InferCtxtExt as _;
1515
use rustc_trait_selection::opaque_types::OpaqueTypeDecl;
@@ -59,7 +59,7 @@ pub struct Inherited<'a, 'tcx> {
5959
// associated fresh inference variable. Writeback resolves these
6060
// variables to get the concrete type, which can be used to
6161
// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
62-
pub(super) opaque_types: RefCell<VecMap<DefId, OpaqueTypeDecl<'tcx>>>,
62+
pub(super) opaque_types: RefCell<VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>>,
6363

6464
/// A map from inference variables created from opaque
6565
/// type instantiations (`ty::Infer`) to the actual opaque

compiler/rustc_typeck/src/check/writeback.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
475475
}
476476

477477
fn visit_opaque_types(&mut self, span: Span) {
478-
for &(def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
478+
for &(opaque_type_key, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
479+
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
479480
let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local());
480481
let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id);
481482

0 commit comments

Comments
 (0)