diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 3476c94b797d..e03ae3869ef3 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -1283,20 +1283,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); for &(opaque_type_key, opaque_decl) in &opaque_type_map { - let opaque_def_id = opaque_type_key.def_id; let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty); let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() { - *def_id == opaque_def_id + *def_id == opaque_type_key.def_id } else { false }; - let opaque_type_key = - OpaqueTypeKey { def_id: opaque_def_id, substs: opaque_decl.substs }; let concrete_ty = match concrete_opaque_types .iter() - .find(|(opaque_type_key, _)| opaque_type_key.def_id == opaque_def_id) - .map(|(_, concrete_ty)| concrete_ty) + .find(|(key, _)| key.def_id == opaque_type_key.def_id) + .map(|(_, ty)| ty) { None => { if !concrete_is_opaque { @@ -1304,7 +1301,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { body.span, &format!( "Non-defining use of {:?} with revealed type", - opaque_def_id, + opaque_type_key.def_id, ), ); } @@ -1313,7 +1310,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Some(concrete_ty) => concrete_ty, }; debug!("concrete_ty = {:?}", concrete_ty); - let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_decl.substs); + let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_type_key.substs); let renumbered_opaque_defn_ty = renumber::renumber_regions(infcx, subst_opaque_defn_ty); @@ -1353,7 +1350,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // gets 'revealed' into debug!( "eq_opaque_type_and_type: non-defining use of {:?}", - opaque_def_id, + opaque_type_key.def_id, ); } } @@ -1379,14 +1376,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // instantiated it with). if let Some(opaque_type_map) = opaque_type_map { for (opaque_type_key, opaque_decl) in opaque_type_map { - let opaque_def_id = opaque_type_key.def_id; self.fully_perform_op( locations, ConstraintCategory::OpaqueType, CustomTypeOp::new( |_cx| { infcx.constrain_opaque_type( - opaque_def_id, + opaque_type_key.def_id, &opaque_decl, GenerateMemberConstraints::IfNoStaticBound, universal_region_relations, diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 6137521c4c13..9bb08503712f 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -371,9 +371,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { debug!("constrain_opaque_types()"); for &(opaque_type_key, opaque_defn) in opaque_types { - let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key; self.constrain_opaque_type( - def_id, + opaque_type_key.def_id, &opaque_defn, GenerateMemberConstraints::WhenRequired, free_region_relations, diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index e32561900de1..5df5fb7ea688 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -717,11 +717,10 @@ fn check_opaque_meets_bounds<'tcx>( ); for (opaque_type_key, opaque_defn) in opaque_type_map { - let def_id = opaque_type_key.def_id; - match infcx - .at(&misc_cause, param_env) - .eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, opaque_defn.substs)) - { + match infcx.at(&misc_cause, param_env).eq( + opaque_defn.concrete_ty, + tcx.type_of(opaque_type_key.def_id).subst(tcx, opaque_defn.substs), + ) { Ok(infer_ok) => inh.register_infer_ok_obligations(infer_ok), Err(ty_err) => tcx.sess.delay_span_bug( opaque_defn.definition_span, diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 07c33d007ccc..e8f606455f2a 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -15,7 +15,7 @@ use rustc_middle::hir::place::Place as HirPlace; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast}; use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; -use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::symbol::sym; use rustc_span::Span; use rustc_trait_selection::opaque_types::InferCtxtExt; @@ -476,8 +476,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn visit_opaque_types(&mut self, span: Span) { for &(opaque_type_key, opaque_defn) in self.fcx.opaque_types.borrow().iter() { - let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key; - let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local()); + let hir_id = + self.tcx().hir().local_def_id_to_hir_id(opaque_type_key.def_id.expect_local()); let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id); debug_assert!(!instantiated_ty.has_escaping_bound_vars()); @@ -494,7 +494,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // fn foo() -> Foo { .. } // ``` // figures out the concrete type with `U`, but the stored type is with `T`. - let opaque_type_key = OpaqueTypeKey { def_id, substs: opaque_defn.substs }; let definition_ty = self.fcx.infer_opaque_definition_from_instantiation( opaque_type_key, instantiated_ty, @@ -506,7 +505,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { if let ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() { if let hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias = opaque_defn.origin { - if def_id == defin_ty_def_id { + if opaque_type_key.def_id == defin_ty_def_id { debug!( "skipping adding concrete definition for opaque type {:?} {:?}", opaque_defn, defin_ty_def_id @@ -516,14 +515,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } } - if !opaque_defn.substs.needs_infer() { + if !opaque_type_key.substs.needs_infer() { // We only want to add an entry into `concrete_opaque_types` // if we actually found a defining usage of this opaque type. // Otherwise, we do nothing - we'll either find a defining usage // in some other location, or we'll end up emitting an error due // to the lack of defining usage if !skip_add { - let opaque_type_key = OpaqueTypeKey { def_id, substs: opaque_defn.substs }; let old_concrete_ty = self .typeck_results .concrete_opaque_types @@ -534,7 +532,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { span, "`visit_opaque_types` tried to write different types for the same \ opaque type: {:?}, {:?}, {:?}, {:?}", - def_id, + opaque_type_key.def_id, definition_ty, opaque_defn, old_concrete_ty,