@@ -4,13 +4,13 @@ use std::iter;
44
55use super :: assembly:: { self , Candidate , CandidateSource } ;
66use super :: infcx_ext:: InferCtxtExt ;
7- use super :: { EvalCtxt , Goal , QueryResult } ;
7+ use super :: { Certainty , EvalCtxt , Goal , QueryResult } ;
88use rustc_hir:: def_id:: DefId ;
99use rustc_infer:: infer:: InferCtxt ;
1010use rustc_infer:: traits:: query:: NoSolution ;
1111use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
12- use rustc_middle:: ty:: TraitPredicate ;
1312use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
13+ use rustc_middle:: ty:: { TraitPredicate , TypeVisitable } ;
1414use rustc_span:: DUMMY_SP ;
1515
1616mod structural_traits;
@@ -127,6 +127,29 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
127127 structural_traits:: instantiate_constituent_tys_for_copy_clone_trait,
128128 )
129129 }
130+
131+ fn consider_builtin_pointer_sized_candidate (
132+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
133+ goal : Goal < ' tcx , Self > ,
134+ ) -> QueryResult < ' tcx > {
135+ if goal. predicate . self_ty ( ) . has_non_region_infer ( ) {
136+ return ecx. make_canonical_response ( Certainty :: Maybe ( MaybeCause :: Ambiguity ) ) ;
137+ }
138+
139+ let tcx = ecx. tcx ( ) ;
140+ let self_ty = tcx. erase_regions ( goal. predicate . self_ty ( ) ) ;
141+
142+ if let Ok ( layout) = tcx. layout_of ( goal. param_env . and ( self_ty) )
143+ && let usize_layout = tcx. layout_of ( ty:: ParamEnv :: empty ( ) . and ( tcx. types . usize ) ) . unwrap ( ) . layout
144+ && layout. layout . size ( ) == usize_layout. size ( )
145+ && layout. layout . align ( ) . abi == usize_layout. align ( ) . abi
146+ {
147+ // FIXME: We could make this faster by making a no-constraints response
148+ ecx. make_canonical_response ( Certainty :: Yes )
149+ } else {
150+ Err ( NoSolution )
151+ }
152+ }
130153}
131154
132155impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
0 commit comments