@@ -49,7 +49,7 @@ fn assemble_clauses_from_assoc_ty_values<'tcx>(
49
49
}
50
50
51
51
52
- fn program_clauses_for_raw_ptr < ' tcx > (
52
+ fn wf_clause_for_raw_ptr < ' tcx > (
53
53
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
54
54
mutbl : hir:: Mutability
55
55
) -> Clauses < ' tcx > {
@@ -66,7 +66,7 @@ fn program_clauses_for_raw_ptr<'tcx>(
66
66
tcx. mk_clauses ( iter:: once ( wf_clause) )
67
67
}
68
68
69
- fn program_clauses_for_fn_ptr < ' tcx > (
69
+ fn wf_clause_for_fn_ptr < ' tcx > (
70
70
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
71
71
arity_and_output : usize ,
72
72
variadic : bool ,
@@ -87,7 +87,7 @@ fn program_clauses_for_fn_ptr<'tcx>(
87
87
tcx. mk_clauses ( iter:: once ( wf_clause) )
88
88
}
89
89
90
- fn program_clauses_for_slice < ' tcx > ( tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ) -> Clauses < ' tcx > {
90
+ fn wf_clause_for_slice < ' tcx > ( tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ) -> Clauses < ' tcx > {
91
91
let ty = generic_types:: bound ( tcx, 0 ) ;
92
92
let slice_ty = tcx. mk_slice ( ty) ;
93
93
@@ -116,7 +116,7 @@ fn program_clauses_for_slice<'tcx>(tcx: ty::TyCtxt<'_, '_, 'tcx>) -> Clauses<'tc
116
116
tcx. mk_clauses ( iter:: once ( wf_clause) )
117
117
}
118
118
119
- fn program_clauses_for_array < ' tcx > (
119
+ fn wf_clause_for_array < ' tcx > (
120
120
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
121
121
length : & ' tcx ty:: Const < ' tcx >
122
122
) -> Clauses < ' tcx > {
@@ -148,7 +148,7 @@ fn program_clauses_for_array<'tcx>(
148
148
tcx. mk_clauses ( iter:: once ( wf_clause) )
149
149
}
150
150
151
- fn program_clauses_for_tuple < ' tcx > (
151
+ fn wf_clause_for_tuple < ' tcx > (
152
152
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
153
153
arity : usize
154
154
) -> Clauses < ' tcx > {
@@ -189,7 +189,7 @@ fn program_clauses_for_tuple<'tcx>(
189
189
tcx. mk_clauses ( iter:: once ( wf_clause) )
190
190
}
191
191
192
- fn program_clauses_for_ref < ' tcx > (
192
+ fn wf_clause_for_ref < ' tcx > (
193
193
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
194
194
mutbl : hir:: Mutability
195
195
) -> Clauses < ' tcx > {
@@ -202,13 +202,16 @@ fn program_clauses_for_ref<'tcx>(
202
202
mutbl,
203
203
} ) ;
204
204
205
- let outlives : DomainGoal = ty:: OutlivesPredicate ( ty, region) . lower ( ) ;
205
+ let _outlives : DomainGoal = ty:: OutlivesPredicate ( ty, region) . lower ( ) ;
206
206
let wf_clause = ProgramClause {
207
207
goal : DomainGoal :: WellFormed ( WellFormed :: Ty ( ref_ty) ) ,
208
- hypotheses : tcx. mk_goals (
209
- iter:: once ( tcx. mk_goal ( outlives. into_goal ( ) ) )
210
- ) ,
211
- category : ProgramClauseCategory :: ImpliedBound ,
208
+ hypotheses : ty:: List :: empty ( ) ,
209
+
210
+ // FIXME: restore this later once we get better at handling regions
211
+ // hypotheses: tcx.mk_goals(
212
+ // iter::once(tcx.mk_goal(outlives.into_goal()))
213
+ // ),
214
+ category : ProgramClauseCategory :: WellFormed ,
212
215
} ;
213
216
let wf_clause = Clause :: ForAll ( ty:: Binder :: bind ( wf_clause) ) ;
214
217
@@ -323,6 +326,8 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
323
326
ty:: Float ( ..) |
324
327
ty:: Str |
325
328
ty:: Param ( ..) |
329
+ ty:: Placeholder ( ..) |
330
+ ty:: Error |
326
331
ty:: Never => {
327
332
let wf_clause = ProgramClause {
328
333
goal : DomainGoal :: WellFormed ( WellFormed :: Ty ( ty) ) ,
@@ -335,12 +340,12 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
335
340
}
336
341
337
342
// Always WF (recall that we do not check for parameters to be WF).
338
- ty:: RawPtr ( ptr) => program_clauses_for_raw_ptr ( self . infcx . tcx , ptr. mutbl ) ,
343
+ ty:: RawPtr ( ptr) => wf_clause_for_raw_ptr ( self . infcx . tcx , ptr. mutbl ) ,
339
344
340
345
// Always WF (recall that we do not check for parameters to be WF).
341
346
ty:: FnPtr ( fn_ptr) => {
342
347
let fn_ptr = fn_ptr. skip_binder ( ) ;
343
- program_clauses_for_fn_ptr (
348
+ wf_clause_for_fn_ptr (
344
349
self . infcx . tcx ,
345
350
fn_ptr. inputs_and_output . len ( ) ,
346
351
fn_ptr. variadic ,
@@ -350,19 +355,19 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
350
355
}
351
356
352
357
// WF if inner type is `Sized`.
353
- ty:: Slice ( ..) => program_clauses_for_slice ( self . infcx . tcx ) ,
358
+ ty:: Slice ( ..) => wf_clause_for_slice ( self . infcx . tcx ) ,
354
359
355
360
// WF if inner type is `Sized`.
356
- ty:: Array ( _, length) => program_clauses_for_array ( self . infcx . tcx , length) ,
361
+ ty:: Array ( _, length) => wf_clause_for_array ( self . infcx . tcx , length) ,
357
362
358
363
// WF if all types but the last one are `Sized`.
359
- ty:: Tuple ( types) => program_clauses_for_tuple (
364
+ ty:: Tuple ( types) => wf_clause_for_tuple (
360
365
self . infcx . tcx ,
361
366
types. len ( )
362
367
) ,
363
368
364
369
// WF if `sub_ty` outlives `region`.
365
- ty:: Ref ( _, _, mutbl) => program_clauses_for_ref ( self . infcx . tcx , mutbl) ,
370
+ ty:: Ref ( _, _, mutbl) => wf_clause_for_ref ( self . infcx . tcx , mutbl) ,
366
371
367
372
ty:: Dynamic ( ..) => {
368
373
// FIXME: no rules yet for trait objects
@@ -381,12 +386,24 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
381
386
self . infcx . tcx . program_clauses_for ( def_id)
382
387
}
383
388
389
+ // Artificially trigger an ambiguity.
390
+ ty:: Infer ( ..) => {
391
+ let tcx = self . infcx . tcx ;
392
+ let types = [ tcx. types . i32 , tcx. types . u32 , tcx. types . f32 , tcx. types . f64 ] ;
393
+ let clauses = types. iter ( )
394
+ . cloned ( )
395
+ . map ( |ty| ProgramClause {
396
+ goal : DomainGoal :: WellFormed ( WellFormed :: Ty ( ty) ) ,
397
+ hypotheses : ty:: List :: empty ( ) ,
398
+ category : ProgramClauseCategory :: WellFormed ,
399
+ } )
400
+ . map ( |clause| Clause :: Implies ( clause) ) ;
401
+ tcx. mk_clauses ( clauses)
402
+ }
403
+
384
404
ty:: GeneratorWitness ( ..) |
385
- ty:: Placeholder ( ..) |
386
405
ty:: UnnormalizedProjection ( ..) |
387
- ty:: Infer ( ..) |
388
- ty:: Bound ( ..) |
389
- ty:: Error => {
406
+ ty:: Bound ( ..) => {
390
407
bug ! ( "unexpected type {:?}" , ty)
391
408
}
392
409
} ;
0 commit comments