@@ -3,7 +3,10 @@ use std::mem;
3
3
use rustc_data_structures:: fx:: FxHashMap ;
4
4
use rustc_infer:: {
5
5
infer:: InferCtxt ,
6
- traits:: { query:: NoSolution , FulfillmentError , PredicateObligation , TraitEngine } ,
6
+ traits:: {
7
+ query:: NoSolution , FulfillmentError , FulfillmentErrorCode , PredicateObligation ,
8
+ SelectionError , TraitEngine ,
9
+ } ,
7
10
} ;
8
11
use rustc_middle:: ty;
9
12
@@ -45,32 +48,43 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
45
48
return errors;
46
49
}
47
50
48
- if self . obligations . is_empty ( ) {
49
- Vec :: new ( )
50
- } else {
51
- unimplemented ! ( "ambiguous obligations" )
52
- }
51
+ self . obligations
52
+ . drain ( ..)
53
+ . map ( |obligation| FulfillmentError {
54
+ obligation : obligation. clone ( ) ,
55
+ code : FulfillmentErrorCode :: CodeSelectionError ( SelectionError :: Unimplemented ) ,
56
+ root_obligation : obligation,
57
+ } )
58
+ . collect ( )
53
59
}
54
60
55
61
fn select_where_possible ( & mut self , infcx : & InferCtxt < ' tcx > ) -> Vec < FulfillmentError < ' tcx > > {
56
- let errors = Vec :: new ( ) ;
62
+ let mut errors = Vec :: new ( ) ;
57
63
for i in 0 .. {
58
64
if !infcx. tcx . recursion_limit ( ) . value_within_limit ( i) {
59
65
unimplemented ! ( "overflow" )
60
66
}
61
67
62
68
let mut has_changed = false ;
63
- for o in mem:: take ( & mut self . obligations ) {
69
+ for obligation in mem:: take ( & mut self . obligations ) {
64
70
let mut cx = EvalCtxt :: new ( infcx. tcx ) ;
65
- let ( changed, certainty) = match cx. evaluate_goal ( infcx, o. clone ( ) . into ( ) ) {
71
+ let ( changed, certainty) = match cx. evaluate_goal ( infcx, obligation. clone ( ) . into ( ) )
72
+ {
66
73
Ok ( result) => result,
67
- Err ( NoSolution ) => unimplemented ! ( "error" ) ,
74
+ Err ( NoSolution ) => {
75
+ errors. push ( FulfillmentError {
76
+ obligation : obligation. clone ( ) ,
77
+ code : FulfillmentErrorCode :: CodeAmbiguity ,
78
+ root_obligation : obligation,
79
+ } ) ;
80
+ continue ;
81
+ }
68
82
} ;
69
83
70
84
has_changed |= changed;
71
85
match certainty {
72
86
Certainty :: Yes => { }
73
- Certainty :: Maybe ( _) => self . obligations . push ( o ) ,
87
+ Certainty :: Maybe ( _) => self . obligations . push ( obligation ) ,
74
88
}
75
89
}
76
90
0 commit comments