@@ -290,6 +290,33 @@ impl<'tcx> BestObligation<'tcx> {
290
290
ControlFlow :: Continue ( ( ) )
291
291
}
292
292
}
293
+
294
+ /// It is likely that `NormalizesTo` failed without any applicable candidates
295
+ /// because the alias is not well-formed.
296
+ ///
297
+ /// As we only enter `RigidAlias` candidates if the trait bound of the associated type
298
+ /// holds, we discard these candidates in `non_trivial_candidates` and always manually
299
+ /// check this here.
300
+ fn detect_non_well_formed_assoc_item (
301
+ & mut self ,
302
+ goal : & inspect:: InspectGoal < ' _ , ' tcx > ,
303
+ alias : ty:: AliasTerm < ' tcx > ,
304
+ ) -> ControlFlow < PredicateObligation < ' tcx > > {
305
+ let tcx = goal. infcx ( ) . tcx ;
306
+ let obligation = Obligation :: new (
307
+ tcx,
308
+ self . obligation . cause . clone ( ) ,
309
+ goal. goal ( ) . param_env ,
310
+ alias. trait_ref ( tcx) ,
311
+ ) ;
312
+ self . with_derived_obligation ( obligation, |this| {
313
+ goal. infcx ( ) . visit_proof_tree_at_depth (
314
+ goal. goal ( ) . with ( tcx, alias. trait_ref ( tcx) ) ,
315
+ goal. depth ( ) + 1 ,
316
+ this,
317
+ )
318
+ } )
319
+ }
293
320
}
294
321
295
322
impl < ' tcx > ProofTreeVisitor < ' tcx > for BestObligation < ' tcx > {
@@ -321,23 +348,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
321
348
| ty:: AliasTermKind :: ProjectionConst = pred. alias . kind ( tcx) =>
322
349
{
323
350
self . detect_error_in_self_ty_normalization ( goal, pred. alias . self_ty ( ) ) ?;
324
- // It is likely that `NormalizesTo` failed because the alias is not well-formed.
325
- // As we only enter `RigidAlias` candidates if the trait bound of the associated type
326
- // holds, we discard these candidates in `non_trivial_candidates` and always manually
327
- // check this here.
328
- let obligation = Obligation :: new (
329
- tcx,
330
- self . obligation . cause . clone ( ) ,
331
- goal. goal ( ) . param_env ,
332
- pred. alias . trait_ref ( tcx) ,
333
- ) ;
334
- self . with_derived_obligation ( obligation, |this| {
335
- goal. infcx ( ) . visit_proof_tree_at_depth (
336
- goal. goal ( ) . with ( tcx, pred. alias . trait_ref ( tcx) ) ,
337
- goal. depth ( ) + 1 ,
338
- this,
339
- )
340
- } ) ?;
351
+ self . detect_non_well_formed_assoc_item ( goal, pred. alias ) ?;
341
352
}
342
353
Some ( _) | None => { }
343
354
}
0 commit comments