]> git.lizzy.rs Git - rust.git/blob - src/librustc/traits/fulfill.rs
Auto merge of #41282 - arielb1:missing-impl-item, r=petrochenkov
[rust.git] / src / librustc / traits / fulfill.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 use dep_graph::DepGraph;
12 use infer::{InferCtxt, InferOk};
13 use ty::{self, Ty, TypeFoldable, ToPolyTraitRef, TyCtxt, ToPredicate};
14 use ty::error::ExpectedFound;
15 use rustc_data_structures::obligation_forest::{ObligationForest, Error};
16 use rustc_data_structures::obligation_forest::{ForestObligation, ObligationProcessor};
17 use std::marker::PhantomData;
18 use syntax::ast;
19 use util::nodemap::{FxHashSet, NodeMap};
20 use hir::def_id::DefId;
21
22 use super::CodeAmbiguity;
23 use super::CodeProjectionError;
24 use super::CodeSelectionError;
25 use super::{FulfillmentError, FulfillmentErrorCode};
26 use super::{ObligationCause, PredicateObligation, Obligation};
27 use super::project;
28 use super::select::SelectionContext;
29 use super::Unimplemented;
30
31 impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
32     type Predicate = ty::Predicate<'tcx>;
33
34     fn as_predicate(&self) -> &Self::Predicate { &self.obligation.predicate }
35 }
36
37 pub struct GlobalFulfilledPredicates<'tcx> {
38     set: FxHashSet<ty::PolyTraitPredicate<'tcx>>,
39     dep_graph: DepGraph,
40 }
41
42 /// The fulfillment context is used to drive trait resolution.  It
43 /// consists of a list of obligations that must be (eventually)
44 /// satisfied. The job is to track which are satisfied, which yielded
45 /// errors, and which are still pending. At any point, users can call
46 /// `select_where_possible`, and the fulfilment context will try to do
47 /// selection, retaining only those obligations that remain
48 /// ambiguous. This may be helpful in pushing type inference
49 /// along. Once all type inference constraints have been generated, the
50 /// method `select_all_or_error` can be used to report any remaining
51 /// ambiguous cases as errors.
52
53 pub struct FulfillmentContext<'tcx> {
54     // A list of all obligations that have been registered with this
55     // fulfillment context.
56     predicates: ObligationForest<PendingPredicateObligation<'tcx>>,
57
58     // A set of constraints that regionck must validate. Each
59     // constraint has the form `T:'a`, meaning "some type `T` must
60     // outlive the lifetime 'a". These constraints derive from
61     // instantiated type parameters. So if you had a struct defined
62     // like
63     //
64     //     struct Foo<T:'static> { ... }
65     //
66     // then in some expression `let x = Foo { ... }` it will
67     // instantiate the type parameter `T` with a fresh type `$0`. At
68     // the same time, it will record a region obligation of
69     // `$0:'static`. This will get checked later by regionck. (We
70     // can't generally check these things right away because we have
71     // to wait until types are resolved.)
72     //
73     // These are stored in a map keyed to the id of the innermost
74     // enclosing fn body / static initializer expression. This is
75     // because the location where the obligation was incurred can be
76     // relevant with respect to which sublifetime assumptions are in
77     // place. The reason that we store under the fn-id, and not
78     // something more fine-grained, is so that it is easier for
79     // regionck to be sure that it has found *all* the region
80     // obligations (otherwise, it's easy to fail to walk to a
81     // particular node-id).
82     region_obligations: NodeMap<Vec<RegionObligation<'tcx>>>,
83 }
84
85 #[derive(Clone)]
86 pub struct RegionObligation<'tcx> {
87     pub sub_region: &'tcx ty::Region,
88     pub sup_type: Ty<'tcx>,
89     pub cause: ObligationCause<'tcx>,
90 }
91
92 #[derive(Clone, Debug)]
93 pub struct PendingPredicateObligation<'tcx> {
94     pub obligation: PredicateObligation<'tcx>,
95     pub stalled_on: Vec<Ty<'tcx>>,
96 }
97
98 impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
99     /// Creates a new fulfillment context.
100     pub fn new() -> FulfillmentContext<'tcx> {
101         FulfillmentContext {
102             predicates: ObligationForest::new(),
103             region_obligations: NodeMap(),
104         }
105     }
106
107     /// "Normalize" a projection type `<SomeType as SomeTrait>::X` by
108     /// creating a fresh type variable `$0` as well as a projection
109     /// predicate `<SomeType as SomeTrait>::X == $0`. When the
110     /// inference engine runs, it will attempt to find an impl of
111     /// `SomeTrait` or a where clause that lets us unify `$0` with
112     /// something concrete. If this fails, we'll unify `$0` with
113     /// `projection_ty` again.
114     pub fn normalize_projection_type(&mut self,
115                                      infcx: &InferCtxt<'a, 'gcx, 'tcx>,
116                                      projection_ty: ty::ProjectionTy<'tcx>,
117                                      cause: ObligationCause<'tcx>)
118                                      -> Ty<'tcx>
119     {
120         debug!("normalize_projection_type(projection_ty={:?})",
121                projection_ty);
122
123         assert!(!projection_ty.has_escaping_regions());
124
125         // FIXME(#20304) -- cache
126
127         let mut selcx = SelectionContext::new(infcx);
128         let normalized = project::normalize_projection_type(&mut selcx, projection_ty, cause, 0);
129
130         for obligation in normalized.obligations {
131             self.register_predicate_obligation(infcx, obligation);
132         }
133
134         debug!("normalize_projection_type: result={:?}", normalized.value);
135
136         normalized.value
137     }
138
139     pub fn register_bound(&mut self,
140                           infcx: &InferCtxt<'a, 'gcx, 'tcx>,
141                           ty: Ty<'tcx>,
142                           def_id: DefId,
143                           cause: ObligationCause<'tcx>)
144     {
145         let trait_ref = ty::TraitRef {
146             def_id: def_id,
147             substs: infcx.tcx.mk_substs_trait(ty, &[]),
148         };
149         self.register_predicate_obligation(infcx, Obligation {
150             cause: cause,
151             recursion_depth: 0,
152             predicate: trait_ref.to_predicate()
153         });
154     }
155
156     pub fn register_region_obligation(&mut self,
157                                       t_a: Ty<'tcx>,
158                                       r_b: &'tcx ty::Region,
159                                       cause: ObligationCause<'tcx>)
160     {
161         register_region_obligation(t_a, r_b, cause, &mut self.region_obligations);
162     }
163
164     pub fn register_predicate_obligation(&mut self,
165                                          infcx: &InferCtxt<'a, 'gcx, 'tcx>,
166                                          obligation: PredicateObligation<'tcx>)
167     {
168         // this helps to reduce duplicate errors, as well as making
169         // debug output much nicer to read and so on.
170         let obligation = infcx.resolve_type_vars_if_possible(&obligation);
171
172         debug!("register_predicate_obligation(obligation={:?})", obligation);
173
174         infcx.obligations_in_snapshot.set(true);
175
176         if infcx.tcx.fulfilled_predicates.borrow().check_duplicate(&obligation.predicate) {
177             debug!("register_predicate_obligation: duplicate");
178             return
179         }
180
181         self.predicates.register_obligation(PendingPredicateObligation {
182             obligation: obligation,
183             stalled_on: vec![]
184         });
185     }
186
187     pub fn region_obligations(&self,
188                               body_id: ast::NodeId)
189                               -> &[RegionObligation<'tcx>]
190     {
191         match self.region_obligations.get(&body_id) {
192             None => Default::default(),
193             Some(vec) => vec,
194         }
195     }
196
197     pub fn select_all_or_error(&mut self,
198                                infcx: &InferCtxt<'a, 'gcx, 'tcx>)
199                                -> Result<(),Vec<FulfillmentError<'tcx>>>
200     {
201         self.select_where_possible(infcx)?;
202
203         let errors: Vec<_> =
204             self.predicates.to_errors(CodeAmbiguity)
205                            .into_iter()
206                            .map(|e| to_fulfillment_error(e))
207                            .collect();
208         if errors.is_empty() {
209             Ok(())
210         } else {
211             Err(errors)
212         }
213     }
214
215     pub fn select_where_possible(&mut self,
216                                  infcx: &InferCtxt<'a, 'gcx, 'tcx>)
217                                  -> Result<(),Vec<FulfillmentError<'tcx>>>
218     {
219         let mut selcx = SelectionContext::new(infcx);
220         self.select(&mut selcx)
221     }
222
223     pub fn pending_obligations(&self) -> Vec<PendingPredicateObligation<'tcx>> {
224         self.predicates.pending_obligations()
225     }
226
227     /// Attempts to select obligations using `selcx`. If `only_new_obligations` is true, then it
228     /// only attempts to select obligations that haven't been seen before.
229     fn select(&mut self, selcx: &mut SelectionContext<'a, 'gcx, 'tcx>)
230               -> Result<(),Vec<FulfillmentError<'tcx>>> {
231         debug!("select(obligation-forest-size={})", self.predicates.len());
232
233         let mut errors = Vec::new();
234
235         loop {
236             debug!("select: starting another iteration");
237
238             // Process pending obligations.
239             let outcome = self.predicates.process_obligations(&mut FulfillProcessor {
240                 selcx: selcx,
241                 region_obligations: &mut self.region_obligations,
242             });
243             debug!("select: outcome={:?}", outcome);
244
245             // these are obligations that were proven to be true.
246             for pending_obligation in outcome.completed {
247                 let predicate = &pending_obligation.obligation.predicate;
248                 selcx.tcx().fulfilled_predicates.borrow_mut()
249                            .add_if_global(selcx.tcx(), predicate);
250             }
251
252             errors.extend(
253                 outcome.errors.into_iter()
254                               .map(|e| to_fulfillment_error(e)));
255
256             // If nothing new was added, no need to keep looping.
257             if outcome.stalled {
258                 break;
259             }
260         }
261
262         debug!("select({} predicates remaining, {} errors) done",
263                self.predicates.len(), errors.len());
264
265         if errors.is_empty() {
266             Ok(())
267         } else {
268             Err(errors)
269         }
270     }
271 }
272
273 struct FulfillProcessor<'a, 'b: 'a, 'gcx: 'tcx, 'tcx: 'b> {
274     selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
275     region_obligations: &'a mut NodeMap<Vec<RegionObligation<'tcx>>>,
276 }
277
278 impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx, 'tcx> {
279     type Obligation = PendingPredicateObligation<'tcx>;
280     type Error = FulfillmentErrorCode<'tcx>;
281
282     fn process_obligation(&mut self,
283                           obligation: &mut Self::Obligation)
284                           -> Result<Option<Vec<Self::Obligation>>, Self::Error>
285     {
286         process_predicate(self.selcx,
287                           obligation,
288                           self.region_obligations)
289             .map(|os| os.map(|os| os.into_iter().map(|o| PendingPredicateObligation {
290                 obligation: o,
291                 stalled_on: vec![]
292             }).collect()))
293     }
294
295     fn process_backedge<'c, I>(&mut self, cycle: I,
296                                _marker: PhantomData<&'c PendingPredicateObligation<'tcx>>)
297         where I: Clone + Iterator<Item=&'c PendingPredicateObligation<'tcx>>,
298     {
299         if coinductive_match(self.selcx, cycle.clone()) {
300             debug!("process_child_obligations: coinductive match");
301         } else {
302             let cycle : Vec<_> = cycle.map(|c| c.obligation.clone()).collect();
303             self.selcx.infcx().report_overflow_error_cycle(&cycle);
304         }
305     }
306 }
307
308 /// Return the set of type variables contained in a trait ref
309 fn trait_ref_type_vars<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
310                                        t: ty::PolyTraitRef<'tcx>) -> Vec<Ty<'tcx>>
311 {
312     t.skip_binder() // ok b/c this check doesn't care about regions
313      .input_types()
314      .map(|t| selcx.infcx().resolve_type_vars_if_possible(&t))
315      .filter(|t| t.has_infer_types())
316      .flat_map(|t| t.walk())
317      .filter(|t| match t.sty { ty::TyInfer(_) => true, _ => false })
318      .collect()
319 }
320
321 /// Processes a predicate obligation and returns either:
322 /// - `Ok(Some(v))` if the predicate is true, presuming that `v` are also true
323 /// - `Ok(None)` if we don't have enough info to be sure
324 /// - `Err` if the predicate does not hold
325 fn process_predicate<'a, 'gcx, 'tcx>(
326     selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
327     pending_obligation: &mut PendingPredicateObligation<'tcx>,
328     region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>)
329     -> Result<Option<Vec<PredicateObligation<'tcx>>>,
330               FulfillmentErrorCode<'tcx>>
331 {
332     // if we were stalled on some unresolved variables, first check
333     // whether any of them have been resolved; if not, don't bother
334     // doing more work yet
335     if !pending_obligation.stalled_on.is_empty() {
336         if pending_obligation.stalled_on.iter().all(|&ty| {
337             let resolved_ty = selcx.infcx().shallow_resolve(&ty);
338             resolved_ty == ty // nothing changed here
339         }) {
340             debug!("process_predicate: pending obligation {:?} still stalled on {:?}",
341                    selcx.infcx().resolve_type_vars_if_possible(&pending_obligation.obligation),
342                    pending_obligation.stalled_on);
343             return Ok(None);
344         }
345         pending_obligation.stalled_on = vec![];
346     }
347
348     let obligation = &mut pending_obligation.obligation;
349
350     if obligation.predicate.has_infer_types() {
351         obligation.predicate = selcx.infcx().resolve_type_vars_if_possible(&obligation.predicate);
352     }
353
354     match obligation.predicate {
355         ty::Predicate::Trait(ref data) => {
356             if selcx.tcx().fulfilled_predicates.borrow().check_duplicate_trait(data) {
357                 return Ok(Some(vec![]));
358             }
359
360             let trait_obligation = obligation.with(data.clone());
361             match selcx.select(&trait_obligation) {
362                 Ok(Some(vtable)) => {
363                     debug!("selecting trait `{:?}` at depth {} yielded Ok(Some)",
364                           data, obligation.recursion_depth);
365                     Ok(Some(vtable.nested_obligations()))
366                 }
367                 Ok(None) => {
368                     debug!("selecting trait `{:?}` at depth {} yielded Ok(None)",
369                           data, obligation.recursion_depth);
370
371                     // This is a bit subtle: for the most part, the
372                     // only reason we can fail to make progress on
373                     // trait selection is because we don't have enough
374                     // information about the types in the trait. One
375                     // exception is that we sometimes haven't decided
376                     // what kind of closure a closure is. *But*, in
377                     // that case, it turns out, the type of the
378                     // closure will also change, because the closure
379                     // also includes references to its upvars as part
380                     // of its type, and those types are resolved at
381                     // the same time.
382                     //
383                     // FIXME(#32286) logic seems false if no upvars
384                     pending_obligation.stalled_on =
385                         trait_ref_type_vars(selcx, data.to_poly_trait_ref());
386
387                     debug!("process_predicate: pending obligation {:?} now stalled on {:?}",
388                            selcx.infcx().resolve_type_vars_if_possible(obligation),
389                            pending_obligation.stalled_on);
390
391                     Ok(None)
392                 }
393                 Err(selection_err) => {
394                     info!("selecting trait `{:?}` at depth {} yielded Err",
395                           data, obligation.recursion_depth);
396
397                     Err(CodeSelectionError(selection_err))
398                 }
399             }
400         }
401
402         ty::Predicate::Equate(ref binder) => {
403             match selcx.infcx().equality_predicate(&obligation.cause, binder) {
404                 Ok(InferOk { obligations, value: () }) => {
405                     Ok(Some(obligations))
406                 },
407                 Err(_) => Err(CodeSelectionError(Unimplemented)),
408             }
409         }
410
411         ty::Predicate::RegionOutlives(ref binder) => {
412             match selcx.infcx().region_outlives_predicate(&obligation.cause, binder) {
413                 Ok(()) => Ok(Some(Vec::new())),
414                 Err(_) => Err(CodeSelectionError(Unimplemented)),
415             }
416         }
417
418         ty::Predicate::TypeOutlives(ref binder) => {
419             // Check if there are higher-ranked regions.
420             match selcx.tcx().no_late_bound_regions(binder) {
421                 // If there are, inspect the underlying type further.
422                 None => {
423                     // Convert from `Binder<OutlivesPredicate<Ty, Region>>` to `Binder<Ty>`.
424                     let binder = binder.map_bound_ref(|pred| pred.0);
425
426                     // Check if the type has any bound regions.
427                     match selcx.tcx().no_late_bound_regions(&binder) {
428                         // If so, this obligation is an error (for now). Eventually we should be
429                         // able to support additional cases here, like `for<'a> &'a str: 'a`.
430                         None => {
431                             Err(CodeSelectionError(Unimplemented))
432                         }
433                         // Otherwise, we have something of the form
434                         // `for<'a> T: 'a where 'a not in T`, which we can treat as `T: 'static`.
435                         Some(t_a) => {
436                             let r_static = selcx.tcx().mk_region(ty::ReStatic);
437                             register_region_obligation(t_a, r_static,
438                                                        obligation.cause.clone(),
439                                                        region_obligations);
440                             Ok(Some(vec![]))
441                         }
442                     }
443                 }
444                 // If there aren't, register the obligation.
445                 Some(ty::OutlivesPredicate(t_a, r_b)) => {
446                     register_region_obligation(t_a, r_b,
447                                                obligation.cause.clone(),
448                                                region_obligations);
449                     Ok(Some(vec![]))
450                 }
451             }
452         }
453
454         ty::Predicate::Projection(ref data) => {
455             let project_obligation = obligation.with(data.clone());
456             match project::poly_project_and_unify_type(selcx, &project_obligation) {
457                 Ok(None) => {
458                     pending_obligation.stalled_on =
459                         trait_ref_type_vars(selcx, data.to_poly_trait_ref());
460                     Ok(None)
461                 }
462                 Ok(v) => Ok(v),
463                 Err(e) => Err(CodeProjectionError(e))
464             }
465         }
466
467         ty::Predicate::ObjectSafe(trait_def_id) => {
468             if !selcx.tcx().is_object_safe(trait_def_id) {
469                 Err(CodeSelectionError(Unimplemented))
470             } else {
471                 Ok(Some(Vec::new()))
472             }
473         }
474
475         ty::Predicate::ClosureKind(closure_def_id, kind) => {
476             match selcx.infcx().closure_kind(closure_def_id) {
477                 Some(closure_kind) => {
478                     if closure_kind.extends(kind) {
479                         Ok(Some(vec![]))
480                     } else {
481                         Err(CodeSelectionError(Unimplemented))
482                     }
483                 }
484                 None => {
485                     Ok(None)
486                 }
487             }
488         }
489
490         ty::Predicate::WellFormed(ty) => {
491             match ty::wf::obligations(selcx.infcx(), obligation.cause.body_id,
492                                       ty, obligation.cause.span) {
493                 None => {
494                     pending_obligation.stalled_on = vec![ty];
495                     Ok(None)
496                 }
497                 s => Ok(s)
498             }
499         }
500
501         ty::Predicate::Subtype(ref subtype) => {
502             match selcx.infcx().subtype_predicate(&obligation.cause, subtype) {
503                 None => {
504                     // none means that both are unresolved
505                     pending_obligation.stalled_on = vec![subtype.skip_binder().a,
506                                                          subtype.skip_binder().b];
507                     Ok(None)
508                 }
509                 Some(Ok(ok)) => {
510                     Ok(Some(ok.obligations))
511                 }
512                 Some(Err(err)) => {
513                     let expected_found = ExpectedFound::new(subtype.skip_binder().a_is_expected,
514                                                             subtype.skip_binder().a,
515                                                             subtype.skip_binder().b);
516                     Err(FulfillmentErrorCode::CodeSubtypeError(expected_found, err))
517                 }
518             }
519         }
520     }
521 }
522
523 /// For defaulted traits, we use a co-inductive strategy to solve, so
524 /// that recursion is ok. This routine returns true if the top of the
525 /// stack (`cycle[0]`):
526 /// - is a defaulted trait, and
527 /// - it also appears in the backtrace at some position `X`; and,
528 /// - all the predicates at positions `X..` between `X` an the top are
529 ///   also defaulted traits.
530 fn coinductive_match<'a,'c,'gcx,'tcx,I>(selcx: &mut SelectionContext<'a,'gcx,'tcx>,
531                                         cycle: I) -> bool
532     where I: Iterator<Item=&'c PendingPredicateObligation<'tcx>>,
533           'tcx: 'c
534 {
535     let mut cycle = cycle;
536     cycle
537         .all(|bt_obligation| {
538             let result = coinductive_obligation(selcx, &bt_obligation.obligation);
539             debug!("coinductive_match: bt_obligation={:?} coinductive={}",
540                    bt_obligation, result);
541             result
542         })
543 }
544
545 fn coinductive_obligation<'a,'gcx,'tcx>(selcx: &SelectionContext<'a,'gcx,'tcx>,
546                                           obligation: &PredicateObligation<'tcx>)
547                                           -> bool {
548     match obligation.predicate {
549         ty::Predicate::Trait(ref data) => {
550             selcx.tcx().trait_has_default_impl(data.def_id())
551         }
552         _ => {
553             false
554         }
555     }
556 }
557
558 fn register_region_obligation<'tcx>(t_a: Ty<'tcx>,
559                                     r_b: &'tcx ty::Region,
560                                     cause: ObligationCause<'tcx>,
561                                     region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>)
562 {
563     let region_obligation = RegionObligation { sup_type: t_a,
564                                                sub_region: r_b,
565                                                cause: cause };
566
567     debug!("register_region_obligation({:?}, cause={:?})",
568            region_obligation, region_obligation.cause);
569
570     region_obligations.entry(region_obligation.cause.body_id)
571                       .or_insert(vec![])
572                       .push(region_obligation);
573
574 }
575
576 impl<'a, 'gcx, 'tcx> GlobalFulfilledPredicates<'gcx> {
577     pub fn new(dep_graph: DepGraph) -> GlobalFulfilledPredicates<'gcx> {
578         GlobalFulfilledPredicates {
579             set: FxHashSet(),
580             dep_graph: dep_graph,
581         }
582     }
583
584     pub fn check_duplicate(&self, key: &ty::Predicate<'tcx>) -> bool {
585         if let ty::Predicate::Trait(ref data) = *key {
586             self.check_duplicate_trait(data)
587         } else {
588             false
589         }
590     }
591
592     pub fn check_duplicate_trait(&self, data: &ty::PolyTraitPredicate<'tcx>) -> bool {
593         // For the global predicate registry, when we find a match, it
594         // may have been computed by some other task, so we want to
595         // add a read from the node corresponding to the predicate
596         // processing to make sure we get the transitive dependencies.
597         if self.set.contains(data) {
598             debug_assert!(data.is_global());
599             self.dep_graph.read(data.dep_node());
600             debug!("check_duplicate: global predicate `{:?}` already proved elsewhere", data);
601
602             true
603         } else {
604             false
605         }
606     }
607
608     fn add_if_global(&mut self, tcx: TyCtxt<'a, 'gcx, 'tcx>, key: &ty::Predicate<'tcx>) {
609         if let ty::Predicate::Trait(ref data) = *key {
610             // We only add things to the global predicate registry
611             // after the current task has proved them, and hence
612             // already has the required read edges, so we don't need
613             // to add any more edges here.
614             if data.is_global() {
615                 if let Some(data) = tcx.lift_to_global(data) {
616                     if self.set.insert(data.clone()) {
617                         debug!("add_if_global: global predicate `{:?}` added", data);
618                     }
619                 }
620             }
621         }
622     }
623 }
624
625 fn to_fulfillment_error<'tcx>(
626     error: Error<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>>)
627     -> FulfillmentError<'tcx>
628 {
629     let obligation = error.backtrace.into_iter().next().unwrap().obligation;
630     FulfillmentError::new(obligation, error.error)
631 }