@@ -4,6 +4,7 @@ use super::infcx_ext::InferCtxtExt;
44use super :: { CanonicalResponse , EvalCtxt , Goal , QueryResult } ;
55use rustc_hir:: def_id:: DefId ;
66use rustc_infer:: traits:: query:: NoSolution ;
7+ use rustc_infer:: traits:: util:: elaborate_predicates;
78use rustc_middle:: ty:: TypeFoldable ;
89use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
910use std:: fmt:: Debug ;
@@ -119,6 +120,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
119120
120121 self . assemble_alias_bound_candidates ( goal, & mut candidates) ;
121122
123+ self . assemble_object_bound_candidates ( goal, & mut candidates) ;
124+
122125 candidates
123126 }
124127
@@ -272,4 +275,53 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
272275 }
273276 }
274277 }
278+
279+ fn assemble_object_bound_candidates < G : GoalKind < ' tcx > > (
280+ & mut self ,
281+ goal : Goal < ' tcx , G > ,
282+ candidates : & mut Vec < Candidate < ' tcx > > ,
283+ ) {
284+ let self_ty = goal. predicate . self_ty ( ) ;
285+ let bounds = match * self_ty. kind ( ) {
286+ ty:: Bool
287+ | ty:: Char
288+ | ty:: Int ( _)
289+ | ty:: Uint ( _)
290+ | ty:: Float ( _)
291+ | ty:: Adt ( _, _)
292+ | ty:: Foreign ( _)
293+ | ty:: Str
294+ | ty:: Array ( _, _)
295+ | ty:: Slice ( _)
296+ | ty:: RawPtr ( _)
297+ | ty:: Ref ( _, _, _)
298+ | ty:: FnDef ( _, _)
299+ | ty:: FnPtr ( _)
300+ | ty:: Alias ( ..)
301+ | ty:: Closure ( ..)
302+ | ty:: Generator ( ..)
303+ | ty:: GeneratorWitness ( _)
304+ | ty:: Never
305+ | ty:: Tuple ( _)
306+ | ty:: Param ( _)
307+ | ty:: Placeholder ( ..)
308+ | ty:: Infer ( _)
309+ | ty:: Error ( _) => return ,
310+ ty:: Bound ( ..) => bug ! ( "unexpected bound type: {goal:?}" ) ,
311+ ty:: Dynamic ( bounds, ..) => bounds,
312+ } ;
313+
314+ let tcx = self . tcx ( ) ;
315+ for assumption in
316+ elaborate_predicates ( tcx, bounds. iter ( ) . map ( |bound| bound. with_self_ty ( tcx, self_ty) ) )
317+ {
318+ match G :: consider_assumption ( self , goal, assumption. predicate )
319+ {
320+ Ok ( result) => {
321+ candidates. push ( Candidate { source : CandidateSource :: BuiltinImpl , result } )
322+ }
323+ Err ( NoSolution ) => ( ) ,
324+ }
325+ }
326+ }
275327}
0 commit comments