@@ -4,6 +4,7 @@ use super::infcx_ext::InferCtxtExt;
4
4
use super :: { CanonicalResponse , EvalCtxt , Goal , QueryResult } ;
5
5
use rustc_hir:: def_id:: DefId ;
6
6
use rustc_infer:: traits:: query:: NoSolution ;
7
+ use rustc_infer:: traits:: util:: elaborate_predicates;
7
8
use rustc_middle:: ty:: TypeFoldable ;
8
9
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
9
10
use std:: fmt:: Debug ;
@@ -119,6 +120,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
119
120
120
121
self . assemble_alias_bound_candidates ( goal, & mut candidates) ;
121
122
123
+ self . assemble_object_bound_candidates ( goal, & mut candidates) ;
124
+
122
125
candidates
123
126
}
124
127
@@ -272,4 +275,53 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
272
275
}
273
276
}
274
277
}
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
+ }
275
327
}
0 commit comments