@@ -13,8 +13,8 @@ use rustc_infer::traits::query::NoSolution;
1313use rustc_infer:: traits:: util:: supertraits;
1414use rustc_infer:: traits:: ObligationCause ;
1515use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
16- use rustc_middle:: ty:: TraitPredicate ;
1716use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
17+ use rustc_middle:: ty:: { TraitPredicate , TypeVisitable } ;
1818use rustc_span:: DUMMY_SP ;
1919use rustc_target:: spec:: abi:: Abi ;
2020
@@ -274,6 +274,53 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
274274 match_poly_trait_ref_against_goal ( acx, goal, found_trait_ref, CandidateSource :: Fn ) ;
275275 } )
276276 }
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+ }
277324}
278325
279326fn match_poly_trait_ref_against_goal < ' tcx > (
0 commit comments