Skip to content

Commit 0329621

Browse files
committed
[REFACTOR] use OpaqueTypeMap type alias
1 parent 73a3c7e commit 0329621

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_data_structures::vec_map::VecMap;
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::OpaqueTyOrigin;
55
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
6+
use rustc_infer::infer::opaque_types::OpaqueTypeMap;
67
use rustc_infer::infer::TyCtxtInferExt as _;
78
use rustc_infer::infer::{DefiningAnchor, InferCtxt};
89
use rustc_infer::traits::{Obligation, ObligationCause, TraitEngine};
@@ -62,12 +63,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6263
pub(crate) fn infer_opaque_types(
6364
&self,
6465
infcx: &InferCtxt<'_, 'tcx>,
65-
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
66+
opaque_ty_decls: OpaqueTypeMap<'tcx>,
6667
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
6768
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
68-
for (opaque_type_key, (concrete_type, origin)) in opaque_ty_decls {
69+
for (opaque_type_key, decl) in opaque_ty_decls {
6970
let substs = opaque_type_key.substs;
70-
debug!(?concrete_type, ?substs);
71+
debug!(?decl.hidden_type, ?substs);
7172

7273
let mut subst_regions = vec![self.universal_regions.fr_static];
7374
let universal_substs = infcx.tcx.fold_regions(substs, |region, _| {
@@ -90,7 +91,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9091
None => {
9192
subst_regions.push(vid);
9293
infcx.tcx.sess.delay_span_bug(
93-
concrete_type.span,
94+
decl.hidden_type.span,
9495
"opaque type with non-universal region substs",
9596
);
9697
infcx.tcx.lifetimes.re_static
@@ -102,7 +103,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
102103
subst_regions.dedup();
103104

104105
let universal_concrete_type =
105-
infcx.tcx.fold_regions(concrete_type, |region, _| match *region {
106+
infcx.tcx.fold_regions(decl.hidden_type, |region, _| match *region {
106107
ty::ReVar(vid) => subst_regions
107108
.iter()
108109
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
@@ -118,7 +119,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
118119
let ty = infcx.infer_opaque_definition_from_instantiation(
119120
opaque_type_key,
120121
universal_concrete_type,
121-
origin,
122+
decl.origin,
122123
);
123124
// Sometimes two opaque types are the same only after we remap the generic parameters
124125
// back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to `(X, Y)`
@@ -128,19 +129,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
128129
if prev.ty != ty {
129130
if !ty.references_error() {
130131
prev.report_mismatch(
131-
&OpaqueHiddenType { ty, span: concrete_type.span },
132+
&OpaqueHiddenType { ty, span: decl.hidden_type.span },
132133
infcx.tcx,
133134
);
134135
}
135136
prev.ty = infcx.tcx.ty_error();
136137
}
137138
// Pick a better span if there is one.
138139
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
139-
prev.span = prev.span.substitute_dummy(concrete_type.span);
140+
prev.span = prev.span.substitute_dummy(decl.hidden_type.span);
140141
} else {
141142
result.insert(
142143
opaque_type_key.def_id,
143-
OpaqueHiddenType { ty, span: concrete_type.span },
144+
OpaqueHiddenType { ty, span: decl.hidden_type.span },
144145
);
145146
}
146147
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ use std::{fmt, iter, mem};
55

66
use either::Either;
77

8-
use hir::OpaqueTyOrigin;
98
use rustc_data_structures::frozen::Frozen;
109
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
11-
use rustc_data_structures::vec_map::VecMap;
1210
use rustc_hir as hir;
1311
use rustc_hir::def::DefKind;
1412
use rustc_hir::def_id::LocalDefId;
1513
use rustc_hir::lang_items::LangItem;
1614
use rustc_index::vec::{Idx, IndexVec};
1715
use rustc_infer::infer::canonical::QueryRegionConstraints;
16+
use rustc_infer::infer::opaque_types::{OpaqueTypeDecl, OpaqueTypeMap};
1817
use rustc_infer::infer::outlives::env::RegionBoundPairs;
1918
use rustc_infer::infer::region_constraints::RegionConstraintData;
2019
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -30,8 +29,8 @@ use rustc_middle::ty::cast::CastTy;
3029
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef, UserSubsts};
3130
use rustc_middle::ty::visit::TypeVisitable;
3231
use rustc_middle::ty::{
33-
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueHiddenType,
34-
OpaqueTypeKey, RegionVid, ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
32+
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPredicate, Ty,
33+
TyCtxt, UserType, UserTypeAnnotationIndex,
3534
};
3635
use rustc_span::def_id::CRATE_DEF_ID;
3736
use rustc_span::{Span, DUMMY_SP};
@@ -870,8 +869,7 @@ struct BorrowCheckContext<'a, 'tcx> {
870869
pub(crate) struct MirTypeckResults<'tcx> {
871870
pub(crate) constraints: MirTypeckRegionConstraints<'tcx>,
872871
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
873-
pub(crate) opaque_type_values:
874-
VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
872+
pub(crate) opaque_type_values: OpaqueTypeMap<'tcx>,
875873
}
876874

877875
/// A collection of region constraints that must be satisfied for the
@@ -2645,9 +2643,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26452643

26462644
/// Generates member constraints for the opaque types found so far.
26472645
/// Returns a map to their hidden types.
2648-
fn finalize_opaque_types(
2649-
&mut self,
2650-
) -> VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)> {
2646+
fn finalize_opaque_types(&mut self) -> OpaqueTypeMap<'tcx> {
26512647
let opaque_type_values =
26522648
self.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
26532649

@@ -2686,7 +2682,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26862682
hidden_type.ty = self.infcx.tcx.ty_error();
26872683
}
26882684

2689-
(opaque_type_key, (hidden_type, decl.origin))
2685+
(opaque_type_key, OpaqueTypeDecl { hidden_type, ..decl })
26902686
})
26912687
.collect()
26922688
}

0 commit comments

Comments
 (0)