Skip to content

Commit 5dabd55

Browse files
committed
Use substs from opaque type key instead of using it from opaque_decl
1 parent 37ab718 commit 5dabd55

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,28 +1283,25 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12831283
);
12841284

12851285
for &(opaque_type_key, opaque_decl) in &opaque_type_map {
1286-
let opaque_def_id = opaque_type_key.def_id;
12871286
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
12881287
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
1289-
*def_id == opaque_def_id
1288+
*def_id == opaque_type_key.def_id
12901289
} else {
12911290
false
12921291
};
12931292

1294-
let opaque_type_key =
1295-
OpaqueTypeKey { def_id: opaque_def_id, substs: opaque_decl.substs };
12961293
let concrete_ty = match concrete_opaque_types
12971294
.iter()
1298-
.find(|(opaque_type_key, _)| opaque_type_key.def_id == opaque_def_id)
1299-
.map(|(_, concrete_ty)| concrete_ty)
1295+
.find(|(key, _)| key.def_id == opaque_type_key.def_id)
1296+
.map(|(_, ty)| ty)
13001297
{
13011298
None => {
13021299
if !concrete_is_opaque {
13031300
tcx.sess.delay_span_bug(
13041301
body.span,
13051302
&format!(
13061303
"Non-defining use of {:?} with revealed type",
1307-
opaque_def_id,
1304+
opaque_type_key.def_id,
13081305
),
13091306
);
13101307
}
@@ -1313,7 +1310,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13131310
Some(concrete_ty) => concrete_ty,
13141311
};
13151312
debug!("concrete_ty = {:?}", concrete_ty);
1316-
let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_decl.substs);
1313+
let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_type_key.substs);
13171314
let renumbered_opaque_defn_ty =
13181315
renumber::renumber_regions(infcx, subst_opaque_defn_ty);
13191316

@@ -1353,7 +1350,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13531350
// gets 'revealed' into
13541351
debug!(
13551352
"eq_opaque_type_and_type: non-defining use of {:?}",
1356-
opaque_def_id,
1353+
opaque_type_key.def_id,
13571354
);
13581355
}
13591356
}
@@ -1379,14 +1376,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13791376
// instantiated it with).
13801377
if let Some(opaque_type_map) = opaque_type_map {
13811378
for (opaque_type_key, opaque_decl) in opaque_type_map {
1382-
let opaque_def_id = opaque_type_key.def_id;
13831379
self.fully_perform_op(
13841380
locations,
13851381
ConstraintCategory::OpaqueType,
13861382
CustomTypeOp::new(
13871383
|_cx| {
13881384
infcx.constrain_opaque_type(
1389-
opaque_def_id,
1385+
opaque_type_key.def_id,
13901386
&opaque_decl,
13911387
GenerateMemberConstraints::IfNoStaticBound,
13921388
universal_region_relations,

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
371371
debug!("constrain_opaque_types()");
372372

373373
for &(opaque_type_key, opaque_defn) in opaque_types {
374-
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
375374
self.constrain_opaque_type(
376-
def_id,
375+
opaque_type_key.def_id,
377376
&opaque_defn,
378377
GenerateMemberConstraints::WhenRequired,
379378
free_region_relations,

compiler/rustc_typeck/src/check/check.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,10 @@ fn check_opaque_meets_bounds<'tcx>(
717717
);
718718

719719
for (opaque_type_key, opaque_defn) in opaque_type_map {
720-
let def_id = opaque_type_key.def_id;
721-
match infcx
722-
.at(&misc_cause, param_env)
723-
.eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, opaque_defn.substs))
724-
{
720+
match infcx.at(&misc_cause, param_env).eq(
721+
opaque_defn.concrete_ty,
722+
tcx.type_of(opaque_type_key.def_id).subst(tcx, opaque_defn.substs),
723+
) {
725724
Ok(infer_ok) => inh.register_infer_ok_obligations(infer_ok),
726725
Err(ty_err) => tcx.sess.delay_span_bug(
727726
opaque_defn.definition_span,

compiler/rustc_typeck/src/check/writeback.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::hir::place::Place as HirPlace;
1515
use rustc_middle::mir::FakeReadCause;
1616
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
1717
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
18-
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
18+
use rustc_middle::ty::{self, Ty, TyCtxt};
1919
use rustc_span::symbol::sym;
2020
use rustc_span::Span;
2121
use rustc_trait_selection::opaque_types::InferCtxtExt;
@@ -476,8 +476,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
476476

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

483483
debug_assert!(!instantiated_ty.has_escaping_bound_vars());
@@ -494,7 +494,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
494494
// fn foo<U>() -> Foo<U> { .. }
495495
// ```
496496
// figures out the concrete type with `U`, but the stored type is with `T`.
497-
let opaque_type_key = OpaqueTypeKey { def_id, substs: opaque_defn.substs };
498497
let definition_ty = self.fcx.infer_opaque_definition_from_instantiation(
499498
opaque_type_key,
500499
instantiated_ty,
@@ -506,7 +505,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
506505
if let ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() {
507506
if let hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias = opaque_defn.origin
508507
{
509-
if def_id == defin_ty_def_id {
508+
if opaque_type_key.def_id == defin_ty_def_id {
510509
debug!(
511510
"skipping adding concrete definition for opaque type {:?} {:?}",
512511
opaque_defn, defin_ty_def_id
@@ -516,14 +515,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
516515
}
517516
}
518517

519-
if !opaque_defn.substs.needs_infer() {
518+
if !opaque_type_key.substs.needs_infer() {
520519
// We only want to add an entry into `concrete_opaque_types`
521520
// if we actually found a defining usage of this opaque type.
522521
// Otherwise, we do nothing - we'll either find a defining usage
523522
// in some other location, or we'll end up emitting an error due
524523
// to the lack of defining usage
525524
if !skip_add {
526-
let opaque_type_key = OpaqueTypeKey { def_id, substs: opaque_defn.substs };
527525
let old_concrete_ty = self
528526
.typeck_results
529527
.concrete_opaque_types
@@ -534,7 +532,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
534532
span,
535533
"`visit_opaque_types` tried to write different types for the same \
536534
opaque type: {:?}, {:?}, {:?}, {:?}",
537-
def_id,
535+
opaque_type_key.def_id,
538536
definition_ty,
539537
opaque_defn,
540538
old_concrete_ty,

0 commit comments

Comments
 (0)