]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/traits/mod.rs
Make RFC 1214 warnings into errors, and rip out the "warn or err"
[rust.git] / src / librustc / middle / traits / mod.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Trait Resolution. See the Book for more.
12
13 pub use self::SelectionError::*;
14 pub use self::FulfillmentErrorCode::*;
15 pub use self::Vtable::*;
16 pub use self::ObligationCauseCode::*;
17
18 use middle::def_id::DefId;
19 use middle::free_region::FreeRegionMap;
20 use middle::subst;
21 use middle::ty::{self, HasTypeFlags, Ty};
22 use middle::ty::fold::TypeFoldable;
23 use middle::infer::{self, fixup_err_to_string, InferCtxt};
24
25 use std::rc::Rc;
26 use syntax::ast;
27 use syntax::codemap::{Span, DUMMY_SP};
28
29 pub use self::error_reporting::TraitErrorKey;
30 pub use self::error_reporting::report_fulfillment_errors;
31 pub use self::error_reporting::report_overflow_error;
32 pub use self::error_reporting::report_selection_error;
33 pub use self::error_reporting::report_object_safety_error;
34 pub use self::coherence::orphan_check;
35 pub use self::coherence::overlapping_impls;
36 pub use self::coherence::OrphanCheckErr;
37 pub use self::fulfill::{FulfillmentContext, FulfilledPredicates, RegionObligation};
38 pub use self::project::MismatchedProjectionTypes;
39 pub use self::project::normalize;
40 pub use self::project::Normalized;
41 pub use self::object_safety::is_object_safe;
42 pub use self::object_safety::astconv_object_safety_violations;
43 pub use self::object_safety::object_safety_violations;
44 pub use self::object_safety::ObjectSafetyViolation;
45 pub use self::object_safety::MethodViolationCode;
46 pub use self::object_safety::is_vtable_safe_method;
47 pub use self::select::EvaluationCache;
48 pub use self::select::SelectionContext;
49 pub use self::select::SelectionCache;
50 pub use self::select::{MethodMatchResult, MethodMatched, MethodAmbiguous, MethodDidNotMatch};
51 pub use self::select::{MethodMatchedData}; // intentionally don't export variants
52 pub use self::util::elaborate_predicates;
53 pub use self::util::get_vtable_index_of_object_method;
54 pub use self::util::trait_ref_for_builtin_bound;
55 pub use self::util::predicate_for_trait_def;
56 pub use self::util::supertraits;
57 pub use self::util::Supertraits;
58 pub use self::util::supertrait_def_ids;
59 pub use self::util::SupertraitDefIds;
60 pub use self::util::transitive_bounds;
61 pub use self::util::upcast;
62
63 mod coherence;
64 mod error_reporting;
65 mod fulfill;
66 mod project;
67 mod object_safety;
68 mod select;
69 mod structural_impls;
70 mod util;
71
72 /// An `Obligation` represents some trait reference (e.g. `int:Eq`) for
73 /// which the vtable must be found.  The process of finding a vtable is
74 /// called "resolving" the `Obligation`. This process consists of
75 /// either identifying an `impl` (e.g., `impl Eq for int`) that
76 /// provides the required vtable, or else finding a bound that is in
77 /// scope. The eventual result is usually a `Selection` (defined below).
78 #[derive(Clone, PartialEq, Eq)]
79 pub struct Obligation<'tcx, T> {
80     pub cause: ObligationCause<'tcx>,
81     pub recursion_depth: usize,
82     pub predicate: T,
83 }
84
85 pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
86 pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
87
88 /// Why did we incur this obligation? Used for error reporting.
89 #[derive(Clone, Debug, PartialEq, Eq)]
90 pub struct ObligationCause<'tcx> {
91     pub span: Span,
92
93     // The id of the fn body that triggered this obligation. This is
94     // used for region obligations to determine the precise
95     // environment in which the region obligation should be evaluated
96     // (in particular, closures can add new assumptions). See the
97     // field `region_obligations` of the `FulfillmentContext` for more
98     // information.
99     pub body_id: ast::NodeId,
100
101     pub code: ObligationCauseCode<'tcx>
102 }
103
104 #[derive(Clone, Debug, PartialEq, Eq)]
105 pub enum ObligationCauseCode<'tcx> {
106     /// Not well classified or should be obvious from span.
107     MiscObligation,
108
109     /// This is the trait reference from the given projection
110     SliceOrArrayElem,
111
112     /// This is the trait reference from the given projection
113     ProjectionWf(ty::ProjectionTy<'tcx>),
114
115     /// In an impl of trait X for type Y, type Y must
116     /// also implement all supertraits of X.
117     ItemObligation(DefId),
118
119     /// A type like `&'a T` is WF only if `T: 'a`.
120     ReferenceOutlivesReferent(Ty<'tcx>),
121
122     /// Obligation incurred due to an object cast.
123     ObjectCastObligation(/* Object type */ Ty<'tcx>),
124
125     /// Various cases where expressions must be sized/copy/etc:
126     AssignmentLhsSized,        // L = X implies that L is Sized
127     StructInitializerSized,    // S { ... } must be Sized
128     VariableType(ast::NodeId), // Type of each variable must be Sized
129     ReturnType,                // Return type must be Sized
130     RepeatVec,                 // [T,..n] --> T must be Copy
131
132     // Captures of variable the given id by a closure (span is the
133     // span of the closure)
134     ClosureCapture(ast::NodeId, Span, ty::BuiltinBound),
135
136     // Types of fields (other than the last) in a struct must be sized.
137     FieldSized,
138
139     // static items must have `Sync` type
140     SharedStatic,
141
142     BuiltinDerivedObligation(DerivedObligationCause<'tcx>),
143
144     ImplDerivedObligation(DerivedObligationCause<'tcx>),
145
146     CompareImplMethodObligation,
147 }
148
149 #[derive(Clone, Debug, PartialEq, Eq)]
150 pub struct DerivedObligationCause<'tcx> {
151     /// The trait reference of the parent obligation that led to the
152     /// current obligation. Note that only trait obligations lead to
153     /// derived obligations, so we just store the trait reference here
154     /// directly.
155     parent_trait_ref: ty::PolyTraitRef<'tcx>,
156
157     /// The parent trait had this cause
158     parent_code: Rc<ObligationCauseCode<'tcx>>
159 }
160
161 pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
162 pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;
163 pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
164
165 pub type Selection<'tcx> = Vtable<'tcx, PredicateObligation<'tcx>>;
166
167 #[derive(Clone,Debug)]
168 pub enum SelectionError<'tcx> {
169     Unimplemented,
170     OutputTypeParameterMismatch(ty::PolyTraitRef<'tcx>,
171                                 ty::PolyTraitRef<'tcx>,
172                                 ty::error::TypeError<'tcx>),
173     TraitNotObjectSafe(DefId),
174 }
175
176 pub struct FulfillmentError<'tcx> {
177     pub obligation: PredicateObligation<'tcx>,
178     pub code: FulfillmentErrorCode<'tcx>
179 }
180
181 #[derive(Clone)]
182 pub enum FulfillmentErrorCode<'tcx> {
183     CodeSelectionError(SelectionError<'tcx>),
184     CodeProjectionError(MismatchedProjectionTypes<'tcx>),
185     CodeAmbiguity,
186 }
187
188 /// When performing resolution, it is typically the case that there
189 /// can be one of three outcomes:
190 ///
191 /// - `Ok(Some(r))`: success occurred with result `r`
192 /// - `Ok(None)`: could not definitely determine anything, usually due
193 ///   to inconclusive type inference.
194 /// - `Err(e)`: error `e` occurred
195 pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
196
197 /// Given the successful resolution of an obligation, the `Vtable`
198 /// indicates where the vtable comes from. Note that while we call this
199 /// a "vtable", it does not necessarily indicate dynamic dispatch at
200 /// runtime. `Vtable` instances just tell the compiler where to find
201 /// methods, but in generic code those methods are typically statically
202 /// dispatched -- only when an object is constructed is a `Vtable`
203 /// instance reified into an actual vtable.
204 ///
205 /// For example, the vtable may be tied to a specific impl (case A),
206 /// or it may be relative to some bound that is in scope (case B).
207 ///
208 ///
209 /// ```
210 /// impl<T:Clone> Clone<T> for Option<T> { ... } // Impl_1
211 /// impl<T:Clone> Clone<T> for Box<T> { ... }    // Impl_2
212 /// impl Clone for int { ... }             // Impl_3
213 ///
214 /// fn foo<T:Clone>(concrete: Option<Box<int>>,
215 ///                 param: T,
216 ///                 mixed: Option<T>) {
217 ///
218 ///    // Case A: Vtable points at a specific impl. Only possible when
219 ///    // type is concretely known. If the impl itself has bounded
220 ///    // type parameters, Vtable will carry resolutions for those as well:
221 ///    concrete.clone(); // Vtable(Impl_1, [Vtable(Impl_2, [Vtable(Impl_3)])])
222 ///
223 ///    // Case B: Vtable must be provided by caller. This applies when
224 ///    // type is a type parameter.
225 ///    param.clone();    // VtableParam
226 ///
227 ///    // Case C: A mix of cases A and B.
228 ///    mixed.clone();    // Vtable(Impl_1, [VtableParam])
229 /// }
230 /// ```
231 ///
232 /// ### The type parameter `N`
233 ///
234 /// See explanation on `VtableImplData`.
235 #[derive(Clone)]
236 pub enum Vtable<'tcx, N> {
237     /// Vtable identifying a particular impl.
238     VtableImpl(VtableImplData<'tcx, N>),
239
240     /// Vtable for default trait implementations
241     /// This carries the information and nested obligations with regards
242     /// to a default implementation for a trait `Trait`. The nested obligations
243     /// ensure the trait implementation holds for all the constituent types.
244     VtableDefaultImpl(VtableDefaultImplData<N>),
245
246     /// Successful resolution to an obligation provided by the caller
247     /// for some type parameter. The `Vec<N>` represents the
248     /// obligations incurred from normalizing the where-clause (if
249     /// any).
250     VtableParam(Vec<N>),
251
252     /// Virtual calls through an object
253     VtableObject(VtableObjectData<'tcx>),
254
255     /// Successful resolution for a builtin trait.
256     VtableBuiltin(VtableBuiltinData<N>),
257
258     /// Vtable automatically generated for a closure. The def ID is the ID
259     /// of the closure expression. This is a `VtableImpl` in spirit, but the
260     /// impl is generated by the compiler and does not appear in the source.
261     VtableClosure(VtableClosureData<'tcx, N>),
262
263     /// Same as above, but for a fn pointer type with the given signature.
264     VtableFnPointer(ty::Ty<'tcx>),
265 }
266
267 /// Identifies a particular impl in the source, along with a set of
268 /// substitutions from the impl's type/lifetime parameters. The
269 /// `nested` vector corresponds to the nested obligations attached to
270 /// the impl's type parameters.
271 ///
272 /// The type parameter `N` indicates the type used for "nested
273 /// obligations" that are required by the impl. During type check, this
274 /// is `Obligation`, as one might expect. During trans, however, this
275 /// is `()`, because trans only requires a shallow resolution of an
276 /// impl, and nested obligations are satisfied later.
277 #[derive(Clone, PartialEq, Eq)]
278 pub struct VtableImplData<'tcx, N> {
279     pub impl_def_id: DefId,
280     pub substs: subst::Substs<'tcx>,
281     pub nested: Vec<N>
282 }
283
284 #[derive(Clone, PartialEq, Eq)]
285 pub struct VtableClosureData<'tcx, N> {
286     pub closure_def_id: DefId,
287     pub substs: ty::ClosureSubsts<'tcx>,
288     /// Nested obligations. This can be non-empty if the closure
289     /// signature contains associated types.
290     pub nested: Vec<N>
291 }
292
293 #[derive(Clone)]
294 pub struct VtableDefaultImplData<N> {
295     pub trait_def_id: DefId,
296     pub nested: Vec<N>
297 }
298
299 #[derive(Clone)]
300 pub struct VtableBuiltinData<N> {
301     pub nested: Vec<N>
302 }
303
304 /// A vtable for some object-safe trait `Foo` automatically derived
305 /// for the object type `Foo`.
306 #[derive(PartialEq,Eq,Clone)]
307 pub struct VtableObjectData<'tcx> {
308     /// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
309     pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,
310
311     /// The vtable is formed by concatenating together the method lists of
312     /// the base object trait and all supertraits; this is the start of
313     /// `upcast_trait_ref`'s methods in that vtable.
314     pub vtable_base: usize
315 }
316
317 /// Creates predicate obligations from the generic bounds.
318 pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
319                                      generic_bounds: &ty::InstantiatedPredicates<'tcx>)
320                                      -> PredicateObligations<'tcx>
321 {
322     util::predicates_for_generics(cause, 0, generic_bounds)
323 }
324
325 /// Determines whether the type `ty` is known to meet `bound` and
326 /// returns true if so. Returns false if `ty` either does not meet
327 /// `bound` or is not known to meet bound (note that this is
328 /// conservative towards *no impl*, which is the opposite of the
329 /// `evaluate` methods).
330 pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
331                                                  ty: Ty<'tcx>,
332                                                  bound: ty::BuiltinBound,
333                                                  span: Span)
334                                                  -> bool
335 {
336     debug!("type_known_to_meet_builtin_bound(ty={:?}, bound={:?})",
337            ty,
338            bound);
339
340     let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
341     let obligation =
342         util::predicate_for_builtin_bound(infcx.tcx, cause, bound, 0, ty);
343     let obligation = match obligation {
344         Ok(o) => o,
345         Err(..) => return false
346     };
347     let result = SelectionContext::new(infcx)
348         .evaluate_obligation_conservatively(&obligation);
349     debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} => {:?}",
350            ty, bound, result);
351
352     if result && (ty.has_infer_types() || ty.has_closure_types()) {
353         // Because of inference "guessing", selection can sometimes claim
354         // to succeed while the success requires a guess. To ensure
355         // this function's result remains infallible, we must confirm
356         // that guess. While imperfect, I believe this is sound.
357
358         let mut fulfill_cx = FulfillmentContext::new(false);
359
360         // We can use a dummy node-id here because we won't pay any mind
361         // to region obligations that arise (there shouldn't really be any
362         // anyhow).
363         let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
364
365         fulfill_cx.register_builtin_bound(infcx, ty, bound, cause);
366
367         // Note: we only assume something is `Copy` if we can
368         // *definitively* show that it implements `Copy`. Otherwise,
369         // assume it is move; linear is always ok.
370         match fulfill_cx.select_all_or_error(infcx) {
371             Ok(()) => {
372                 debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} success",
373                        ty,
374                        bound);
375                 true
376             }
377             Err(e) => {
378                 debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} errors={:?}",
379                        ty,
380                        bound,
381                        e);
382                 false
383             }
384         }
385     } else {
386         result
387     }
388 }
389
390 // FIXME: this is gonna need to be removed ...
391 /// Normalizes the parameter environment, reporting errors if they occur.
392 pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvironment<'a,'tcx>,
393                                              cause: ObligationCause<'tcx>)
394                                              -> ty::ParameterEnvironment<'a,'tcx>
395 {
396     // I'm not wild about reporting errors here; I'd prefer to
397     // have the errors get reported at a defined place (e.g.,
398     // during typeck). Instead I have all parameter
399     // environments, in effect, going through this function
400     // and hence potentially reporting errors. This ensurse of
401     // course that we never forget to normalize (the
402     // alternative seemed like it would involve a lot of
403     // manual invocations of this fn -- and then we'd have to
404     // deal with the errors at each of those sites).
405     //
406     // In any case, in practice, typeck constructs all the
407     // parameter environments once for every fn as it goes,
408     // and errors will get reported then; so after typeck we
409     // can be sure that no errors should occur.
410
411     let tcx = unnormalized_env.tcx;
412     let span = cause.span;
413     let body_id = cause.body_id;
414
415     debug!("normalize_param_env_or_error(unnormalized_env={:?})",
416            unnormalized_env);
417
418     let predicates: Vec<_> =
419         util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.clone())
420         .filter(|p| !p.is_global()) // (*)
421         .collect();
422
423     // (*) Any predicate like `i32: Trait<u32>` or whatever doesn't
424     // need to be in the *environment* to be proven, so screen those
425     // out. This is important for the soundness of inter-fn
426     // caching. Note though that we should probably check that these
427     // predicates hold at the point where the environment is
428     // constructed, but I am not currently doing so out of laziness.
429     // -nmatsakis
430
431     debug!("normalize_param_env_or_error: elaborated-predicates={:?}",
432            predicates);
433
434     let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
435
436     let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env), false);
437     let predicates = match fully_normalize(&infcx, cause,
438                                            &infcx.parameter_environment.caller_bounds) {
439         Ok(predicates) => predicates,
440         Err(errors) => {
441             report_fulfillment_errors(&infcx, &errors);
442             return infcx.parameter_environment; // an unnormalized env is better than nothing
443         }
444     };
445
446     let free_regions = FreeRegionMap::new();
447     infcx.resolve_regions_and_report_errors(&free_regions, body_id);
448     let predicates = match infcx.fully_resolve(&predicates) {
449         Ok(predicates) => predicates,
450         Err(fixup_err) => {
451             // If we encounter a fixup error, it means that some type
452             // variable wound up unconstrained. I actually don't know
453             // if this can happen, and I certainly don't expect it to
454             // happen often, but if it did happen it probably
455             // represents a legitimate failure due to some kind of
456             // unconstrained variable, and it seems better not to ICE,
457             // all things considered.
458             let err_msg = fixup_err_to_string(fixup_err);
459             tcx.sess.span_err(span, &err_msg);
460             return infcx.parameter_environment; // an unnormalized env is better than nothing
461         }
462     };
463
464     infcx.parameter_environment.with_caller_bounds(predicates)
465 }
466
467 pub fn fully_normalize<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
468                                   cause: ObligationCause<'tcx>,
469                                   value: &T)
470                                   -> Result<T, Vec<FulfillmentError<'tcx>>>
471     where T : TypeFoldable<'tcx> + HasTypeFlags
472 {
473     debug!("normalize_param_env(value={:?})", value);
474
475     let mut selcx = &mut SelectionContext::new(infcx);
476     // FIXME (@jroesch) ISSUE 26721
477     // I'm not sure if this is a bug or not, needs further investigation.
478     // It appears that by reusing the fulfillment_cx here we incur more
479     // obligations and later trip an asssertion on regionck.rs line 337.
480     //
481     // The two possibilities I see is:
482     //      - normalization is not actually fully happening and we
483     //        have a bug else where
484     //      - we are adding a duplicate bound into the list causing
485     //        its size to change.
486     //
487     // I think we should probably land this refactor and then come
488     // back to this is a follow-up patch.
489     let mut fulfill_cx = FulfillmentContext::new(false);
490
491     let Normalized { value: normalized_value, obligations } =
492         project::normalize(selcx, cause, value);
493     debug!("normalize_param_env: normalized_value={:?} obligations={:?}",
494            normalized_value,
495            obligations);
496     for obligation in obligations {
497         fulfill_cx.register_predicate_obligation(selcx.infcx(), obligation);
498     }
499
500     try!(fulfill_cx.select_all_or_error(infcx));
501     let resolved_value = infcx.resolve_type_vars_if_possible(&normalized_value);
502     debug!("normalize_param_env: resolved_value={:?}", resolved_value);
503     Ok(resolved_value)
504 }
505
506 impl<'tcx,O> Obligation<'tcx,O> {
507     pub fn new(cause: ObligationCause<'tcx>,
508                trait_ref: O)
509                -> Obligation<'tcx, O>
510     {
511         Obligation { cause: cause,
512                      recursion_depth: 0,
513                      predicate: trait_ref }
514     }
515
516     fn with_depth(cause: ObligationCause<'tcx>,
517                   recursion_depth: usize,
518                   trait_ref: O)
519                   -> Obligation<'tcx, O>
520     {
521         Obligation { cause: cause,
522                      recursion_depth: recursion_depth,
523                      predicate: trait_ref }
524     }
525
526     pub fn misc(span: Span, body_id: ast::NodeId, trait_ref: O) -> Obligation<'tcx, O> {
527         Obligation::new(ObligationCause::misc(span, body_id), trait_ref)
528     }
529
530     pub fn with<P>(&self, value: P) -> Obligation<'tcx,P> {
531         Obligation { cause: self.cause.clone(),
532                      recursion_depth: self.recursion_depth,
533                      predicate: value }
534     }
535 }
536
537 impl<'tcx> ObligationCause<'tcx> {
538     pub fn new(span: Span,
539                body_id: ast::NodeId,
540                code: ObligationCauseCode<'tcx>)
541                -> ObligationCause<'tcx> {
542         ObligationCause { span: span, body_id: body_id, code: code }
543     }
544
545     pub fn misc(span: Span, body_id: ast::NodeId) -> ObligationCause<'tcx> {
546         ObligationCause { span: span, body_id: body_id, code: MiscObligation }
547     }
548
549     pub fn dummy() -> ObligationCause<'tcx> {
550         ObligationCause { span: DUMMY_SP, body_id: 0, code: MiscObligation }
551     }
552 }
553
554 impl<'tcx, N> Vtable<'tcx, N> {
555     pub fn nested_obligations(self) -> Vec<N> {
556         match self {
557             VtableImpl(i) => i.nested,
558             VtableParam(n) => n,
559             VtableBuiltin(i) => i.nested,
560             VtableDefaultImpl(d) => d.nested,
561             VtableClosure(c) => c.nested,
562             VtableObject(_) | VtableFnPointer(..) => vec![]
563         }
564     }
565
566     pub fn map<M, F>(self, f: F) -> Vtable<'tcx, M> where F: FnMut(N) -> M {
567         match self {
568             VtableImpl(i) => VtableImpl(VtableImplData {
569                 impl_def_id: i.impl_def_id,
570                 substs: i.substs,
571                 nested: i.nested.into_iter().map(f).collect()
572             }),
573             VtableParam(n) => VtableParam(n.into_iter().map(f).collect()),
574             VtableBuiltin(i) => VtableBuiltin(VtableBuiltinData {
575                 nested: i.nested.into_iter().map(f).collect()
576             }),
577             VtableObject(o) => VtableObject(o),
578             VtableDefaultImpl(d) => VtableDefaultImpl(VtableDefaultImplData {
579                 trait_def_id: d.trait_def_id,
580                 nested: d.nested.into_iter().map(f).collect()
581             }),
582             VtableFnPointer(f) => VtableFnPointer(f),
583             VtableClosure(c) => VtableClosure(VtableClosureData {
584                 closure_def_id: c.closure_def_id,
585                 substs: c.substs,
586                 nested: c.nested.into_iter().map(f).collect(),
587             })
588         }
589     }
590 }
591
592 impl<'tcx> FulfillmentError<'tcx> {
593     fn new(obligation: PredicateObligation<'tcx>,
594            code: FulfillmentErrorCode<'tcx>)
595            -> FulfillmentError<'tcx>
596     {
597         FulfillmentError { obligation: obligation, code: code }
598     }
599 }
600
601 impl<'tcx> TraitObligation<'tcx> {
602     fn self_ty(&self) -> ty::Binder<Ty<'tcx>> {
603         ty::Binder(self.predicate.skip_binder().self_ty())
604     }
605 }