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:
Niko Matsakis 2014-12-17 16:00:34 -05:00
parent c5edd22646
commit 986f654f3b
5 changed files with 56 additions and 51 deletions

View File

@ -126,7 +126,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
let trait_obligation = Obligation { cause: cause, let trait_obligation = Obligation { cause: cause,
recursion_depth: 0, recursion_depth: 0,
trait_ref: ty::Predicate::Trait(trait_ref) }; predicate: ty::Predicate::Trait(trait_ref) };
self.register_predicate(tcx, trait_obligation) self.register_predicate(tcx, trait_obligation)
} }
@ -141,15 +141,15 @@ impl<'tcx> FulfillmentContext<'tcx> {
pub fn register_predicate<'a>(&mut self, pub fn register_predicate<'a>(&mut self,
tcx: &ty::ctxt<'tcx>, tcx: &ty::ctxt<'tcx>,
predicate: PredicateObligation<'tcx>) obligation: PredicateObligation<'tcx>)
{ {
if !self.duplicate_set.insert(predicate.trait_ref.clone()) { if !self.duplicate_set.insert(obligation.predicate.clone()) {
debug!("register_predicate({}) -- already seen, skip", predicate.repr(tcx)); debug!("register_predicate({}) -- already seen, skip", obligation.repr(tcx));
return; return;
} }
debug!("register_predicate({})", predicate.repr(tcx)); debug!("register_predicate({})", obligation.repr(tcx));
self.predicates.push(predicate); self.predicates.push(obligation);
} }
pub fn region_obligations(&self, pub fn region_obligations(&self,
@ -289,7 +289,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
} }
fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>, fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
predicate: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
selections: &mut Vec<Selection<'tcx>>, selections: &mut Vec<Selection<'tcx>>,
errors: &mut Vec<FulfillmentError<'tcx>>, errors: &mut Vec<FulfillmentError<'tcx>>,
region_obligations: &mut NodeMap<Vec<RegionObligation<'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(); let tcx = selcx.tcx();
match predicate.trait_ref { match obligation.predicate {
ty::Predicate::Trait(ref trait_ref) => { ty::Predicate::Trait(ref trait_ref) => {
let trait_obligation = Obligation { cause: predicate.cause.clone(), let trait_obligation = obligation.with(trait_ref.clone());
recursion_depth: predicate.recursion_depth,
trait_ref: trait_ref.clone() };
match selcx.select(&trait_obligation) { match selcx.select(&trait_obligation) {
Ok(None) => { Ok(None) => {
false false
@ -318,11 +316,11 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
} }
Err(selection_err) => { Err(selection_err) => {
debug!("predicate: {} error: {}", debug!("predicate: {} error: {}",
predicate.repr(tcx), obligation.repr(tcx),
selection_err.repr(tcx)); selection_err.repr(tcx));
errors.push( errors.push(
FulfillmentError::new( FulfillmentError::new(
predicate.clone(), obligation.clone(),
CodeSelectionError(selection_err))); CodeSelectionError(selection_err)));
true true
} }
@ -330,12 +328,12 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
} }
ty::Predicate::Equate(ref binder) => { ty::Predicate::Equate(ref binder) => {
match selcx.infcx().equality_predicate(predicate.cause.span, binder) { match selcx.infcx().equality_predicate(obligation.cause.span, binder) {
Ok(()) => { } Ok(()) => { }
Err(_) => { Err(_) => {
errors.push( errors.push(
FulfillmentError::new( FulfillmentError::new(
predicate.clone(), obligation.clone(),
CodeSelectionError(Unimplemented))); CodeSelectionError(Unimplemented)));
} }
} }
@ -343,12 +341,12 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
} }
ty::Predicate::RegionOutlives(ref binder) => { 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(()) => { } Ok(()) => { }
Err(_) => { Err(_) => {
errors.push( errors.push(
FulfillmentError::new( FulfillmentError::new(
predicate.clone(), obligation.clone(),
CodeSelectionError(Unimplemented))); 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 { if ty::count_late_bound_regions(selcx.tcx(), binder) != 0 {
errors.push( errors.push(
FulfillmentError::new( FulfillmentError::new(
predicate.clone(), obligation.clone(),
CodeSelectionError(Unimplemented))); CodeSelectionError(Unimplemented)));
} else { } else {
let ty::OutlivesPredicate(t_a, r_b) = binder.0; let ty::OutlivesPredicate(t_a, r_b) = binder.0;
register_region_obligation(tcx, t_a, r_b, register_region_obligation(tcx, t_a, r_b,
predicate.cause.clone(), obligation.cause.clone(),
region_obligations); region_obligations);
} }
true true

View File

@ -53,7 +53,7 @@ mod util;
pub struct Obligation<'tcx, T> { pub struct Obligation<'tcx, T> {
pub cause: ObligationCause<'tcx>, pub cause: ObligationCause<'tcx>,
pub recursion_depth: uint, pub recursion_depth: uint,
pub trait_ref: T, pub predicate: T,
} }
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>; pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
@ -310,7 +310,7 @@ impl<'tcx,O> Obligation<'tcx,O> {
{ {
Obligation { cause: cause, Obligation { cause: cause,
recursion_depth: 0, 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> { 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> { pub fn with<P>(&self, value: P) -> Obligation<'tcx,P> {
Obligation { cause: self.cause.clone(), Obligation { cause: self.cause.clone(),
recursion_depth: self.recursion_depth, recursion_depth: self.recursion_depth,
trait_ref: value } predicate: value }
} }
} }
impl<'tcx> TraitObligation<'tcx> { impl<'tcx> TraitObligation<'tcx> {
pub fn self_ty(&self) -> Ty<'tcx> { pub fn self_ty(&self) -> Ty<'tcx> {
self.trait_ref.self_ty() self.predicate.self_ty()
} }
} }

View File

@ -218,7 +218,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
pub fn select(&mut self, obligation: &TraitObligation<'tcx>) pub fn select(&mut self, obligation: &TraitObligation<'tcx>)
-> SelectionResult<'tcx, Selection<'tcx>> { -> SelectionResult<'tcx, Selection<'tcx>> {
debug!("select({})", obligation.repr(self.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); let stack = self.push_stack(None, obligation);
match try!(self.candidate_from_obligation(&stack)) { match try!(self.candidate_from_obligation(&stack)) {
@ -280,7 +280,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!("evaluate_predicate_recursively({})", debug!("evaluate_predicate_recursively({})",
obligation.repr(self.tcx())); obligation.repr(self.tcx()));
match obligation.trait_ref { match obligation.predicate {
ty::Predicate::Trait(ref t) => { ty::Predicate::Trait(ref t) => {
assert!(!t.has_escaping_regions()); assert!(!t.has_escaping_regions());
let obligation = obligation.with(t.clone()); let obligation = obligation.with(t.clone());
@ -411,7 +411,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.infcx.probe(|snapshot| { self.infcx.probe(|snapshot| {
let (skol_obligation_trait_ref, skol_map) = 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, match self.match_impl(impl_def_id, obligation, snapshot,
&skol_map, Rc::new(skol_obligation_trait_ref)) { &skol_map, Rc::new(skol_obligation_trait_ref)) {
Ok(substs) => { Ok(substs) => {
@ -456,11 +456,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// is because we want the unbound variables to be replaced // is because we want the unbound variables to be replaced
// with fresh skolemized types starting from index 0. // with fresh skolemized types starting from index 0.
let cache_fresh_trait_ref = 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={})", debug!("candidate_from_obligation(cache_fresh_trait_ref={}, obligation={})",
cache_fresh_trait_ref.repr(self.tcx()), cache_fresh_trait_ref.repr(self.tcx()),
stack.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()) { match self.check_candidate_cache(cache_fresh_trait_ref.clone()) {
Some(c) => { Some(c) => {
@ -655,7 +655,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Other bounds. Consider both in-scope bounds from fn decl // Other bounds. Consider both in-scope bounds from fn decl
// and applicable impls. There is a certain set of precedence rules here. // 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) => { Some(ty::BoundCopy) => {
debug!("obligation self ty is {}", debug!("obligation self ty is {}",
obligation.self_ty().repr(self.tcx())); obligation.self_ty().repr(self.tcx()));
@ -747,7 +747,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidates: &mut CandidateSet<'tcx>) candidates: &mut CandidateSet<'tcx>)
-> Result<(),SelectionError<'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, Some(k) => k,
None => { return Ok(()); } 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 // 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 // the other traits (e.g. `FnMut`) since those are provided by blanket
// impls. // 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(()); return Ok(());
} }
@ -830,11 +830,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidate_vec: &mut Vec<Candidate<'tcx>>) candidate_vec: &mut Vec<Candidate<'tcx>>)
-> Result<(), SelectionError<'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() { for &impl_def_id in all_impls.iter() {
self.infcx.probe(|snapshot| { self.infcx.probe(|snapshot| {
let (skol_obligation_trait_ref, skol_map) = 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, match self.match_impl(impl_def_id, obligation, snapshot,
&skol_map, Rc::new(skol_obligation_trait_ref)) { &skol_map, Rc::new(skol_obligation_trait_ref)) {
Ok(_) => { Ok(_) => {
@ -931,7 +931,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.infcx.probe(|snapshot| { self.infcx.probe(|snapshot| {
let (skol_obligation_trait_ref, skol_map) = let (skol_obligation_trait_ref, skol_map) =
self.infcx().skolemize_late_bound_regions( self.infcx().skolemize_late_bound_regions(
&*stack.obligation.trait_ref, snapshot); &*stack.obligation.predicate, snapshot);
let impl_substs = let impl_substs =
self.rematch_impl(impl_def_id, stack.obligation, snapshot, self.rematch_impl(impl_def_id, stack.obligation, snapshot,
&skol_map, Rc::new(skol_obligation_trait_ref)); &skol_map, Rc::new(skol_obligation_trait_ref));
@ -987,7 +987,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &TraitObligation<'tcx>) obligation: &TraitObligation<'tcx>)
-> Result<BuiltinBoundConditions<'tcx>,SelectionError<'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 { return match self_ty.sty {
ty::ty_infer(ty::IntVar(_)) | ty::ty_infer(ty::IntVar(_)) |
ty::ty_infer(ty::FloatVar(_)) | ty::ty_infer(ty::FloatVar(_)) |
@ -1415,7 +1415,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// trait-ref. Repeat that unification now without any // trait-ref. Repeat that unification now without any
// transactional boundary; it should not fail. // transactional boundary; it should not fail.
match self.confirm_poly_trait_refs(obligation.cause.clone(), match self.confirm_poly_trait_refs(obligation.cause.clone(),
obligation.trait_ref.clone(), obligation.predicate.clone(),
param.bound.clone()) { param.bound.clone()) {
Ok(()) => Ok(param), Ok(()) => Ok(param),
Err(_) => { Err(_) => {
@ -1472,7 +1472,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligations.push(Obligation { obligations.push(Obligation {
cause: obligation.cause.clone(), cause: obligation.cause.clone(),
recursion_depth: obligation.recursion_depth+1, 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(), ty::ReStatic)).as_predicate(),
}); });
} }
@ -1500,7 +1500,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// this time not in a probe. // this time not in a probe.
self.infcx.try(|snapshot| { self.infcx.try(|snapshot| {
let (skol_obligation_trait_ref, skol_map) = 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, let substs = self.rematch_impl(impl_def_id, obligation,
snapshot, &skol_map, Rc::new(skol_obligation_trait_ref)); snapshot, &skol_map, Rc::new(skol_obligation_trait_ref));
debug!("confirm_impl_candidate substs={}", substs); debug!("confirm_impl_candidate substs={}", substs);
@ -1574,12 +1574,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
vec![], vec![],
self_ty); self_ty);
let trait_ref = Rc::new(ty::Binder(ty::TraitRef { 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), substs: self.tcx().mk_substs(substs),
})); }));
try!(self.confirm_poly_trait_refs(obligation.cause.clone(), try!(self.confirm_poly_trait_refs(obligation.cause.clone(),
obligation.trait_ref.clone(), obligation.predicate.clone(),
trait_ref)); trait_ref));
Ok(self_ty) Ok(self_ty)
} }
@ -1615,7 +1615,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
vec![], vec![],
obligation.self_ty()); obligation.self_ty());
let trait_ref = Rc::new(ty::Binder(ty::TraitRef { 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), substs: self.tcx().mk_substs(substs),
})); }));
@ -1624,7 +1624,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
trait_ref.repr(self.tcx())); trait_ref.repr(self.tcx()));
self.confirm_poly_trait_refs(obligation.cause.clone(), self.confirm_poly_trait_refs(obligation.cause.clone(),
obligation.trait_ref.clone(), obligation.predicate.clone(),
trait_ref) trait_ref)
} }
@ -1769,7 +1769,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// substitution if we find that any of the input types, when // substitution if we find that any of the input types, when
// simplified, do not match. // simplified, do not match.
obligation.trait_ref.input_types().iter() obligation.predicate.input_types().iter()
.zip(impl_trait_ref.input_types().iter()) .zip(impl_trait_ref.input_types().iter())
.any(|(&obligation_ty, &impl_ty)| { .any(|(&obligation_ty, &impl_ty)| {
let simplified_obligation_ty = let simplified_obligation_ty =
@ -1796,7 +1796,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
match self.infcx.sub_poly_trait_refs(false, match self.infcx.sub_poly_trait_refs(false,
origin, origin,
where_clause_trait_ref, where_clause_trait_ref,
obligation.trait_ref.clone()) { obligation.predicate.clone()) {
Ok(()) => Ok(()), Ok(()) => Ok(()),
Err(_) => Err(()), Err(_) => Err(()),
} }
@ -1878,7 +1878,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &'o TraitObligation<'tcx>) obligation: &'o TraitObligation<'tcx>)
-> TraitObligationStack<'o, '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 { TraitObligationStack {
obligation: obligation, obligation: obligation,
@ -2020,7 +2020,8 @@ impl<'tcx> EvaluationResult<'tcx> {
EvaluatedToOk | EvaluatedToOk |
EvaluatedToAmbig | EvaluatedToAmbig |
EvaluatedToErr(Overflow) | EvaluatedToErr(Overflow) |
EvaluatedToErr(OutputTypeParameterMismatch(..)) => { EvaluatedToErr(OutputTypeParameterMismatch(..)) |
EvaluatedToErr(ProjectionMismatch(..)) => {
true true
} }
EvaluatedToErr(Unimplemented) => { EvaluatedToErr(Unimplemented) => {

View File

@ -261,7 +261,7 @@ pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
generic_bounds.predicates.map(|predicate| { generic_bounds.predicates.map(|predicate| {
Obligation { cause: cause.clone(), Obligation { cause: cause.clone(),
recursion_depth: recursion_depth, recursion_depth: recursion_depth,
trait_ref: predicate.clone() } predicate: predicate.clone() }
}) })
} }
@ -297,7 +297,7 @@ pub fn predicate_for_builtin_bound<'tcx>(
Ok(Obligation { Ok(Obligation {
cause: cause, cause: cause,
recursion_depth: recursion_depth, 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> { impl<'tcx,O:Repr<'tcx>> Repr<'tcx> for super::Obligation<'tcx, O> {
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
format!("Obligation(trait_ref={},depth={})", format!("Obligation(predicate={},depth={})",
self.trait_ref.repr(tcx), self.predicate.repr(tcx),
self.recursion_depth) self.recursion_depth)
} }
} }
@ -390,6 +390,12 @@ impl<'tcx> Repr<'tcx> for super::SelectionError<'tcx> {
a.repr(tcx), a.repr(tcx),
b.repr(tcx), b.repr(tcx),
c.repr(tcx)), c.repr(tcx)),
super::ProjectionMismatch(ref a, ref b, ref c) =>
format!("PrjectionMismatch({},{},{})",
a.repr(tcx),
b.repr(tcx),
c.repr(tcx)),
} }
} }
} }

View File

@ -441,7 +441,7 @@ impl<'tcx,O> TypeFoldable<'tcx> for traits::Obligation<'tcx,O>
traits::Obligation { traits::Obligation {
cause: self.cause.clone(), cause: self.cause.clone(),
recursion_depth: self.recursion_depth, recursion_depth: self.recursion_depth,
trait_ref: self.trait_ref.fold_with(folder), predicate: self.predicate.fold_with(folder),
} }
} }
} }