Rename trait_ref
field to predicate
, since trait_ref
is really
overly general, and the value is always *some* sort of predicate.
This commit is contained in:
parent
c5edd22646
commit
986f654f3b
@ -126,7 +126,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
|
||||
|
||||
let trait_obligation = Obligation { cause: cause,
|
||||
recursion_depth: 0,
|
||||
trait_ref: ty::Predicate::Trait(trait_ref) };
|
||||
predicate: ty::Predicate::Trait(trait_ref) };
|
||||
self.register_predicate(tcx, trait_obligation)
|
||||
}
|
||||
|
||||
@ -141,15 +141,15 @@ impl<'tcx> FulfillmentContext<'tcx> {
|
||||
|
||||
pub fn register_predicate<'a>(&mut self,
|
||||
tcx: &ty::ctxt<'tcx>,
|
||||
predicate: PredicateObligation<'tcx>)
|
||||
obligation: PredicateObligation<'tcx>)
|
||||
{
|
||||
if !self.duplicate_set.insert(predicate.trait_ref.clone()) {
|
||||
debug!("register_predicate({}) -- already seen, skip", predicate.repr(tcx));
|
||||
if !self.duplicate_set.insert(obligation.predicate.clone()) {
|
||||
debug!("register_predicate({}) -- already seen, skip", obligation.repr(tcx));
|
||||
return;
|
||||
}
|
||||
|
||||
debug!("register_predicate({})", predicate.repr(tcx));
|
||||
self.predicates.push(predicate);
|
||||
debug!("register_predicate({})", obligation.repr(tcx));
|
||||
self.predicates.push(obligation);
|
||||
}
|
||||
|
||||
pub fn region_obligations(&self,
|
||||
@ -289,7 +289,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
|
||||
predicate: &PredicateObligation<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
selections: &mut Vec<Selection<'tcx>>,
|
||||
errors: &mut Vec<FulfillmentError<'tcx>>,
|
||||
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>)
|
||||
@ -303,11 +303,9 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
|
||||
*/
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
match predicate.trait_ref {
|
||||
match obligation.predicate {
|
||||
ty::Predicate::Trait(ref trait_ref) => {
|
||||
let trait_obligation = Obligation { cause: predicate.cause.clone(),
|
||||
recursion_depth: predicate.recursion_depth,
|
||||
trait_ref: trait_ref.clone() };
|
||||
let trait_obligation = obligation.with(trait_ref.clone());
|
||||
match selcx.select(&trait_obligation) {
|
||||
Ok(None) => {
|
||||
false
|
||||
@ -318,11 +316,11 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
|
||||
}
|
||||
Err(selection_err) => {
|
||||
debug!("predicate: {} error: {}",
|
||||
predicate.repr(tcx),
|
||||
obligation.repr(tcx),
|
||||
selection_err.repr(tcx));
|
||||
errors.push(
|
||||
FulfillmentError::new(
|
||||
predicate.clone(),
|
||||
obligation.clone(),
|
||||
CodeSelectionError(selection_err)));
|
||||
true
|
||||
}
|
||||
@ -330,12 +328,12 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
|
||||
}
|
||||
|
||||
ty::Predicate::Equate(ref binder) => {
|
||||
match selcx.infcx().equality_predicate(predicate.cause.span, binder) {
|
||||
match selcx.infcx().equality_predicate(obligation.cause.span, binder) {
|
||||
Ok(()) => { }
|
||||
Err(_) => {
|
||||
errors.push(
|
||||
FulfillmentError::new(
|
||||
predicate.clone(),
|
||||
obligation.clone(),
|
||||
CodeSelectionError(Unimplemented)));
|
||||
}
|
||||
}
|
||||
@ -343,12 +341,12 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
|
||||
}
|
||||
|
||||
ty::Predicate::RegionOutlives(ref binder) => {
|
||||
match selcx.infcx().region_outlives_predicate(predicate.cause.span, binder) {
|
||||
match selcx.infcx().region_outlives_predicate(obligation.cause.span, binder) {
|
||||
Ok(()) => { }
|
||||
Err(_) => {
|
||||
errors.push(
|
||||
FulfillmentError::new(
|
||||
predicate.clone(),
|
||||
obligation.clone(),
|
||||
CodeSelectionError(Unimplemented)));
|
||||
}
|
||||
}
|
||||
@ -364,12 +362,12 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
|
||||
if ty::count_late_bound_regions(selcx.tcx(), binder) != 0 {
|
||||
errors.push(
|
||||
FulfillmentError::new(
|
||||
predicate.clone(),
|
||||
obligation.clone(),
|
||||
CodeSelectionError(Unimplemented)));
|
||||
} else {
|
||||
let ty::OutlivesPredicate(t_a, r_b) = binder.0;
|
||||
register_region_obligation(tcx, t_a, r_b,
|
||||
predicate.cause.clone(),
|
||||
obligation.cause.clone(),
|
||||
region_obligations);
|
||||
}
|
||||
true
|
||||
|
@ -53,7 +53,7 @@ mod util;
|
||||
pub struct Obligation<'tcx, T> {
|
||||
pub cause: ObligationCause<'tcx>,
|
||||
pub recursion_depth: uint,
|
||||
pub trait_ref: T,
|
||||
pub predicate: T,
|
||||
}
|
||||
|
||||
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
|
||||
@ -310,7 +310,7 @@ impl<'tcx,O> Obligation<'tcx,O> {
|
||||
{
|
||||
Obligation { cause: cause,
|
||||
recursion_depth: 0,
|
||||
trait_ref: trait_ref }
|
||||
predicate: trait_ref }
|
||||
}
|
||||
|
||||
pub fn misc(span: Span, body_id: ast::NodeId, trait_ref: O) -> Obligation<'tcx, O> {
|
||||
@ -320,13 +320,13 @@ impl<'tcx,O> Obligation<'tcx,O> {
|
||||
pub fn with<P>(&self, value: P) -> Obligation<'tcx,P> {
|
||||
Obligation { cause: self.cause.clone(),
|
||||
recursion_depth: self.recursion_depth,
|
||||
trait_ref: value }
|
||||
predicate: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TraitObligation<'tcx> {
|
||||
pub fn self_ty(&self) -> Ty<'tcx> {
|
||||
self.trait_ref.self_ty()
|
||||
self.predicate.self_ty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
pub fn select(&mut self, obligation: &TraitObligation<'tcx>)
|
||||
-> SelectionResult<'tcx, Selection<'tcx>> {
|
||||
debug!("select({})", obligation.repr(self.tcx()));
|
||||
assert!(!obligation.trait_ref.has_escaping_regions());
|
||||
assert!(!obligation.predicate.has_escaping_regions());
|
||||
|
||||
let stack = self.push_stack(None, obligation);
|
||||
match try!(self.candidate_from_obligation(&stack)) {
|
||||
@ -280,7 +280,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
debug!("evaluate_predicate_recursively({})",
|
||||
obligation.repr(self.tcx()));
|
||||
|
||||
match obligation.trait_ref {
|
||||
match obligation.predicate {
|
||||
ty::Predicate::Trait(ref t) => {
|
||||
assert!(!t.has_escaping_regions());
|
||||
let obligation = obligation.with(t.clone());
|
||||
@ -411,7 +411,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
|
||||
self.infcx.probe(|snapshot| {
|
||||
let (skol_obligation_trait_ref, skol_map) =
|
||||
self.infcx().skolemize_late_bound_regions(&*obligation.trait_ref, snapshot);
|
||||
self.infcx().skolemize_late_bound_regions(&*obligation.predicate, snapshot);
|
||||
match self.match_impl(impl_def_id, obligation, snapshot,
|
||||
&skol_map, Rc::new(skol_obligation_trait_ref)) {
|
||||
Ok(substs) => {
|
||||
@ -456,11 +456,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// is because we want the unbound variables to be replaced
|
||||
// with fresh skolemized types starting from index 0.
|
||||
let cache_fresh_trait_ref =
|
||||
self.infcx.freshen(stack.obligation.trait_ref.clone());
|
||||
self.infcx.freshen(stack.obligation.predicate.clone());
|
||||
debug!("candidate_from_obligation(cache_fresh_trait_ref={}, obligation={})",
|
||||
cache_fresh_trait_ref.repr(self.tcx()),
|
||||
stack.repr(self.tcx()));
|
||||
assert!(!stack.obligation.trait_ref.has_escaping_regions());
|
||||
assert!(!stack.obligation.predicate.has_escaping_regions());
|
||||
|
||||
match self.check_candidate_cache(cache_fresh_trait_ref.clone()) {
|
||||
Some(c) => {
|
||||
@ -655,7 +655,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// Other bounds. Consider both in-scope bounds from fn decl
|
||||
// and applicable impls. There is a certain set of precedence rules here.
|
||||
|
||||
match self.tcx().lang_items.to_builtin_kind(obligation.trait_ref.def_id()) {
|
||||
match self.tcx().lang_items.to_builtin_kind(obligation.predicate.def_id()) {
|
||||
Some(ty::BoundCopy) => {
|
||||
debug!("obligation self ty is {}",
|
||||
obligation.self_ty().repr(self.tcx()));
|
||||
@ -747,7 +747,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
candidates: &mut CandidateSet<'tcx>)
|
||||
-> Result<(),SelectionError<'tcx>>
|
||||
{
|
||||
let kind = match self.fn_family_trait_kind(obligation.trait_ref.def_id()) {
|
||||
let kind = match self.fn_family_trait_kind(obligation.predicate.def_id()) {
|
||||
Some(k) => k,
|
||||
None => { return Ok(()); }
|
||||
};
|
||||
@ -795,7 +795,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// We provide a `Fn` impl for fn pointers. There is no need to provide
|
||||
// the other traits (e.g. `FnMut`) since those are provided by blanket
|
||||
// impls.
|
||||
if Some(obligation.trait_ref.def_id()) != self.tcx().lang_items.fn_trait() {
|
||||
if Some(obligation.predicate.def_id()) != self.tcx().lang_items.fn_trait() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -830,11 +830,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
candidate_vec: &mut Vec<Candidate<'tcx>>)
|
||||
-> Result<(), SelectionError<'tcx>>
|
||||
{
|
||||
let all_impls = self.all_impls(obligation.trait_ref.def_id());
|
||||
let all_impls = self.all_impls(obligation.predicate.def_id());
|
||||
for &impl_def_id in all_impls.iter() {
|
||||
self.infcx.probe(|snapshot| {
|
||||
let (skol_obligation_trait_ref, skol_map) =
|
||||
self.infcx().skolemize_late_bound_regions(&*obligation.trait_ref, snapshot);
|
||||
self.infcx().skolemize_late_bound_regions(&*obligation.predicate, snapshot);
|
||||
match self.match_impl(impl_def_id, obligation, snapshot,
|
||||
&skol_map, Rc::new(skol_obligation_trait_ref)) {
|
||||
Ok(_) => {
|
||||
@ -931,7 +931,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.infcx.probe(|snapshot| {
|
||||
let (skol_obligation_trait_ref, skol_map) =
|
||||
self.infcx().skolemize_late_bound_regions(
|
||||
&*stack.obligation.trait_ref, snapshot);
|
||||
&*stack.obligation.predicate, snapshot);
|
||||
let impl_substs =
|
||||
self.rematch_impl(impl_def_id, stack.obligation, snapshot,
|
||||
&skol_map, Rc::new(skol_obligation_trait_ref));
|
||||
@ -987,7 +987,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
obligation: &TraitObligation<'tcx>)
|
||||
-> Result<BuiltinBoundConditions<'tcx>,SelectionError<'tcx>>
|
||||
{
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.trait_ref.self_ty());
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.predicate.self_ty());
|
||||
return match self_ty.sty {
|
||||
ty::ty_infer(ty::IntVar(_)) |
|
||||
ty::ty_infer(ty::FloatVar(_)) |
|
||||
@ -1415,7 +1415,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// trait-ref. Repeat that unification now without any
|
||||
// transactional boundary; it should not fail.
|
||||
match self.confirm_poly_trait_refs(obligation.cause.clone(),
|
||||
obligation.trait_ref.clone(),
|
||||
obligation.predicate.clone(),
|
||||
param.bound.clone()) {
|
||||
Ok(()) => Ok(param),
|
||||
Err(_) => {
|
||||
@ -1472,7 +1472,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
obligations.push(Obligation {
|
||||
cause: obligation.cause.clone(),
|
||||
recursion_depth: obligation.recursion_depth+1,
|
||||
trait_ref: ty::Binder(ty::OutlivesPredicate(obligation.self_ty(),
|
||||
predicate: ty::Binder(ty::OutlivesPredicate(obligation.self_ty(),
|
||||
ty::ReStatic)).as_predicate(),
|
||||
});
|
||||
}
|
||||
@ -1500,7 +1500,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// this time not in a probe.
|
||||
self.infcx.try(|snapshot| {
|
||||
let (skol_obligation_trait_ref, skol_map) =
|
||||
self.infcx().skolemize_late_bound_regions(&*obligation.trait_ref, snapshot);
|
||||
self.infcx().skolemize_late_bound_regions(&*obligation.predicate, snapshot);
|
||||
let substs = self.rematch_impl(impl_def_id, obligation,
|
||||
snapshot, &skol_map, Rc::new(skol_obligation_trait_ref));
|
||||
debug!("confirm_impl_candidate substs={}", substs);
|
||||
@ -1574,12 +1574,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
vec![],
|
||||
self_ty);
|
||||
let trait_ref = Rc::new(ty::Binder(ty::TraitRef {
|
||||
def_id: obligation.trait_ref.def_id(),
|
||||
def_id: obligation.predicate.def_id(),
|
||||
substs: self.tcx().mk_substs(substs),
|
||||
}));
|
||||
|
||||
try!(self.confirm_poly_trait_refs(obligation.cause.clone(),
|
||||
obligation.trait_ref.clone(),
|
||||
obligation.predicate.clone(),
|
||||
trait_ref));
|
||||
Ok(self_ty)
|
||||
}
|
||||
@ -1615,7 +1615,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
vec![],
|
||||
obligation.self_ty());
|
||||
let trait_ref = Rc::new(ty::Binder(ty::TraitRef {
|
||||
def_id: obligation.trait_ref.def_id(),
|
||||
def_id: obligation.predicate.def_id(),
|
||||
substs: self.tcx().mk_substs(substs),
|
||||
}));
|
||||
|
||||
@ -1624,7 +1624,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
trait_ref.repr(self.tcx()));
|
||||
|
||||
self.confirm_poly_trait_refs(obligation.cause.clone(),
|
||||
obligation.trait_ref.clone(),
|
||||
obligation.predicate.clone(),
|
||||
trait_ref)
|
||||
}
|
||||
|
||||
@ -1769,7 +1769,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// substitution if we find that any of the input types, when
|
||||
// simplified, do not match.
|
||||
|
||||
obligation.trait_ref.input_types().iter()
|
||||
obligation.predicate.input_types().iter()
|
||||
.zip(impl_trait_ref.input_types().iter())
|
||||
.any(|(&obligation_ty, &impl_ty)| {
|
||||
let simplified_obligation_ty =
|
||||
@ -1796,7 +1796,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
match self.infcx.sub_poly_trait_refs(false,
|
||||
origin,
|
||||
where_clause_trait_ref,
|
||||
obligation.trait_ref.clone()) {
|
||||
obligation.predicate.clone()) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
@ -1878,7 +1878,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
obligation: &'o TraitObligation<'tcx>)
|
||||
-> TraitObligationStack<'o, 'tcx>
|
||||
{
|
||||
let fresh_trait_ref = obligation.trait_ref.fold_with(&mut self.freshener);
|
||||
let fresh_trait_ref = obligation.predicate.fold_with(&mut self.freshener);
|
||||
|
||||
TraitObligationStack {
|
||||
obligation: obligation,
|
||||
@ -2020,7 +2020,8 @@ impl<'tcx> EvaluationResult<'tcx> {
|
||||
EvaluatedToOk |
|
||||
EvaluatedToAmbig |
|
||||
EvaluatedToErr(Overflow) |
|
||||
EvaluatedToErr(OutputTypeParameterMismatch(..)) => {
|
||||
EvaluatedToErr(OutputTypeParameterMismatch(..)) |
|
||||
EvaluatedToErr(ProjectionMismatch(..)) => {
|
||||
true
|
||||
}
|
||||
EvaluatedToErr(Unimplemented) => {
|
||||
|
@ -261,7 +261,7 @@ pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
generic_bounds.predicates.map(|predicate| {
|
||||
Obligation { cause: cause.clone(),
|
||||
recursion_depth: recursion_depth,
|
||||
trait_ref: predicate.clone() }
|
||||
predicate: predicate.clone() }
|
||||
})
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ pub fn predicate_for_builtin_bound<'tcx>(
|
||||
Ok(Obligation {
|
||||
cause: cause,
|
||||
recursion_depth: recursion_depth,
|
||||
trait_ref: ty::Predicate::Trait(trait_ref),
|
||||
predicate: ty::Predicate::Trait(trait_ref),
|
||||
})
|
||||
}
|
||||
|
||||
@ -323,8 +323,8 @@ pub fn search_trait_and_supertraits_from_bound<'tcx,F>(tcx: &ty::ctxt<'tcx>,
|
||||
|
||||
impl<'tcx,O:Repr<'tcx>> Repr<'tcx> for super::Obligation<'tcx, O> {
|
||||
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
||||
format!("Obligation(trait_ref={},depth={})",
|
||||
self.trait_ref.repr(tcx),
|
||||
format!("Obligation(predicate={},depth={})",
|
||||
self.predicate.repr(tcx),
|
||||
self.recursion_depth)
|
||||
}
|
||||
}
|
||||
@ -390,6 +390,12 @@ impl<'tcx> Repr<'tcx> for super::SelectionError<'tcx> {
|
||||
a.repr(tcx),
|
||||
b.repr(tcx),
|
||||
c.repr(tcx)),
|
||||
|
||||
super::ProjectionMismatch(ref a, ref b, ref c) =>
|
||||
format!("PrjectionMismatch({},{},{})",
|
||||
a.repr(tcx),
|
||||
b.repr(tcx),
|
||||
c.repr(tcx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ impl<'tcx,O> TypeFoldable<'tcx> for traits::Obligation<'tcx,O>
|
||||
traits::Obligation {
|
||||
cause: self.cause.clone(),
|
||||
recursion_depth: self.recursion_depth,
|
||||
trait_ref: self.trait_ref.fold_with(folder),
|
||||
predicate: self.predicate.fold_with(folder),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user