Skip to content

Commit f07412d

Browse files
committed
Destructure OpaqueTypeKey in certain cases to simplify code
1 parent 1278f3f commit f07412d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Diff for: compiler/rustc_typeck/src/check/check.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::ty::fold::TypeFoldable;
1616
use rustc_middle::ty::layout::MAX_SIMD_LANES;
1717
use rustc_middle::ty::subst::GenericArgKind;
1818
use rustc_middle::ty::util::{Discr, IntTypeExt};
19-
use rustc_middle::ty::{self, ParamEnv, RegionKind, Ty, TyCtxt};
19+
use rustc_middle::ty::{self, OpaqueTypeKey, ParamEnv, RegionKind, Ty, TyCtxt};
2020
use rustc_session::lint::builtin::UNINHABITED_STATIC;
2121
use rustc_span::symbol::sym;
2222
use rustc_span::{self, MultiSpan, Span};
@@ -716,11 +716,11 @@ fn check_opaque_meets_bounds<'tcx>(
716716
infcx.instantiate_opaque_types(def_id, hir_id, param_env, opaque_ty, span),
717717
);
718718

719-
for (opaque_type_key, opaque_defn) in opaque_type_map {
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_type_key.substs),
723-
) {
719+
for (OpaqueTypeKey { def_id, substs }, opaque_defn) in opaque_type_map {
720+
match infcx
721+
.at(&misc_cause, param_env)
722+
.eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, substs))
723+
{
724724
Ok(infer_ok) => inh.register_infer_ok_obligations(infer_ok),
725725
Err(ty_err) => tcx.sess.delay_span_bug(
726726
opaque_defn.definition_span,

Diff for: compiler/rustc_typeck/src/check/writeback.rs

+8-7
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, Ty, TyCtxt};
18+
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
1919
use rustc_span::symbol::sym;
2020
use rustc_span::Span;
2121
use rustc_trait_selection::opaque_types::InferCtxtExt;
@@ -475,9 +475,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
475475
}
476476

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

483484
debug_assert!(!instantiated_ty.has_escaping_bound_vars());
@@ -505,7 +506,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
505506
if let ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() {
506507
if let hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias = opaque_defn.origin
507508
{
508-
if opaque_type_key.def_id == defin_ty_def_id {
509+
if def_id == defin_ty_def_id {
509510
debug!(
510511
"skipping adding concrete definition for opaque type {:?} {:?}",
511512
opaque_defn, defin_ty_def_id
@@ -515,7 +516,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
515516
}
516517
}
517518

518-
if !opaque_type_key.substs.needs_infer() {
519+
if !substs.needs_infer() {
519520
// We only want to add an entry into `concrete_opaque_types`
520521
// if we actually found a defining usage of this opaque type.
521522
// Otherwise, we do nothing - we'll either find a defining usage
@@ -532,7 +533,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
532533
span,
533534
"`visit_opaque_types` tried to write different types for the same \
534535
opaque type: {:?}, {:?}, {:?}, {:?}",
535-
opaque_type_key.def_id,
536+
def_id,
536537
definition_ty,
537538
opaque_defn,
538539
old_concrete_ty,

0 commit comments

Comments
 (0)