Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create different inference variables for different defining uses of TAITs #86118

Merged
merged 18 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::layout::MAX_SIMD_LANES;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, ParamEnv, RegionKind, Ty, TyCtxt};
use rustc_middle::ty::{self, OpaqueTypeKey, ParamEnv, RegionKind, Ty, TyCtxt};
use rustc_session::lint::builtin::UNINHABITED_STATIC;
use rustc_span::symbol::sym;
use rustc_span::{self, MultiSpan, Span};
Expand Down Expand Up @@ -716,11 +716,11 @@ fn check_opaque_meets_bounds<'tcx>(
infcx.instantiate_opaque_types(def_id, hir_id, param_env, opaque_ty, span),
);

for (opaque_type_key, opaque_defn) in opaque_type_map {
match infcx.at(&misc_cause, param_env).eq(
opaque_defn.concrete_ty,
tcx.type_of(opaque_type_key.def_id).subst(tcx, opaque_type_key.substs),
) {
for (OpaqueTypeKey { def_id, substs }, opaque_defn) in opaque_type_map {
match infcx
.at(&misc_cause, param_env)
.eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, substs))
{
Ok(infer_ok) => inh.register_infer_ok_obligations(infer_ok),
Err(ty_err) => tcx.sess.delay_span_bug(
opaque_defn.definition_span,
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Ty, TyCtxt};
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_trait_selection::opaque_types::InferCtxtExt;
Expand Down Expand Up @@ -475,9 +475,10 @@ 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 hir_id =
self.tcx().hir().local_def_id_to_hir_id(opaque_type_key.def_id.expect_local());
for &(opaque_type_key @ OpaqueTypeKey { def_id, substs }, opaque_defn) in
spastorino marked this conversation as resolved.
Show resolved Hide resolved
self.fcx.opaque_types.borrow().iter()
{
let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local());
let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id);

debug_assert!(!instantiated_ty.has_escaping_bound_vars());
Expand Down Expand Up @@ -505,7 +506,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 opaque_type_key.def_id == defin_ty_def_id {
if def_id == defin_ty_def_id {
spastorino marked this conversation as resolved.
Show resolved Hide resolved
debug!(
"skipping adding concrete definition for opaque type {:?} {:?}",
opaque_defn, defin_ty_def_id
Expand All @@ -515,7 +516,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
}
}

if !opaque_type_key.substs.needs_infer() {
if !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
Expand All @@ -532,7 +533,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
span,
"`visit_opaque_types` tried to write different types for the same \
opaque type: {:?}, {:?}, {:?}, {:?}",
opaque_type_key.def_id,
def_id,
definition_ty,
opaque_defn,
old_concrete_ty,
Expand Down