Pull opaque type handling out of the type relating delegate
This commit is contained in:
parent
1481fd964b
commit
14caf7396d
@ -1,6 +1,6 @@
|
|||||||
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
|
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
|
||||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::PredicateObligations;
|
||||||
use rustc_middle::mir::ConstraintCategory;
|
use rustc_middle::mir::ConstraintCategory;
|
||||||
use rustc_middle::ty::error::TypeError;
|
use rustc_middle::ty::error::TypeError;
|
||||||
use rustc_middle::ty::relate::TypeRelation;
|
use rustc_middle::ty::relate::TypeRelation;
|
||||||
@ -155,27 +155,16 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_opaque_type(
|
fn register_opaque_type_obligations(
|
||||||
&mut self,
|
&mut self,
|
||||||
a: Ty<'tcx>,
|
obligations: PredicateObligations<'tcx>,
|
||||||
b: Ty<'tcx>,
|
|
||||||
a_is_expected: bool,
|
|
||||||
) -> Result<(), TypeError<'tcx>> {
|
) -> Result<(), TypeError<'tcx>> {
|
||||||
let param_env = self.param_env();
|
|
||||||
let span = self.span();
|
|
||||||
let def_id = self.type_checker.body.source.def_id().expect_local();
|
|
||||||
let body_id = self.type_checker.tcx().hir().local_def_id_to_hir_id(def_id);
|
|
||||||
let cause = ObligationCause::misc(span, body_id);
|
|
||||||
self.type_checker
|
self.type_checker
|
||||||
.fully_perform_op(
|
.fully_perform_op(
|
||||||
self.locations,
|
self.locations,
|
||||||
self.category,
|
self.category,
|
||||||
InstantiateOpaqueType {
|
InstantiateOpaqueType {
|
||||||
obligations: self
|
obligations,
|
||||||
.type_checker
|
|
||||||
.infcx
|
|
||||||
.handle_opaque_type(a, b, a_is_expected, &cause, param_env)?
|
|
||||||
.obligations,
|
|
||||||
// These fields are filled in during execution of the operation
|
// These fields are filled in during execution of the operation
|
||||||
base_universe: None,
|
base_universe: None,
|
||||||
region_constraints: None,
|
region_constraints: None,
|
||||||
|
@ -16,8 +16,8 @@ use crate::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelating
|
|||||||
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
|
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
|
||||||
use crate::infer::{InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
|
use crate::infer::{InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
|
||||||
use crate::traits::query::{Fallible, NoSolution};
|
use crate::traits::query::{Fallible, NoSolution};
|
||||||
use crate::traits::TraitEngine;
|
|
||||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
||||||
|
use crate::traits::{PredicateObligations, TraitEngine};
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
@ -509,7 +509,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
for &(a, b) in &query_response.value.opaque_types {
|
for &(a, b) in &query_response.value.opaque_types {
|
||||||
let a = substitute_value(self.tcx, &result_subst, a);
|
let a = substitute_value(self.tcx, &result_subst, a);
|
||||||
let b = substitute_value(self.tcx, &result_subst, b);
|
let b = substitute_value(self.tcx, &result_subst, b);
|
||||||
obligations.extend(self.handle_opaque_type(a, b, true, cause, param_env)?.obligations);
|
obligations.extend(self.at(cause, param_env).eq(a, b)?.obligations);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(InferOk { value: result_subst, obligations })
|
Ok(InferOk { value: result_subst, obligations })
|
||||||
@ -741,17 +741,11 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_opaque_type(
|
fn register_opaque_type_obligations(
|
||||||
&mut self,
|
&mut self,
|
||||||
a: Ty<'tcx>,
|
obligations: PredicateObligations<'tcx>,
|
||||||
b: Ty<'tcx>,
|
|
||||||
a_is_expected: bool,
|
|
||||||
) -> Result<(), TypeError<'tcx>> {
|
) -> Result<(), TypeError<'tcx>> {
|
||||||
self.obligations.extend(
|
self.obligations.extend(obligations);
|
||||||
self.infcx
|
|
||||||
.handle_opaque_type(a, b, a_is_expected, &self.cause, self.param_env)?
|
|
||||||
.obligations,
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,9 @@ use crate::infer::combine::ConstEquateRelation;
|
|||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::infer::{ConstVarValue, ConstVariableValue};
|
use crate::infer::{ConstVarValue, ConstVariableValue};
|
||||||
use crate::infer::{TypeVariableOrigin, TypeVariableOriginKind};
|
use crate::infer::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
|
use crate::traits::PredicateObligation;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::error::TypeError;
|
use rustc_middle::ty::error::TypeError;
|
||||||
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
|
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
|
||||||
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
||||||
@ -91,11 +93,9 @@ pub trait TypeRelatingDelegate<'tcx> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fn const_equate(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>);
|
fn const_equate(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>);
|
||||||
fn register_opaque_type(
|
fn register_opaque_type_obligations(
|
||||||
&mut self,
|
&mut self,
|
||||||
a: Ty<'tcx>,
|
obligations: Vec<PredicateObligation<'tcx>>,
|
||||||
b: Ty<'tcx>,
|
|
||||||
a_is_expected: bool,
|
|
||||||
) -> Result<(), TypeError<'tcx>>;
|
) -> Result<(), TypeError<'tcx>>;
|
||||||
|
|
||||||
/// Creates a new universe index. Used when instantiating placeholders.
|
/// Creates a new universe index. Used when instantiating placeholders.
|
||||||
@ -414,7 +414,12 @@ where
|
|||||||
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
|
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
self.delegate.register_opaque_type(a, b, true)?;
|
let cause = ObligationCause::dummy_with_span(self.delegate.span());
|
||||||
|
let obligations = self
|
||||||
|
.infcx
|
||||||
|
.handle_opaque_type(a, b, true, &cause, self.delegate.param_env())?
|
||||||
|
.obligations;
|
||||||
|
self.delegate.register_opaque_type_obligations(obligations)?;
|
||||||
trace!(a = ?a.kind(), b = ?b.kind(), "opaque type instantiated");
|
trace!(a = ?a.kind(), b = ?b.kind(), "opaque type instantiated");
|
||||||
Ok(a)
|
Ok(a)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user