Use substs from opaque type key instead of using it from opaque_decl
This commit is contained in:
parent
37ab718350
commit
5dabd55d7d
4 changed files with 18 additions and 26 deletions
|
@ -1283,20 +1283,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
for &(opaque_type_key, opaque_decl) in &opaque_type_map {
|
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 resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
|
||||||
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let opaque_type_key =
|
|
||||||
OpaqueTypeKey { def_id: opaque_def_id, substs: opaque_decl.substs };
|
|
||||||
let concrete_ty = match concrete_opaque_types
|
let concrete_ty = match concrete_opaque_types
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(opaque_type_key, _)| opaque_type_key.def_id == opaque_def_id)
|
.find(|(key, _)| key.def_id == opaque_type_key.def_id)
|
||||||
.map(|(_, concrete_ty)| concrete_ty)
|
.map(|(_, ty)| ty)
|
||||||
{
|
{
|
||||||
None => {
|
None => {
|
||||||
if !concrete_is_opaque {
|
if !concrete_is_opaque {
|
||||||
|
@ -1304,7 +1301,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
body.span,
|
body.span,
|
||||||
&format!(
|
&format!(
|
||||||
"Non-defining use of {:?} with revealed type",
|
"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,
|
Some(concrete_ty) => concrete_ty,
|
||||||
};
|
};
|
||||||
debug!("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 =
|
let renumbered_opaque_defn_ty =
|
||||||
renumber::renumber_regions(infcx, subst_opaque_defn_ty);
|
renumber::renumber_regions(infcx, subst_opaque_defn_ty);
|
||||||
|
|
||||||
|
@ -1353,7 +1350,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
// gets 'revealed' into
|
// gets 'revealed' into
|
||||||
debug!(
|
debug!(
|
||||||
"eq_opaque_type_and_type: non-defining use of {:?}",
|
"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).
|
// instantiated it with).
|
||||||
if let Some(opaque_type_map) = opaque_type_map {
|
if let Some(opaque_type_map) = opaque_type_map {
|
||||||
for (opaque_type_key, opaque_decl) in 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(
|
self.fully_perform_op(
|
||||||
locations,
|
locations,
|
||||||
ConstraintCategory::OpaqueType,
|
ConstraintCategory::OpaqueType,
|
||||||
CustomTypeOp::new(
|
CustomTypeOp::new(
|
||||||
|_cx| {
|
|_cx| {
|
||||||
infcx.constrain_opaque_type(
|
infcx.constrain_opaque_type(
|
||||||
opaque_def_id,
|
opaque_type_key.def_id,
|
||||||
&opaque_decl,
|
&opaque_decl,
|
||||||
GenerateMemberConstraints::IfNoStaticBound,
|
GenerateMemberConstraints::IfNoStaticBound,
|
||||||
universal_region_relations,
|
universal_region_relations,
|
||||||
|
|
|
@ -371,9 +371,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
debug!("constrain_opaque_types()");
|
debug!("constrain_opaque_types()");
|
||||||
|
|
||||||
for &(opaque_type_key, opaque_defn) in opaque_types {
|
for &(opaque_type_key, opaque_defn) in opaque_types {
|
||||||
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
|
|
||||||
self.constrain_opaque_type(
|
self.constrain_opaque_type(
|
||||||
def_id,
|
opaque_type_key.def_id,
|
||||||
&opaque_defn,
|
&opaque_defn,
|
||||||
GenerateMemberConstraints::WhenRequired,
|
GenerateMemberConstraints::WhenRequired,
|
||||||
free_region_relations,
|
free_region_relations,
|
||||||
|
|
|
@ -717,11 +717,10 @@ fn check_opaque_meets_bounds<'tcx>(
|
||||||
);
|
);
|
||||||
|
|
||||||
for (opaque_type_key, opaque_defn) in opaque_type_map {
|
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(
|
||||||
match infcx
|
opaque_defn.concrete_ty,
|
||||||
.at(&misc_cause, param_env)
|
tcx.type_of(opaque_type_key.def_id).subst(tcx, opaque_defn.substs),
|
||||||
.eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, opaque_defn.substs))
|
) {
|
||||||
{
|
|
||||||
Ok(infer_ok) => inh.register_infer_ok_obligations(infer_ok),
|
Ok(infer_ok) => inh.register_infer_ok_obligations(infer_ok),
|
||||||
Err(ty_err) => tcx.sess.delay_span_bug(
|
Err(ty_err) => tcx.sess.delay_span_bug(
|
||||||
opaque_defn.definition_span,
|
opaque_defn.definition_span,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_middle::hir::place::Place as HirPlace;
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
|
||||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
|
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::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::opaque_types::InferCtxtExt;
|
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) {
|
fn visit_opaque_types(&mut self, span: Span) {
|
||||||
for &(opaque_type_key, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
|
for &(opaque_type_key, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
|
||||||
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
|
let hir_id =
|
||||||
let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local());
|
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);
|
let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id);
|
||||||
|
|
||||||
debug_assert!(!instantiated_ty.has_escaping_bound_vars());
|
debug_assert!(!instantiated_ty.has_escaping_bound_vars());
|
||||||
|
@ -494,7 +494,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
// fn foo<U>() -> Foo<U> { .. }
|
// fn foo<U>() -> Foo<U> { .. }
|
||||||
// ```
|
// ```
|
||||||
// figures out the concrete type with `U`, but the stored type is with `T`.
|
// 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(
|
let definition_ty = self.fcx.infer_opaque_definition_from_instantiation(
|
||||||
opaque_type_key,
|
opaque_type_key,
|
||||||
instantiated_ty,
|
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 ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() {
|
||||||
if let hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias = opaque_defn.origin
|
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!(
|
debug!(
|
||||||
"skipping adding concrete definition for opaque type {:?} {:?}",
|
"skipping adding concrete definition for opaque type {:?} {:?}",
|
||||||
opaque_defn, defin_ty_def_id
|
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`
|
// We only want to add an entry into `concrete_opaque_types`
|
||||||
// if we actually found a defining usage of this opaque type.
|
// if we actually found a defining usage of this opaque type.
|
||||||
// Otherwise, we do nothing - we'll either find a defining usage
|
// Otherwise, we do nothing - we'll either find a defining usage
|
||||||
// in some other location, or we'll end up emitting an error due
|
// in some other location, or we'll end up emitting an error due
|
||||||
// to the lack of defining usage
|
// to the lack of defining usage
|
||||||
if !skip_add {
|
if !skip_add {
|
||||||
let opaque_type_key = OpaqueTypeKey { def_id, substs: opaque_defn.substs };
|
|
||||||
let old_concrete_ty = self
|
let old_concrete_ty = self
|
||||||
.typeck_results
|
.typeck_results
|
||||||
.concrete_opaque_types
|
.concrete_opaque_types
|
||||||
|
@ -534,7 +532,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
span,
|
span,
|
||||||
"`visit_opaque_types` tried to write different types for the same \
|
"`visit_opaque_types` tried to write different types for the same \
|
||||||
opaque type: {:?}, {:?}, {:?}, {:?}",
|
opaque type: {:?}, {:?}, {:?}, {:?}",
|
||||||
def_id,
|
opaque_type_key.def_id,
|
||||||
definition_ty,
|
definition_ty,
|
||||||
opaque_defn,
|
opaque_defn,
|
||||||
old_concrete_ty,
|
old_concrete_ty,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue