propagate other obligations that were left out
cc #32730 -- I left exactly one instance where I wasn't sure of the right behavior.
This commit is contained in:
parent
aa6c2b1cb7
commit
93e10977d8
7 changed files with 40 additions and 22 deletions
|
@ -1597,9 +1597,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
// generic so we don't have to do anything quite this
|
// generic so we don't have to do anything quite this
|
||||||
// terrible.
|
// terrible.
|
||||||
let trace = TypeTrace::dummy(self.tcx);
|
let trace = TypeTrace::dummy(self.tcx);
|
||||||
self.equate(true, trace, a, b).map(|InferOk { obligations, .. }| {
|
self.equate(true, trace, a, b).map(|InferOk { obligations: _, .. }| {
|
||||||
// FIXME(#32730) propagate obligations
|
// We can intentionally ignore obligations here, since
|
||||||
assert!(obligations.is_empty());
|
// this is part of a simple test for general
|
||||||
|
// "equatability". However, it's not entirely clear
|
||||||
|
// that we *ought* to be, perhaps a better thing would
|
||||||
|
// be to use a mini-fulfillment context or something
|
||||||
|
// like that.
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,16 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn register_predicate_obligations(&mut self,
|
||||||
|
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||||
|
obligations: Vec<PredicateObligation<'tcx>>)
|
||||||
|
{
|
||||||
|
for obligation in obligations {
|
||||||
|
self.register_predicate_obligation(infcx, obligation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn region_obligations(&self,
|
pub fn region_obligations(&self,
|
||||||
body_id: ast::NodeId)
|
body_id: ast::NodeId)
|
||||||
-> &[RegionObligation<'tcx>]
|
-> &[RegionObligation<'tcx>]
|
||||||
|
|
|
@ -218,7 +218,7 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||||
-> Result<&'tcx Substs<'tcx>, ()> {
|
-> Result<&'tcx Substs<'tcx>, ()> {
|
||||||
let selcx = &mut SelectionContext::new(&infcx);
|
let selcx = &mut SelectionContext::new(&infcx);
|
||||||
let target_substs = infcx.fresh_substs_for_item(DUMMY_SP, target_impl);
|
let target_substs = infcx.fresh_substs_for_item(DUMMY_SP, target_impl);
|
||||||
let (target_trait_ref, obligations) = impl_trait_ref_and_oblig(selcx,
|
let (target_trait_ref, mut obligations) = impl_trait_ref_and_oblig(selcx,
|
||||||
target_impl,
|
target_impl,
|
||||||
target_substs);
|
target_substs);
|
||||||
|
|
||||||
|
@ -227,9 +227,8 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||||
&ObligationCause::dummy(),
|
&ObligationCause::dummy(),
|
||||||
source_trait_ref,
|
source_trait_ref,
|
||||||
target_trait_ref) {
|
target_trait_ref) {
|
||||||
Ok(InferOk { obligations, .. }) => {
|
Ok(InferOk { obligations: o, .. }) => {
|
||||||
// FIXME(#32730) propagate obligations
|
obligations.extend(o);
|
||||||
assert!(obligations.is_empty())
|
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!("fulfill_implication: {:?} does not unify with {:?}",
|
debug!("fulfill_implication: {:?} does not unify with {:?}",
|
||||||
|
|
|
@ -376,7 +376,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||||
pub fn check_sub(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) {
|
pub fn check_sub(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) {
|
||||||
match self.sub(t1, t2) {
|
match self.sub(t1, t2) {
|
||||||
Ok(InferOk { obligations, .. }) => {
|
Ok(InferOk { obligations, .. }) => {
|
||||||
// FIXME(#32730) once obligations are being propagated, assert the right thing.
|
// None of these tests should require nested obligations:
|
||||||
assert!(obligations.is_empty());
|
assert!(obligations.is_empty());
|
||||||
}
|
}
|
||||||
Err(ref e) => {
|
Err(ref e) => {
|
||||||
|
@ -400,7 +400,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||||
pub fn check_lub(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_lub: Ty<'tcx>) {
|
pub fn check_lub(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_lub: Ty<'tcx>) {
|
||||||
match self.lub(t1, t2) {
|
match self.lub(t1, t2) {
|
||||||
Ok(InferOk { obligations, value: t }) => {
|
Ok(InferOk { obligations, value: t }) => {
|
||||||
// FIXME(#32730) once obligations are being propagated, assert the right thing.
|
// None of these tests should require nested obligations:
|
||||||
assert!(obligations.is_empty());
|
assert!(obligations.is_empty());
|
||||||
|
|
||||||
self.assert_eq(t, t_lub);
|
self.assert_eq(t, t_lub);
|
||||||
|
@ -415,7 +415,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||||
match self.glb(t1, t2) {
|
match self.glb(t1, t2) {
|
||||||
Err(e) => panic!("unexpected error computing LUB: {:?}", e),
|
Err(e) => panic!("unexpected error computing LUB: {:?}", e),
|
||||||
Ok(InferOk { obligations, value: t }) => {
|
Ok(InferOk { obligations, value: t }) => {
|
||||||
// FIXME(#32730) once obligations are being propagated, assert the right thing.
|
// None of these tests should require nested obligations:
|
||||||
assert!(obligations.is_empty());
|
assert!(obligations.is_empty());
|
||||||
|
|
||||||
self.assert_eq(t, t_glb);
|
self.assert_eq(t, t_glb);
|
||||||
|
|
|
@ -294,10 +294,9 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
debug!("compare_impl_method: trait_fty={:?}", trait_fty);
|
debug!("compare_impl_method: trait_fty={:?}", trait_fty);
|
||||||
|
|
||||||
let sub_result = infcx.sub_types(false, &cause, impl_fty, trait_fty)
|
let sub_result = infcx.sub_types(false, &cause, impl_fty, trait_fty)
|
||||||
.map(|InferOk { obligations, .. }| {
|
.map(|InferOk { obligations, .. }| {
|
||||||
// FIXME(#32730) propagate obligations
|
inh.register_predicates(obligations);
|
||||||
assert!(obligations.is_empty());
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if let Err(terr) = sub_result {
|
if let Err(terr) = sub_result {
|
||||||
debug!("sub_types failed: impl ty {:?}, trait ty {:?}",
|
debug!("sub_types failed: impl ty {:?}, trait ty {:?}",
|
||||||
|
|
|
@ -82,7 +82,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
|
||||||
// check that the impl type can be made to match the trait type.
|
// check that the impl type can be made to match the trait type.
|
||||||
|
|
||||||
let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id);
|
let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id);
|
||||||
tcx.infer_ctxt(impl_param_env, Reveal::UserFacing).enter(|infcx| {
|
tcx.infer_ctxt(impl_param_env, Reveal::UserFacing).enter(|ref infcx| {
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
let mut fulfillment_cx = traits::FulfillmentContext::new();
|
let mut fulfillment_cx = traits::FulfillmentContext::new();
|
||||||
|
|
||||||
|
@ -97,8 +97,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
|
||||||
let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id);
|
let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id);
|
||||||
match infcx.eq_types(true, cause, named_type, fresh_impl_self_ty) {
|
match infcx.eq_types(true, cause, named_type, fresh_impl_self_ty) {
|
||||||
Ok(InferOk { obligations, .. }) => {
|
Ok(InferOk { obligations, .. }) => {
|
||||||
// FIXME(#32730) propagate obligations
|
fulfillment_cx.register_predicate_obligations(infcx, obligations);
|
||||||
assert!(obligations.is_empty());
|
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let item_span = tcx.hir.span(self_type_node_id);
|
let item_span = tcx.hir.span(self_type_node_id);
|
||||||
|
|
|
@ -109,7 +109,7 @@ use rustc::infer::InferOk;
|
||||||
use rustc::ty::subst::Substs;
|
use rustc::ty::subst::Substs;
|
||||||
use rustc::ty::{self, Ty, TyCtxt};
|
use rustc::ty::{self, Ty, TyCtxt};
|
||||||
use rustc::ty::maps::Providers;
|
use rustc::ty::maps::Providers;
|
||||||
use rustc::traits::{ObligationCause, ObligationCauseCode, Reveal};
|
use rustc::traits::{FulfillmentContext, ObligationCause, ObligationCauseCode, Reveal};
|
||||||
use session::config;
|
use session::config;
|
||||||
use util::common::time;
|
use util::common::time;
|
||||||
|
|
||||||
|
@ -153,15 +153,22 @@ fn require_same_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
actual: Ty<'tcx>)
|
actual: Ty<'tcx>)
|
||||||
-> bool {
|
-> bool {
|
||||||
tcx.infer_ctxt((), Reveal::UserFacing).enter(|infcx| {
|
tcx.infer_ctxt((), Reveal::UserFacing).enter(|ref infcx| {
|
||||||
|
let mut fulfill_cx = FulfillmentContext::new();
|
||||||
match infcx.eq_types(false, &cause, expected, actual) {
|
match infcx.eq_types(false, &cause, expected, actual) {
|
||||||
Ok(InferOk { obligations, .. }) => {
|
Ok(InferOk { obligations, .. }) => {
|
||||||
// FIXME(#32730) propagate obligations
|
fulfill_cx.register_predicate_obligations(infcx, obligations);
|
||||||
assert!(obligations.is_empty());
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
infcx.report_mismatched_types(cause, expected, actual, err).emit();
|
infcx.report_mismatched_types(cause, expected, actual, err).emit();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match fulfill_cx.select_all_or_error(infcx) {
|
||||||
|
Ok(()) => true,
|
||||||
|
Err(errors) => {
|
||||||
|
infcx.report_fulfillment_errors(&errors);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue