Skip to content

Commit 986f654

Browse files
committed
Rename trait_ref field to predicate, since trait_ref is really
overly general, and the value is always *some* sort of predicate.
1 parent c5edd22 commit 986f654

File tree

5 files changed

+56
-51
lines changed

5 files changed

+56
-51
lines changed

src/librustc/middle/traits/fulfill.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
126126

127127
let trait_obligation = Obligation { cause: cause,
128128
recursion_depth: 0,
129-
trait_ref: ty::Predicate::Trait(trait_ref) };
129+
predicate: ty::Predicate::Trait(trait_ref) };
130130
self.register_predicate(tcx, trait_obligation)
131131
}
132132

@@ -141,15 +141,15 @@ impl<'tcx> FulfillmentContext<'tcx> {
141141

142142
pub fn register_predicate<'a>(&mut self,
143143
tcx: &ty::ctxt<'tcx>,
144-
predicate: PredicateObligation<'tcx>)
144+
obligation: PredicateObligation<'tcx>)
145145
{
146-
if !self.duplicate_set.insert(predicate.trait_ref.clone()) {
147-
debug!("register_predicate({}) -- already seen, skip", predicate.repr(tcx));
146+
if !self.duplicate_set.insert(obligation.predicate.clone()) {
147+
debug!("register_predicate({}) -- already seen, skip", obligation.repr(tcx));
148148
return;
149149
}
150150

151-
debug!("register_predicate({})", predicate.repr(tcx));
152-
self.predicates.push(predicate);
151+
debug!("register_predicate({})", obligation.repr(tcx));
152+
self.predicates.push(obligation);
153153
}
154154

155155
pub fn region_obligations(&self,
@@ -289,7 +289,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
289289
}
290290

291291
fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
292-
predicate: &PredicateObligation<'tcx>,
292+
obligation: &PredicateObligation<'tcx>,
293293
selections: &mut Vec<Selection<'tcx>>,
294294
errors: &mut Vec<FulfillmentError<'tcx>>,
295295
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>)
@@ -303,11 +303,9 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
303303
*/
304304

305305
let tcx = selcx.tcx();
306-
match predicate.trait_ref {
306+
match obligation.predicate {
307307
ty::Predicate::Trait(ref trait_ref) => {
308-
let trait_obligation = Obligation { cause: predicate.cause.clone(),
309-
recursion_depth: predicate.recursion_depth,
310-
trait_ref: trait_ref.clone() };
308+
let trait_obligation = obligation.with(trait_ref.clone());
311309
match selcx.select(&trait_obligation) {
312310
Ok(None) => {
313311
false
@@ -318,37 +316,37 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
318316
}
319317
Err(selection_err) => {
320318
debug!("predicate: {} error: {}",
321-
predicate.repr(tcx),
319+
obligation.repr(tcx),
322320
selection_err.repr(tcx));
323321
errors.push(
324322
FulfillmentError::new(
325-
predicate.clone(),
323+
obligation.clone(),
326324
CodeSelectionError(selection_err)));
327325
true
328326
}
329327
}
330328
}
331329

332330
ty::Predicate::Equate(ref binder) => {
333-
match selcx.infcx().equality_predicate(predicate.cause.span, binder) {
331+
match selcx.infcx().equality_predicate(obligation.cause.span, binder) {
334332
Ok(()) => { }
335333
Err(_) => {
336334
errors.push(
337335
FulfillmentError::new(
338-
predicate.clone(),
336+
obligation.clone(),
339337
CodeSelectionError(Unimplemented)));
340338
}
341339
}
342340
true
343341
}
344342

345343
ty::Predicate::RegionOutlives(ref binder) => {
346-
match selcx.infcx().region_outlives_predicate(predicate.cause.span, binder) {
344+
match selcx.infcx().region_outlives_predicate(obligation.cause.span, binder) {
347345
Ok(()) => { }
348346
Err(_) => {
349347
errors.push(
350348
FulfillmentError::new(
351-
predicate.clone(),
349+
obligation.clone(),
352350
CodeSelectionError(Unimplemented)));
353351
}
354352
}
@@ -364,12 +362,12 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
364362
if ty::count_late_bound_regions(selcx.tcx(), binder) != 0 {
365363
errors.push(
366364
FulfillmentError::new(
367-
predicate.clone(),
365+
obligation.clone(),
368366
CodeSelectionError(Unimplemented)));
369367
} else {
370368
let ty::OutlivesPredicate(t_a, r_b) = binder.0;
371369
register_region_obligation(tcx, t_a, r_b,
372-
predicate.cause.clone(),
370+
obligation.cause.clone(),
373371
region_obligations);
374372
}
375373
true

src/librustc/middle/traits/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod util;
5353
pub struct Obligation<'tcx, T> {
5454
pub cause: ObligationCause<'tcx>,
5555
pub recursion_depth: uint,
56-
pub trait_ref: T,
56+
pub predicate: T,
5757
}
5858

5959
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
@@ -310,7 +310,7 @@ impl<'tcx,O> Obligation<'tcx,O> {
310310
{
311311
Obligation { cause: cause,
312312
recursion_depth: 0,
313-
trait_ref: trait_ref }
313+
predicate: trait_ref }
314314
}
315315

316316
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> {
320320
pub fn with<P>(&self, value: P) -> Obligation<'tcx,P> {
321321
Obligation { cause: self.cause.clone(),
322322
recursion_depth: self.recursion_depth,
323-
trait_ref: value }
323+
predicate: value }
324324
}
325325
}
326326

327327
impl<'tcx> TraitObligation<'tcx> {
328328
pub fn self_ty(&self) -> Ty<'tcx> {
329-
self.trait_ref.self_ty()
329+
self.predicate.self_ty()
330330
}
331331
}
332332

src/librustc/middle/traits/select.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
218218
pub fn select(&mut self, obligation: &TraitObligation<'tcx>)
219219
-> SelectionResult<'tcx, Selection<'tcx>> {
220220
debug!("select({})", obligation.repr(self.tcx()));
221-
assert!(!obligation.trait_ref.has_escaping_regions());
221+
assert!(!obligation.predicate.has_escaping_regions());
222222

223223
let stack = self.push_stack(None, obligation);
224224
match try!(self.candidate_from_obligation(&stack)) {
@@ -280,7 +280,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
280280
debug!("evaluate_predicate_recursively({})",
281281
obligation.repr(self.tcx()));
282282

283-
match obligation.trait_ref {
283+
match obligation.predicate {
284284
ty::Predicate::Trait(ref t) => {
285285
assert!(!t.has_escaping_regions());
286286
let obligation = obligation.with(t.clone());
@@ -411,7 +411,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
411411

412412
self.infcx.probe(|snapshot| {
413413
let (skol_obligation_trait_ref, skol_map) =
414-
self.infcx().skolemize_late_bound_regions(&*obligation.trait_ref, snapshot);
414+
self.infcx().skolemize_late_bound_regions(&*obligation.predicate, snapshot);
415415
match self.match_impl(impl_def_id, obligation, snapshot,
416416
&skol_map, Rc::new(skol_obligation_trait_ref)) {
417417
Ok(substs) => {
@@ -456,11 +456,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
456456
// is because we want the unbound variables to be replaced
457457
// with fresh skolemized types starting from index 0.
458458
let cache_fresh_trait_ref =
459-
self.infcx.freshen(stack.obligation.trait_ref.clone());
459+
self.infcx.freshen(stack.obligation.predicate.clone());
460460
debug!("candidate_from_obligation(cache_fresh_trait_ref={}, obligation={})",
461461
cache_fresh_trait_ref.repr(self.tcx()),
462462
stack.repr(self.tcx()));
463-
assert!(!stack.obligation.trait_ref.has_escaping_regions());
463+
assert!(!stack.obligation.predicate.has_escaping_regions());
464464

465465
match self.check_candidate_cache(cache_fresh_trait_ref.clone()) {
466466
Some(c) => {
@@ -655,7 +655,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
655655
// Other bounds. Consider both in-scope bounds from fn decl
656656
// and applicable impls. There is a certain set of precedence rules here.
657657

658-
match self.tcx().lang_items.to_builtin_kind(obligation.trait_ref.def_id()) {
658+
match self.tcx().lang_items.to_builtin_kind(obligation.predicate.def_id()) {
659659
Some(ty::BoundCopy) => {
660660
debug!("obligation self ty is {}",
661661
obligation.self_ty().repr(self.tcx()));
@@ -747,7 +747,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
747747
candidates: &mut CandidateSet<'tcx>)
748748
-> Result<(),SelectionError<'tcx>>
749749
{
750-
let kind = match self.fn_family_trait_kind(obligation.trait_ref.def_id()) {
750+
let kind = match self.fn_family_trait_kind(obligation.predicate.def_id()) {
751751
Some(k) => k,
752752
None => { return Ok(()); }
753753
};
@@ -795,7 +795,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
795795
// We provide a `Fn` impl for fn pointers. There is no need to provide
796796
// the other traits (e.g. `FnMut`) since those are provided by blanket
797797
// impls.
798-
if Some(obligation.trait_ref.def_id()) != self.tcx().lang_items.fn_trait() {
798+
if Some(obligation.predicate.def_id()) != self.tcx().lang_items.fn_trait() {
799799
return Ok(());
800800
}
801801

@@ -830,11 +830,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
830830
candidate_vec: &mut Vec<Candidate<'tcx>>)
831831
-> Result<(), SelectionError<'tcx>>
832832
{
833-
let all_impls = self.all_impls(obligation.trait_ref.def_id());
833+
let all_impls = self.all_impls(obligation.predicate.def_id());
834834
for &impl_def_id in all_impls.iter() {
835835
self.infcx.probe(|snapshot| {
836836
let (skol_obligation_trait_ref, skol_map) =
837-
self.infcx().skolemize_late_bound_regions(&*obligation.trait_ref, snapshot);
837+
self.infcx().skolemize_late_bound_regions(&*obligation.predicate, snapshot);
838838
match self.match_impl(impl_def_id, obligation, snapshot,
839839
&skol_map, Rc::new(skol_obligation_trait_ref)) {
840840
Ok(_) => {
@@ -931,7 +931,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
931931
self.infcx.probe(|snapshot| {
932932
let (skol_obligation_trait_ref, skol_map) =
933933
self.infcx().skolemize_late_bound_regions(
934-
&*stack.obligation.trait_ref, snapshot);
934+
&*stack.obligation.predicate, snapshot);
935935
let impl_substs =
936936
self.rematch_impl(impl_def_id, stack.obligation, snapshot,
937937
&skol_map, Rc::new(skol_obligation_trait_ref));
@@ -987,7 +987,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
987987
obligation: &TraitObligation<'tcx>)
988988
-> Result<BuiltinBoundConditions<'tcx>,SelectionError<'tcx>>
989989
{
990-
let self_ty = self.infcx.shallow_resolve(obligation.trait_ref.self_ty());
990+
let self_ty = self.infcx.shallow_resolve(obligation.predicate.self_ty());
991991
return match self_ty.sty {
992992
ty::ty_infer(ty::IntVar(_)) |
993993
ty::ty_infer(ty::FloatVar(_)) |
@@ -1415,7 +1415,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14151415
// trait-ref. Repeat that unification now without any
14161416
// transactional boundary; it should not fail.
14171417
match self.confirm_poly_trait_refs(obligation.cause.clone(),
1418-
obligation.trait_ref.clone(),
1418+
obligation.predicate.clone(),
14191419
param.bound.clone()) {
14201420
Ok(()) => Ok(param),
14211421
Err(_) => {
@@ -1472,7 +1472,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14721472
obligations.push(Obligation {
14731473
cause: obligation.cause.clone(),
14741474
recursion_depth: obligation.recursion_depth+1,
1475-
trait_ref: ty::Binder(ty::OutlivesPredicate(obligation.self_ty(),
1475+
predicate: ty::Binder(ty::OutlivesPredicate(obligation.self_ty(),
14761476
ty::ReStatic)).as_predicate(),
14771477
});
14781478
}
@@ -1500,7 +1500,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15001500
// this time not in a probe.
15011501
self.infcx.try(|snapshot| {
15021502
let (skol_obligation_trait_ref, skol_map) =
1503-
self.infcx().skolemize_late_bound_regions(&*obligation.trait_ref, snapshot);
1503+
self.infcx().skolemize_late_bound_regions(&*obligation.predicate, snapshot);
15041504
let substs = self.rematch_impl(impl_def_id, obligation,
15051505
snapshot, &skol_map, Rc::new(skol_obligation_trait_ref));
15061506
debug!("confirm_impl_candidate substs={}", substs);
@@ -1574,12 +1574,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15741574
vec![],
15751575
self_ty);
15761576
let trait_ref = Rc::new(ty::Binder(ty::TraitRef {
1577-
def_id: obligation.trait_ref.def_id(),
1577+
def_id: obligation.predicate.def_id(),
15781578
substs: self.tcx().mk_substs(substs),
15791579
}));
15801580

15811581
try!(self.confirm_poly_trait_refs(obligation.cause.clone(),
1582-
obligation.trait_ref.clone(),
1582+
obligation.predicate.clone(),
15831583
trait_ref));
15841584
Ok(self_ty)
15851585
}
@@ -1615,7 +1615,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16151615
vec![],
16161616
obligation.self_ty());
16171617
let trait_ref = Rc::new(ty::Binder(ty::TraitRef {
1618-
def_id: obligation.trait_ref.def_id(),
1618+
def_id: obligation.predicate.def_id(),
16191619
substs: self.tcx().mk_substs(substs),
16201620
}));
16211621

@@ -1624,7 +1624,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16241624
trait_ref.repr(self.tcx()));
16251625

16261626
self.confirm_poly_trait_refs(obligation.cause.clone(),
1627-
obligation.trait_ref.clone(),
1627+
obligation.predicate.clone(),
16281628
trait_ref)
16291629
}
16301630

@@ -1769,7 +1769,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17691769
// substitution if we find that any of the input types, when
17701770
// simplified, do not match.
17711771

1772-
obligation.trait_ref.input_types().iter()
1772+
obligation.predicate.input_types().iter()
17731773
.zip(impl_trait_ref.input_types().iter())
17741774
.any(|(&obligation_ty, &impl_ty)| {
17751775
let simplified_obligation_ty =
@@ -1796,7 +1796,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17961796
match self.infcx.sub_poly_trait_refs(false,
17971797
origin,
17981798
where_clause_trait_ref,
1799-
obligation.trait_ref.clone()) {
1799+
obligation.predicate.clone()) {
18001800
Ok(()) => Ok(()),
18011801
Err(_) => Err(()),
18021802
}
@@ -1878,7 +1878,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18781878
obligation: &'o TraitObligation<'tcx>)
18791879
-> TraitObligationStack<'o, 'tcx>
18801880
{
1881-
let fresh_trait_ref = obligation.trait_ref.fold_with(&mut self.freshener);
1881+
let fresh_trait_ref = obligation.predicate.fold_with(&mut self.freshener);
18821882

18831883
TraitObligationStack {
18841884
obligation: obligation,
@@ -2020,7 +2020,8 @@ impl<'tcx> EvaluationResult<'tcx> {
20202020
EvaluatedToOk |
20212021
EvaluatedToAmbig |
20222022
EvaluatedToErr(Overflow) |
2023-
EvaluatedToErr(OutputTypeParameterMismatch(..)) => {
2023+
EvaluatedToErr(OutputTypeParameterMismatch(..)) |
2024+
EvaluatedToErr(ProjectionMismatch(..)) => {
20242025
true
20252026
}
20262027
EvaluatedToErr(Unimplemented) => {

src/librustc/middle/traits/util.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
261261
generic_bounds.predicates.map(|predicate| {
262262
Obligation { cause: cause.clone(),
263263
recursion_depth: recursion_depth,
264-
trait_ref: predicate.clone() }
264+
predicate: predicate.clone() }
265265
})
266266
}
267267

@@ -297,7 +297,7 @@ pub fn predicate_for_builtin_bound<'tcx>(
297297
Ok(Obligation {
298298
cause: cause,
299299
recursion_depth: recursion_depth,
300-
trait_ref: ty::Predicate::Trait(trait_ref),
300+
predicate: ty::Predicate::Trait(trait_ref),
301301
})
302302
}
303303

@@ -323,8 +323,8 @@ pub fn search_trait_and_supertraits_from_bound<'tcx,F>(tcx: &ty::ctxt<'tcx>,
323323

324324
impl<'tcx,O:Repr<'tcx>> Repr<'tcx> for super::Obligation<'tcx, O> {
325325
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
326-
format!("Obligation(trait_ref={},depth={})",
327-
self.trait_ref.repr(tcx),
326+
format!("Obligation(predicate={},depth={})",
327+
self.predicate.repr(tcx),
328328
self.recursion_depth)
329329
}
330330
}
@@ -390,6 +390,12 @@ impl<'tcx> Repr<'tcx> for super::SelectionError<'tcx> {
390390
a.repr(tcx),
391391
b.repr(tcx),
392392
c.repr(tcx)),
393+
394+
super::ProjectionMismatch(ref a, ref b, ref c) =>
395+
format!("PrjectionMismatch({},{},{})",
396+
a.repr(tcx),
397+
b.repr(tcx),
398+
c.repr(tcx)),
393399
}
394400
}
395401
}

src/librustc/middle/ty_fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl<'tcx,O> TypeFoldable<'tcx> for traits::Obligation<'tcx,O>
441441
traits::Obligation {
442442
cause: self.cause.clone(),
443443
recursion_depth: self.recursion_depth,
444-
trait_ref: self.trait_ref.fold_with(folder),
444+
predicate: self.predicate.fold_with(folder),
445445
}
446446
}
447447
}

0 commit comments

Comments
 (0)