@@ -286,18 +286,23 @@ where
286
286
// fixing it may cause inference breakage or introduce ambiguity.
287
287
GoalSource :: Misc => PathKind :: Unknown ,
288
288
GoalSource :: NormalizeGoal ( path_kind) => path_kind,
289
- GoalSource :: ImplWhereBound => {
289
+ GoalSource :: ImplWhereBound => match self . current_goal_kind {
290
290
// We currently only consider a cycle coinductive if it steps
291
291
// into a where-clause of a coinductive trait.
292
+ CurrentGoalKind :: CoinductiveTrait => PathKind :: Coinductive ,
293
+ // While normalizing via an impl does step into a where-clause of
294
+ // an impl, accessing the associated item immediately steps out of
295
+ // it again. This means cycles/recursive calls are not guarded
296
+ // by impls used for normalization.
292
297
//
298
+ // See tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.rs
299
+ // for how this can go wrong.
300
+ CurrentGoalKind :: NormalizesTo => PathKind :: Inductive ,
293
301
// We probably want to make all traits coinductive in the future,
294
- // so we treat cycles involving their where-clauses as ambiguous.
295
- if let CurrentGoalKind :: CoinductiveTrait = self . current_goal_kind {
296
- PathKind :: Coinductive
297
- } else {
298
- PathKind :: Unknown
299
- }
300
- }
302
+ // so we treat cycles involving where-clauses of not-yet coinductive
303
+ // traits as ambiguous for now.
304
+ CurrentGoalKind :: Misc => PathKind :: Unknown ,
305
+ } ,
301
306
// Relating types is always unproductive. If we were to map proof trees to
302
307
// corecursive functions as explained in #136824, relating types never
303
308
// introduces a constructor which could cause the recursion to be guarded.
0 commit comments