@@ -217,8 +217,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
217
217
}
218
218
219
219
selcx. infcx . probe ( |_| {
220
- let bound =
221
- util:: unelaborated_sizedness_candidate ( selcx. infcx , obligation, bound) ;
220
+ if util:: unelaborated_sizedness_candidate ( selcx. infcx , obligation, bound)
221
+ . is_some ( )
222
+ {
223
+ candidates. vec . push ( ProjectionCandidate ( idx) ) ;
224
+ return ;
225
+ }
222
226
223
227
// We checked the polarity already
224
228
match selcx. match_normalize_trait_ref (
@@ -258,26 +262,32 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
258
262
) -> Result < ( ) , SelectionError < ' tcx > > {
259
263
debug ! ( ?stack. obligation) ;
260
264
265
+ if let Some ( bound) = stack
266
+ . obligation
267
+ . param_env
268
+ . caller_bounds ( )
269
+ . iter ( )
270
+ . filter_map ( |p| p. as_trait_clause ( ) )
271
+ . find_map ( |p| util:: unelaborated_sizedness_candidate ( self . infcx , stack. obligation , p) )
272
+ {
273
+ candidates. vec . push ( ParamCandidate ( bound) ) ;
274
+ return Ok ( ( ) ) ;
275
+ }
276
+
261
277
let bounds = stack
262
278
. obligation
263
279
. param_env
264
280
. caller_bounds ( )
265
281
. iter ( )
266
282
. filter_map ( |p| p. as_trait_clause ( ) )
267
- // Micro-optimization: filter out predicates with different polarities.
283
+ // Micro-optimization: filter out predicates relating to different traits.
284
+ . filter ( |p| p. def_id ( ) == stack. obligation . predicate . def_id ( ) )
268
285
. filter ( |p| p. polarity ( ) == stack. obligation . predicate . polarity ( ) ) ;
269
286
270
287
let drcx = DeepRejectCtxt :: relate_rigid_rigid ( self . tcx ( ) ) ;
271
288
let obligation_args = stack. obligation . predicate . skip_binder ( ) . trait_ref . args ;
272
289
// Keep only those bounds which may apply, and propagate overflow if it occurs.
273
290
for bound in bounds {
274
- let bound = util:: unelaborated_sizedness_candidate ( self . infcx , stack. obligation , bound) ;
275
-
276
- // Micro-optimization: filter out predicates relating to different traits.
277
- if bound. def_id ( ) != stack. obligation . predicate . def_id ( ) {
278
- continue ;
279
- }
280
-
281
291
let bound_trait_ref = bound. map_bound ( |t| t. trait_ref ) ;
282
292
if !drcx. args_may_unify ( obligation_args, bound_trait_ref. skip_binder ( ) . args ) {
283
293
continue ;
0 commit comments