@@ -13,8 +13,8 @@ use rustc_infer::traits::query::NoSolution;
13
13
use rustc_infer:: traits:: util:: supertraits;
14
14
use rustc_infer:: traits:: ObligationCause ;
15
15
use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
16
- use rustc_middle:: ty:: TraitPredicate ;
17
16
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
17
+ use rustc_middle:: ty:: { TraitPredicate , TypeVisitable } ;
18
18
use rustc_span:: DUMMY_SP ;
19
19
use rustc_target:: spec:: abi:: Abi ;
20
20
@@ -274,6 +274,53 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
274
274
match_poly_trait_ref_against_goal ( acx, goal, found_trait_ref, CandidateSource :: Fn ) ;
275
275
} )
276
276
}
277
+
278
+ fn consider_builtin_trait_candidates (
279
+ acx : & mut AssemblyCtxt < ' _ , ' tcx , Self > ,
280
+ goal : Goal < ' tcx , Self > ,
281
+ ) {
282
+ let lang_items = acx. cx . tcx . lang_items ( ) ;
283
+ let trait_def_id = goal. predicate . def_id ( ) ;
284
+ let self_ty = goal. predicate . self_ty ( ) ;
285
+
286
+ if Some ( trait_def_id) == lang_items. sized_trait ( ) {
287
+ if self_ty. is_trivially_sized ( acx. cx . tcx ) {
288
+ acx. try_insert_candidate ( CandidateSource :: Builtin , Certainty :: Yes ) ;
289
+ }
290
+ } else if Some ( trait_def_id) == lang_items. copy_trait ( )
291
+ || Some ( trait_def_id) == lang_items. clone_trait ( )
292
+ {
293
+ // FIXME
294
+ } else if Some ( trait_def_id) == lang_items. discriminant_kind_trait ( )
295
+ || Some ( trait_def_id) == lang_items. pointee_trait ( )
296
+ {
297
+ // `Pointee` and `DiscriminantKind` are implemented by all traits unconditionally
298
+ acx. try_insert_candidate ( CandidateSource :: Builtin , Certainty :: Yes ) ;
299
+ } else if Some ( trait_def_id) == lang_items. tuple_trait ( ) {
300
+ match * self_ty. kind ( ) {
301
+ ty:: Infer ( ty:: TyVar ( _) ) => todo ! ( "ambiguous" ) ,
302
+ ty:: Tuple ( _) => acx. try_insert_candidate ( CandidateSource :: Builtin , Certainty :: Yes ) ,
303
+ _ => { }
304
+ }
305
+ } else if Some ( trait_def_id) == lang_items. pointer_sized ( ) {
306
+ let erased_self_ty = acx. cx . tcx . erase_regions ( self_ty) ;
307
+ if erased_self_ty. has_non_region_infer ( ) {
308
+ todo ! ( "ambiguous" )
309
+ }
310
+ let usize_layout =
311
+ acx. cx . tcx . layout_of ( ty:: ParamEnv :: empty ( ) . and ( acx. cx . tcx . types . usize ) ) . unwrap ( ) ;
312
+ if let Ok ( layout) = acx. cx . tcx . layout_of ( goal. param_env . and ( self_ty) )
313
+ && layout. layout . size ( ) == usize_layout. layout . size ( )
314
+ && layout. layout . align ( ) . abi == usize_layout. layout . align ( ) . abi
315
+ {
316
+ acx. try_insert_candidate ( CandidateSource :: Builtin , Certainty :: Yes ) ;
317
+ }
318
+ } else if Some ( trait_def_id) == lang_items. coerce_unsized_trait ( )
319
+ || Some ( trait_def_id) == lang_items. unsize_trait ( )
320
+ {
321
+ // FIXME
322
+ }
323
+ }
277
324
}
278
325
279
326
fn match_poly_trait_ref_against_goal < ' tcx > (
0 commit comments