@@ -10,6 +10,7 @@ use rustc_infer::traits::{
1010use rustc_middle:: ty;
1111use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
1212
13+ use super :: eval_ctxt:: GenerateProofTree ;
1314use super :: { Certainty , InferCtxtEvalExt } ;
1415
1516/// A trait engine using the new trait solver.
@@ -46,8 +47,11 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
4647 self . obligations
4748 . drain ( ..)
4849 . map ( |obligation| {
49- let code =
50- infcx. probe ( |_| match infcx. evaluate_root_goal ( obligation. clone ( ) . into ( ) ) {
50+ let code = infcx. probe ( |_| {
51+ match infcx
52+ . evaluate_root_goal ( obligation. clone ( ) . into ( ) , GenerateProofTree :: No )
53+ . 0
54+ {
5155 Ok ( ( _, Certainty :: Maybe ( MaybeCause :: Ambiguity ) , _) ) => {
5256 FulfillmentErrorCode :: CodeAmbiguity { overflow : false }
5357 }
@@ -60,7 +64,8 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
6064 Err ( _) => {
6165 bug ! ( "did not expect selection error when collecting ambiguity errors" )
6266 }
63- } ) ;
67+ }
68+ } ) ;
6469
6570 FulfillmentError {
6671 obligation : obligation. clone ( ) ,
@@ -81,61 +86,62 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
8186 let mut has_changed = false ;
8287 for obligation in mem:: take ( & mut self . obligations ) {
8388 let goal = obligation. clone ( ) . into ( ) ;
84- let ( changed, certainty, nested_goals) = match infcx. evaluate_root_goal ( goal) {
85- Ok ( result) => result,
86- Err ( NoSolution ) => {
87- errors. push ( FulfillmentError {
88- obligation : obligation. clone ( ) ,
89- code : match goal. predicate . kind ( ) . skip_binder ( ) {
90- ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( _) ) => {
91- FulfillmentErrorCode :: CodeProjectionError (
92- // FIXME: This could be a `Sorts` if the term is a type
93- MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
94- )
95- }
96- ty:: PredicateKind :: AliasRelate ( _, _, _) => {
97- FulfillmentErrorCode :: CodeProjectionError (
98- MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
99- )
100- }
101- ty:: PredicateKind :: Subtype ( pred) => {
102- let ( a, b) = infcx. instantiate_binder_with_placeholders (
103- goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
104- ) ;
105- let expected_found = ExpectedFound :: new ( true , a, b) ;
106- FulfillmentErrorCode :: CodeSubtypeError (
107- expected_found,
108- TypeError :: Sorts ( expected_found) ,
109- )
110- }
111- ty:: PredicateKind :: Coerce ( pred) => {
112- let ( a, b) = infcx. instantiate_binder_with_placeholders (
113- goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
114- ) ;
115- let expected_found = ExpectedFound :: new ( false , a, b) ;
116- FulfillmentErrorCode :: CodeSubtypeError (
117- expected_found,
118- TypeError :: Sorts ( expected_found) ,
119- )
120- }
121- ty:: PredicateKind :: Clause ( _)
122- | ty:: PredicateKind :: ObjectSafe ( _)
123- | ty:: PredicateKind :: ClosureKind ( _, _, _)
124- | ty:: PredicateKind :: Ambiguous => {
125- FulfillmentErrorCode :: CodeSelectionError (
126- SelectionError :: Unimplemented ,
127- )
128- }
129- ty:: PredicateKind :: ConstEquate ( ..)
130- | ty:: PredicateKind :: TypeWellFormedFromEnv ( _) => {
131- bug ! ( "unexpected goal: {goal:?}" )
132- }
133- } ,
134- root_obligation : obligation,
135- } ) ;
136- continue ;
137- }
138- } ;
89+ let ( changed, certainty, nested_goals) =
90+ match infcx. evaluate_root_goal ( goal, GenerateProofTree :: No ) . 0 {
91+ Ok ( result) => result,
92+ Err ( NoSolution ) => {
93+ errors. push ( FulfillmentError {
94+ obligation : obligation. clone ( ) ,
95+ code : match goal. predicate . kind ( ) . skip_binder ( ) {
96+ ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( _) ) => {
97+ FulfillmentErrorCode :: CodeProjectionError (
98+ // FIXME: This could be a `Sorts` if the term is a type
99+ MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
100+ )
101+ }
102+ ty:: PredicateKind :: AliasRelate ( _, _, _) => {
103+ FulfillmentErrorCode :: CodeProjectionError (
104+ MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
105+ )
106+ }
107+ ty:: PredicateKind :: Subtype ( pred) => {
108+ let ( a, b) = infcx. instantiate_binder_with_placeholders (
109+ goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
110+ ) ;
111+ let expected_found = ExpectedFound :: new ( true , a, b) ;
112+ FulfillmentErrorCode :: CodeSubtypeError (
113+ expected_found,
114+ TypeError :: Sorts ( expected_found) ,
115+ )
116+ }
117+ ty:: PredicateKind :: Coerce ( pred) => {
118+ let ( a, b) = infcx. instantiate_binder_with_placeholders (
119+ goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
120+ ) ;
121+ let expected_found = ExpectedFound :: new ( false , a, b) ;
122+ FulfillmentErrorCode :: CodeSubtypeError (
123+ expected_found,
124+ TypeError :: Sorts ( expected_found) ,
125+ )
126+ }
127+ ty:: PredicateKind :: Clause ( _)
128+ | ty:: PredicateKind :: ObjectSafe ( _)
129+ | ty:: PredicateKind :: ClosureKind ( _, _, _)
130+ | ty:: PredicateKind :: Ambiguous => {
131+ FulfillmentErrorCode :: CodeSelectionError (
132+ SelectionError :: Unimplemented ,
133+ )
134+ }
135+ ty:: PredicateKind :: ConstEquate ( ..)
136+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( _) => {
137+ bug ! ( "unexpected goal: {goal:?}" )
138+ }
139+ } ,
140+ root_obligation : obligation,
141+ } ) ;
142+ continue ;
143+ }
144+ } ;
139145 // Push any nested goals that we get from unifying our canonical response
140146 // with our obligation onto the fulfillment context.
141147 self . obligations . extend ( nested_goals. into_iter ( ) . map ( |goal| {
0 commit comments