Skip to content

Commit 104ec48

Browse files
Report fulfillment errors in new trait solver
1 parent b22c152 commit 104ec48

File tree

1 file changed

+25
-11
lines changed
  • compiler/rustc_trait_selection/src/solve

1 file changed

+25
-11
lines changed

compiler/rustc_trait_selection/src/solve/fulfill.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::mem;
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_infer::{
55
infer::InferCtxt,
6-
traits::{query::NoSolution, FulfillmentError, PredicateObligation, TraitEngine},
6+
traits::{
7+
query::NoSolution, FulfillmentError, FulfillmentErrorCode, PredicateObligation,
8+
SelectionError, TraitEngine,
9+
},
710
};
811
use rustc_middle::ty;
912

@@ -45,32 +48,43 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
4548
return errors;
4649
}
4750

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()
5359
}
5460

5561
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>> {
56-
let errors = Vec::new();
62+
let mut errors = Vec::new();
5763
for i in 0.. {
5864
if !infcx.tcx.recursion_limit().value_within_limit(i) {
5965
unimplemented!("overflow")
6066
}
6167

6268
let mut has_changed = false;
63-
for o in mem::take(&mut self.obligations) {
69+
for obligation in mem::take(&mut self.obligations) {
6470
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+
{
6673
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+
}
6882
};
6983

7084
has_changed |= changed;
7185
match certainty {
7286
Certainty::Yes => {}
73-
Certainty::Maybe(_) => self.obligations.push(o),
87+
Certainty::Maybe(_) => self.obligations.push(obligation),
7488
}
7589
}
7690

0 commit comments

Comments
 (0)