@@ -3,6 +3,7 @@ use self::env_elaborator::elaborate_env_clauses;
3
3
use self :: program_clauses:: ToProgramClauses ;
4
4
use crate :: split:: Split ;
5
5
use crate :: RustIrDatabase ;
6
+ use chalk_engine:: context:: Floundered ;
6
7
use chalk_ir:: cast:: Cast ;
7
8
use chalk_ir:: could_match:: CouldMatch ;
8
9
use chalk_ir:: interner:: Interner ;
@@ -102,8 +103,6 @@ pub fn push_auto_trait_impls<I: Interner>(
102
103
} ) ;
103
104
}
104
105
105
- // TODO add Floundered error instead of using Option
106
-
107
106
/// Given some goal `goal` that must be proven, along with
108
107
/// its `environment`, figures out the program clauses that apply
109
108
/// to this goal from the Rust program. So for example if the goal
@@ -113,7 +112,7 @@ pub(crate) fn program_clauses_for_goal<'db, I: Interner>(
113
112
db : & ' db dyn RustIrDatabase < I > ,
114
113
environment : & Environment < I > ,
115
114
goal : & DomainGoal < I > ,
116
- ) -> Option < Vec < ProgramClause < I > > > {
115
+ ) -> Result < Vec < ProgramClause < I > > , Floundered > {
117
116
debug_heading ! (
118
117
"program_clauses_for_goal(goal={:?}, environment={:?})" ,
119
118
goal,
@@ -129,7 +128,7 @@ pub(crate) fn program_clauses_for_goal<'db, I: Interner>(
129
128
130
129
debug ! ( "vec = {:#?}" , vec) ;
131
130
132
- Some ( vec)
131
+ Ok ( vec)
133
132
}
134
133
135
134
/// Returns a set of program clauses that could possibly match
@@ -141,7 +140,7 @@ fn program_clauses_that_could_match<I: Interner>(
141
140
environment : & Environment < I > ,
142
141
goal : & DomainGoal < I > ,
143
142
clauses : & mut Vec < ProgramClause < I > > ,
144
- ) -> Option < ( ) > {
143
+ ) -> Result < ( ) , Floundered > {
145
144
let interner = db. interner ( ) ;
146
145
let builder = & mut ClauseBuilder :: new ( db, clauses) ;
147
146
@@ -154,7 +153,7 @@ fn program_clauses_that_could_match<I: Interner>(
154
153
if trait_datum. is_non_enumerable_trait ( ) || trait_datum. is_auto_trait ( ) {
155
154
let self_ty = trait_ref. self_type_parameter ( interner) ;
156
155
if self_ty. bound ( interner) . is_some ( ) || self_ty. inference_var ( interner) . is_some ( ) {
157
- return None ;
156
+ return Err ( Floundered ) ;
158
157
}
159
158
}
160
159
@@ -180,7 +179,7 @@ fn program_clauses_that_could_match<I: Interner>(
180
179
}
181
180
}
182
181
TyData :: InferenceVar ( _) | TyData :: BoundVar ( _) => {
183
- return None ;
182
+ return Err ( Floundered ) ;
184
183
}
185
184
_ => { }
186
185
}
@@ -306,7 +305,7 @@ fn program_clauses_that_could_match<I: Interner>(
306
305
DomainGoal :: Compatible ( ( ) ) => ( ) ,
307
306
} ;
308
307
309
- Some ( ( ) )
308
+ Ok ( ( ) )
310
309
}
311
310
312
311
/// Generate program clauses from the associated-type values
@@ -367,9 +366,9 @@ fn match_ty<I: Interner>(
367
366
builder : & mut ClauseBuilder < ' _ , I > ,
368
367
environment : & Environment < I > ,
369
368
ty : & Ty < I > ,
370
- ) -> Option < ( ) > {
369
+ ) -> Result < ( ) , Floundered > {
371
370
let interner = builder. interner ( ) ;
372
- Some ( match ty. data ( interner) {
371
+ Ok ( match ty. data ( interner) {
373
372
TyData :: Apply ( application_ty) => match_type_name ( builder, application_ty. name ) ,
374
373
TyData :: Placeholder ( _) => {
375
374
builder. push_clause ( WellFormed :: Ty ( ty. clone ( ) ) , Some ( FromEnv :: Ty ( ty. clone ( ) ) ) ) ;
@@ -385,9 +384,9 @@ fn match_ty<I: Interner>(
385
384
. iter ( interner)
386
385
. map ( |p| p. assert_ty_ref ( interner) )
387
386
. map ( |ty| match_ty ( builder, environment, & ty) )
388
- . collect :: < Option < _ > > ( ) ?;
387
+ . collect :: < Result < _ , Floundered > > ( ) ?;
389
388
}
390
- TyData :: BoundVar ( _) | TyData :: InferenceVar ( _) => return None ,
389
+ TyData :: BoundVar ( _) | TyData :: InferenceVar ( _) => return Err ( Floundered ) ,
391
390
TyData :: Dyn ( _) => { }
392
391
} )
393
392
}
0 commit comments