@@ -6,6 +6,7 @@ use super::assembly::{self, Candidate, CandidateSource};
6
6
use super :: infcx_ext:: InferCtxtExt ;
7
7
use super :: { EvalCtxt , Goal , QueryResult } ;
8
8
use rustc_hir:: def_id:: DefId ;
9
+ use rustc_hir:: { Movability , Mutability } ;
9
10
use rustc_infer:: infer:: InferCtxt ;
10
11
use rustc_infer:: traits:: query:: NoSolution ;
11
12
use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
@@ -106,10 +107,27 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
106
107
}
107
108
108
109
fn consider_builtin_sized_candidate (
109
- _ecx : & mut EvalCtxt < ' _ , ' tcx > ,
110
- _goal : Goal < ' tcx , Self > ,
110
+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
111
+ goal : Goal < ' tcx , Self > ,
111
112
) -> QueryResult < ' tcx > {
112
- unimplemented ! ( ) ;
113
+ ecx. infcx . probe ( |_| {
114
+ let constituent_tys =
115
+ instantiate_constituent_tys_for_sized_trait ( ecx. infcx , goal. predicate . self_ty ( ) ) ?;
116
+ ecx. evaluate_goal_for_constituent_tys_and_make_canonical_response ( goal, constituent_tys)
117
+ } )
118
+ }
119
+
120
+ fn consider_builtin_copy_clone_candidate (
121
+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
122
+ goal : Goal < ' tcx , Self > ,
123
+ ) -> QueryResult < ' tcx > {
124
+ ecx. infcx . probe ( |_| {
125
+ let constituent_tys = instantiate_constituent_tys_for_copy_clone_trait (
126
+ ecx. infcx ,
127
+ goal. predicate . self_ty ( ) ,
128
+ ) ?;
129
+ ecx. evaluate_goal_for_constituent_tys_and_make_canonical_response ( goal, constituent_tys)
130
+ } )
113
131
}
114
132
}
115
133
@@ -278,3 +296,116 @@ fn instantiate_constituent_tys_for_auto_trait<'tcx>(
278
296
}
279
297
}
280
298
}
299
+
300
+ fn instantiate_constituent_tys_for_sized_trait < ' tcx > (
301
+ infcx : & InferCtxt < ' tcx > ,
302
+ ty : Ty < ' tcx > ,
303
+ ) -> Result < Vec < Ty < ' tcx > > , NoSolution > {
304
+ match * ty. kind ( ) {
305
+ ty:: Infer ( ty:: IntVar ( _) | ty:: FloatVar ( _) )
306
+ | ty:: Uint ( _)
307
+ | ty:: Int ( _)
308
+ | ty:: Bool
309
+ | ty:: Float ( _)
310
+ | ty:: FnDef ( ..)
311
+ | ty:: FnPtr ( _)
312
+ | ty:: RawPtr ( ..)
313
+ | ty:: Char
314
+ | ty:: Ref ( ..)
315
+ | ty:: Generator ( ..)
316
+ | ty:: GeneratorWitness ( ..)
317
+ | ty:: Array ( ..)
318
+ | ty:: Closure ( ..)
319
+ | ty:: Never
320
+ | ty:: Dynamic ( _, _, ty:: DynStar )
321
+ | ty:: Error ( _) => Ok ( vec ! [ ] ) ,
322
+
323
+ ty:: Str
324
+ | ty:: Slice ( _)
325
+ | ty:: Dynamic ( ..)
326
+ | ty:: Foreign ( ..)
327
+ | ty:: Alias ( ..)
328
+ | ty:: Param ( _) => Err ( NoSolution ) ,
329
+
330
+ ty:: Infer ( ty:: TyVar ( _) ) => bug ! ( "FIXME: ambiguous" ) ,
331
+
332
+ ty:: Placeholder ( ..)
333
+ | ty:: Bound ( ..)
334
+ | ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => bug ! ( ) ,
335
+
336
+ ty:: Tuple ( tys) => Ok ( tys. to_vec ( ) ) ,
337
+
338
+ ty:: Adt ( def, substs) => {
339
+ let sized_crit = def. sized_constraint ( infcx. tcx ) ;
340
+ Ok ( sized_crit
341
+ . 0
342
+ . iter ( )
343
+ . map ( |ty| sized_crit. rebind ( * ty) . subst ( infcx. tcx , substs) )
344
+ . collect ( ) )
345
+ }
346
+ }
347
+ }
348
+
349
+ fn instantiate_constituent_tys_for_copy_clone_trait < ' tcx > (
350
+ infcx : & InferCtxt < ' tcx > ,
351
+ ty : Ty < ' tcx > ,
352
+ ) -> Result < Vec < Ty < ' tcx > > , NoSolution > {
353
+ match * ty. kind ( ) {
354
+ ty:: Infer ( ty:: IntVar ( _) | ty:: FloatVar ( _) )
355
+ | ty:: FnDef ( ..)
356
+ | ty:: FnPtr ( _)
357
+ | ty:: Error ( _) => Ok ( vec ! [ ] ) ,
358
+
359
+ // Implementations are provided in core
360
+ ty:: Uint ( _)
361
+ | ty:: Int ( _)
362
+ | ty:: Bool
363
+ | ty:: Float ( _)
364
+ | ty:: Char
365
+ | ty:: RawPtr ( ..)
366
+ | ty:: Never
367
+ | ty:: Ref ( _, _, Mutability :: Not )
368
+ | ty:: Array ( ..) => Err ( NoSolution ) ,
369
+
370
+ ty:: Dynamic ( ..)
371
+ | ty:: Str
372
+ | ty:: Slice ( _)
373
+ | ty:: Generator ( _, _, Movability :: Static )
374
+ | ty:: Foreign ( ..)
375
+ | ty:: Ref ( _, _, Mutability :: Mut )
376
+ | ty:: Adt ( _, _)
377
+ | ty:: Alias ( _, _)
378
+ | ty:: Param ( _) => Err ( NoSolution ) ,
379
+
380
+ ty:: Infer ( ty:: TyVar ( _) ) => bug ! ( "FIXME: ambiguous" ) ,
381
+
382
+ ty:: Placeholder ( ..)
383
+ | ty:: Bound ( ..)
384
+ | ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => bug ! ( ) ,
385
+
386
+ ty:: Tuple ( tys) => Ok ( tys. to_vec ( ) ) ,
387
+
388
+ ty:: Closure ( _, substs) => match * substs. as_closure ( ) . tupled_upvars_ty ( ) . kind ( ) {
389
+ ty:: Tuple ( tys) => Ok ( tys. to_vec ( ) ) ,
390
+ ty:: Infer ( ty:: TyVar ( _) ) => bug ! ( "FIXME: ambiguous" ) ,
391
+ _ => bug ! ( ) ,
392
+ } ,
393
+
394
+ ty:: Generator ( _, substs, Movability :: Movable ) => {
395
+ if infcx. tcx . features ( ) . generator_clone {
396
+ let generator = substs. as_generator ( ) ;
397
+ match * generator. tupled_upvars_ty ( ) . kind ( ) {
398
+ ty:: Tuple ( tys) => Ok ( tys. iter ( ) . chain ( [ generator. witness ( ) ] ) . collect ( ) ) ,
399
+ ty:: Infer ( ty:: TyVar ( _) ) => bug ! ( "FIXME: ambiguous" ) ,
400
+ _ => bug ! ( ) ,
401
+ }
402
+ } else {
403
+ Err ( NoSolution )
404
+ }
405
+ }
406
+
407
+ ty:: GeneratorWitness ( types) => {
408
+ Ok ( infcx. replace_bound_vars_with_placeholders ( types) . to_vec ( ) )
409
+ }
410
+ }
411
+ }
0 commit comments