Skip to content

Commit 7294f49

Browse files
committed
Remove ResolvedOpaqueTy and just use Ty, SubstsRef is already there
1 parent 7f8cad2 commit 7294f49

File tree

8 files changed

+40
-69
lines changed

8 files changed

+40
-69
lines changed

compiler/rustc_middle/src/mir/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub struct BorrowCheckResult<'tcx> {
211211
/// All the opaque types that are restricted to concrete types
212212
/// by this function. Unlike the value in `TypeckResults`, this has
213213
/// unerased regions.
214-
pub concrete_opaque_types: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
214+
pub concrete_opaque_types: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
215215
pub closure_requirements: Option<ClosureRegionRequirements<'tcx>>,
216216
pub used_mut_upvars: SmallVec<[Field; 8]>,
217217
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,6 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
288288
}
289289
}
290290

291-
/// All information necessary to validate and reveal an `impl Trait`.
292-
#[derive(TyEncodable, TyDecodable, Debug, HashStable)]
293-
pub struct ResolvedOpaqueTy<'tcx> {
294-
/// The revealed type as seen by this function.
295-
pub concrete_type: Ty<'tcx>,
296-
/// Generic parameters on the opaque type as passed by this function.
297-
/// For `type Foo<A, B> = impl Bar<A, B>; fn foo<T, U>() -> Foo<T, U> { .. }`
298-
/// this is `[T, U]`, not `[A, B]`.
299-
pub substs: SubstsRef<'tcx>,
300-
}
301-
302291
/// Whenever a value may be live across a generator yield, the type of that value winds up in the
303292
/// `GeneratorInteriorTypeCause` struct. This struct adds additional information about such
304293
/// captured types that can be useful for diagnostics. In particular, it stores the span that
@@ -426,7 +415,7 @@ pub struct TypeckResults<'tcx> {
426415

427416
/// All the opaque types that are restricted to concrete types
428417
/// by this function.
429-
pub concrete_opaque_types: VecMap<OpaqueTypeKey<'tcx>, ResolvedOpaqueTy<'tcx>>,
418+
pub concrete_opaque_types: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
430419

431420
/// Tracks the minimum captures required for a closure;
432421
/// see `MinCaptureInformationMap` for more details.

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub use self::consts::{Const, ConstInt, ConstKind, InferConst, ScalarInt, Uneval
5858
pub use self::context::{
5959
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
6060
CtxtInterners, DelaySpanBugEmitted, FreeRegionInfo, GeneratorInteriorTypeCause, GlobalCtxt,
61-
Lift, ResolvedOpaqueTy, TyCtxt, TypeckResults, UserType, UserTypeAnnotationIndex,
61+
Lift, TyCtxt, TypeckResults, UserType, UserTypeAnnotationIndex,
6262
};
6363
pub use self::instance::{Instance, InstanceDef};
6464
pub use self::list::List;

compiler/rustc_mir/src/borrow_check/nll.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::{
88
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
99
Promoted,
1010
};
11-
use rustc_middle::ty::{self, OpaqueTypeKey, RegionKind, RegionVid};
11+
use rustc_middle::ty::{self, OpaqueTypeKey, RegionKind, RegionVid, Ty};
1212
use rustc_span::symbol::sym;
1313
use std::env;
1414
use std::fmt::Debug;
@@ -46,7 +46,7 @@ crate type PoloniusOutput = Output<RustcFacts>;
4646
/// closure requirements to propagate, and any generated errors.
4747
crate struct NllOutput<'tcx> {
4848
pub regioncx: RegionInferenceContext<'tcx>,
49-
pub opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
49+
pub opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
5050
pub polonius_output: Option<Rc<PoloniusOutput>>,
5151
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
5252
pub nll_errors: RegionErrors<'tcx>,
@@ -366,7 +366,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
366366
body: &Body<'tcx>,
367367
regioncx: &RegionInferenceContext<'tcx>,
368368
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
369-
opaque_type_values: &VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
369+
opaque_type_values: &VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
370370
errors_buffer: &mut Vec<Diagnostic>,
371371
) {
372372
let tcx = infcx.tcx;

compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_data_structures::vec_map::VecMap;
22
use rustc_infer::infer::InferCtxt;
3-
use rustc_middle::ty::{self, OpaqueTypeKey, TyCtxt, TypeFoldable};
3+
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
44
use rustc_span::Span;
55
use rustc_trait_selection::opaque_types::InferCtxtExt;
66

@@ -50,12 +50,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5050
pub(in crate::borrow_check) fn infer_opaque_types(
5151
&self,
5252
infcx: &InferCtxt<'_, 'tcx>,
53-
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
53+
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
5454
span: Span,
55-
) -> VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>> {
55+
) -> VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>> {
5656
opaque_ty_decls
5757
.into_iter()
58-
.map(|(opaque_type_key, ty::ResolvedOpaqueTy { concrete_type, substs })| {
58+
.map(|(opaque_type_key, concrete_type)| {
59+
let substs = opaque_type_key.substs;
5960
debug!(?concrete_type, ?substs);
6061

6162
let mut subst_regions = vec![self.universal_regions.fr_static];
@@ -116,10 +117,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
116117
universal_concrete_type,
117118
span,
118119
);
119-
(
120-
opaque_type_key,
121-
ty::ResolvedOpaqueTy { concrete_type: remapped_type, substs: universal_substs },
122-
)
120+
(opaque_type_key, remapped_type)
123121
})
124122
.collect()
125123
}

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ struct TypeChecker<'a, 'tcx> {
819819
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
820820
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
821821
universal_region_relations: &'a UniversalRegionRelations<'tcx>,
822-
opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
822+
opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
823823
}
824824

825825
struct BorrowCheckContext<'a, 'tcx> {
@@ -834,7 +834,7 @@ struct BorrowCheckContext<'a, 'tcx> {
834834
crate struct MirTypeckResults<'tcx> {
835835
crate constraints: MirTypeckRegionConstraints<'tcx>,
836836
pub(in crate::borrow_check) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
837-
crate opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
837+
crate opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
838838
}
839839

840840
/// A collection of region constraints that must be satisfied for the
@@ -1292,10 +1292,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12921292

12931293
let opaque_type_key =
12941294
OpaqueTypeKey { def_id: opaque_def_id, substs: opaque_decl.substs };
1295-
let opaque_defn_ty = match concrete_opaque_types
1295+
let concrete_ty = match concrete_opaque_types
12961296
.iter()
12971297
.find(|(opaque_type_key, _)| opaque_type_key.def_id == opaque_def_id)
1298-
.map(|(_, resolved_opaque_ty)| resolved_opaque_ty)
1298+
.map(|(_, concrete_ty)| concrete_ty)
12991299
{
13001300
None => {
13011301
if !concrete_is_opaque {
@@ -1309,17 +1309,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13091309
}
13101310
continue;
13111311
}
1312-
Some(opaque_defn_ty) => opaque_defn_ty,
1312+
Some(concrete_ty) => concrete_ty,
13131313
};
1314-
debug!("opaque_defn_ty = {:?}", opaque_defn_ty);
1315-
let subst_opaque_defn_ty =
1316-
opaque_defn_ty.concrete_type.subst(tcx, opaque_decl.substs);
1314+
debug!("concrete_ty = {:?}", concrete_ty);
1315+
let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_decl.substs);
13171316
let renumbered_opaque_defn_ty =
13181317
renumber::renumber_regions(infcx, subst_opaque_defn_ty);
13191318

13201319
debug!(
13211320
"eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}",
1322-
opaque_decl.concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
1321+
concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
13231322
);
13241323

13251324
if !concrete_is_opaque {
@@ -1330,13 +1329,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13301329
.at(&ObligationCause::dummy(), param_env)
13311330
.eq(opaque_decl.concrete_ty, renumbered_opaque_defn_ty)?,
13321331
);
1333-
opaque_type_values.insert(
1334-
opaque_type_key,
1335-
ty::ResolvedOpaqueTy {
1336-
concrete_type: renumbered_opaque_defn_ty,
1337-
substs: opaque_decl.substs,
1338-
},
1339-
);
1332+
opaque_type_values.insert(opaque_type_key, renumbered_opaque_defn_ty);
13401333
} else {
13411334
// We're using an opaque `impl Trait` type without
13421335
// 'revealing' it. For example, code like this:

compiler/rustc_typeck/src/check/writeback.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -522,24 +522,21 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
522522
// in some other location, or we'll end up emitting an error due
523523
// to the lack of defining usage
524524
if !skip_add {
525-
let new = ty::ResolvedOpaqueTy {
526-
concrete_type: definition_ty,
527-
substs: opaque_defn.substs,
528-
};
529-
530525
let opaque_type_key = OpaqueTypeKey { def_id, substs: opaque_defn.substs };
531-
let old =
532-
self.typeck_results.concrete_opaque_types.insert(opaque_type_key, new);
533-
if let Some(old) = old {
534-
if old.concrete_type != definition_ty || old.substs != opaque_defn.substs {
526+
let old_concrete_ty = self
527+
.typeck_results
528+
.concrete_opaque_types
529+
.insert(opaque_type_key, definition_ty);
530+
if let Some(old_concrete_ty) = old_concrete_ty {
531+
if old_concrete_ty != definition_ty {
535532
span_bug!(
536533
span,
537534
"`visit_opaque_types` tried to write different types for the same \
538535
opaque type: {:?}, {:?}, {:?}, {:?}",
539536
def_id,
540537
definition_ty,
541538
opaque_defn,
542-
old,
539+
old_concrete_ty,
543540
);
544541
}
545542
}

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use rustc_hir::{HirId, Node};
1010
use rustc_middle::hir::map::Map;
1111
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
1212
use rustc_middle::ty::util::IntTypeExt;
13-
use rustc_middle::ty::{
14-
self, DefIdTree, OpaqueTypeKey, ResolvedOpaqueTy, Ty, TyCtxt, TypeFoldable,
15-
};
13+
use rustc_middle::ty::{self, DefIdTree, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
1614
use rustc_span::symbol::Ident;
1715
use rustc_span::{Span, DUMMY_SP};
1816

@@ -353,7 +351,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
353351
&tcx.mir_borrowck(owner.expect_local()).concrete_opaque_types,
354352
def_id.to_def_id(),
355353
)
356-
.map(|opaque| opaque.concrete_type)
354+
.map(|&(_, concrete_ty)| concrete_ty)
357355
.unwrap_or_else(|| {
358356
tcx.sess.delay_span_bug(
359357
DUMMY_SP,
@@ -531,14 +529,13 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
531529
return;
532530
}
533531
// Use borrowck to get the type with unerased regions.
534-
let ty = find_concrete_ty_from_def_id(
535-
&self.tcx.mir_borrowck(def_id).concrete_opaque_types,
536-
self.def_id,
537-
);
538-
if let Some(ty::ResolvedOpaqueTy { concrete_type, substs }) = ty {
532+
let concrete_opaque_types = &self.tcx.mir_borrowck(def_id).concrete_opaque_types;
533+
if let Some((opaque_type_key, concrete_type)) =
534+
find_concrete_ty_from_def_id(concrete_opaque_types, self.def_id)
535+
{
539536
debug!(
540537
"find_opaque_ty_constraints: found constraint for `{:?}` at `{:?}`: {:?}",
541-
self.def_id, def_id, ty,
538+
self.def_id, def_id, concrete_type,
542539
);
543540

544541
// FIXME(oli-obk): trace the actual span from inference to improve errors.
@@ -549,7 +546,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
549546
// using `delay_span_bug`, just in case `wfcheck` slips up.
550547
let opaque_generics = self.tcx.generics_of(self.def_id);
551548
let mut used_params: FxHashSet<_> = FxHashSet::default();
552-
for (i, arg) in substs.iter().enumerate() {
549+
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
553550
let arg_is_param = match arg.unpack() {
554551
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
555552
GenericArgKind::Lifetime(lt) => {
@@ -710,7 +707,7 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty
710707
let owner_typeck_results = tcx.typeck(scope_def_id);
711708
let concrete_ty =
712709
find_concrete_ty_from_def_id(&owner_typeck_results.concrete_opaque_types, opaque_ty_def_id)
713-
.map(|opaque| opaque.concrete_type)
710+
.map(|&(_, concrete_ty)| concrete_ty)
714711
.unwrap_or_else(|| {
715712
tcx.sess.delay_span_bug(
716713
DUMMY_SP,
@@ -808,11 +805,8 @@ fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
808805
}
809806

810807
fn find_concrete_ty_from_def_id<'tcx>(
811-
concrete_opaque_types: &'tcx VecMap<OpaqueTypeKey<'tcx>, ResolvedOpaqueTy<'tcx>>,
808+
concrete_opaque_types: &'tcx VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
812809
def_id: DefId,
813-
) -> Option<&'tcx ResolvedOpaqueTy<'tcx>> {
814-
concrete_opaque_types
815-
.iter()
816-
.find(|(opaque_type_key, _)| opaque_type_key.def_id == def_id)
817-
.map(|(_, resolved_opaque_ty)| resolved_opaque_ty)
810+
) -> Option<&'tcx (OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
811+
concrete_opaque_types.iter().find(|(opaque_type_key, _)| opaque_type_key.def_id == def_id)
818812
}

0 commit comments

Comments
 (0)