@@ -271,12 +271,33 @@ where
271
271
/// and will need to clearly document it in the rustc-dev-guide before
272
272
/// stabilization.
273
273
pub ( super ) fn step_kind_for_source ( & self , source : GoalSource ) -> PathKind {
274
- match ( self . current_goal_kind , source) {
275
- ( _, GoalSource :: NormalizeGoal ( step_kind) ) => step_kind,
276
- ( CurrentGoalKind :: CoinductiveTrait , GoalSource :: ImplWhereBound ) => {
277
- PathKind :: Coinductive
274
+ match source {
275
+ // We treat these goals as unknown for now. It is likely that most, if not all
276
+ // miscellaneous nested goals will be converted to `GoalSource::MiscKnownInductive`
277
+ // over time.
278
+ GoalSource :: Misc => PathKind :: Unknown ,
279
+ GoalSource :: NormalizeGoal ( path_kind) => path_kind,
280
+ GoalSource :: ImplWhereBound => {
281
+ // We currently only consider a cycle coinductive if it steps
282
+ // into a where-clause of a coinductive trait.
283
+ //
284
+ // We probably want to make all traits coinductive in the future,
285
+ // so we treat cycles involving their where-clauses as ambiguous.
286
+ if let CurrentGoalKind :: CoinductiveTrait = self . current_goal_kind {
287
+ PathKind :: Coinductive
288
+ } else {
289
+ PathKind :: Unknown
290
+ }
278
291
}
279
- _ => PathKind :: Inductive ,
292
+ // A step which is clearly unproductive. Cycles exclusively involving such steps
293
+ // result in `Err(NoSolution)`.
294
+ GoalSource :: MiscKnownInductive | GoalSource :: InstantiateHigherRanked => {
295
+ PathKind :: Inductive
296
+ }
297
+ // These goal sources are likely unproductive and can be changed to
298
+ // `PathKind::Inductive`. Keeping them as unknown until we're confident
299
+ // about this and have an example where it is necessary.
300
+ GoalSource :: AliasBoundConstCondition | GoalSource :: AliasWellFormed => PathKind :: Unknown ,
280
301
}
281
302
}
282
303
@@ -606,7 +627,7 @@ where
606
627
607
628
let ( NestedNormalizationGoals ( nested_goals) , _, certainty) = self . evaluate_goal_raw (
608
629
GoalEvaluationKind :: Nested ,
609
- GoalSource :: Misc ,
630
+ GoalSource :: normalizes_to ( ) ,
610
631
unconstrained_goal,
611
632
) ?;
612
633
// Add the nested goals from normalization to our own nested goals.
@@ -683,7 +704,7 @@ where
683
704
pub ( super ) fn add_normalizes_to_goal ( & mut self , mut goal : Goal < I , ty:: NormalizesTo < I > > ) {
684
705
goal. predicate = goal. predicate . fold_with ( & mut ReplaceAliasWithInfer :: new (
685
706
self ,
686
- GoalSource :: Misc ,
707
+ GoalSource :: normalizes_to ( ) ,
687
708
goal. param_env ,
688
709
) ) ;
689
710
self . inspect . add_normalizes_to_goal ( self . delegate , self . max_input_universe , goal) ;
@@ -939,7 +960,16 @@ where
939
960
rhs : T ,
940
961
) -> Result < ( ) , NoSolution > {
941
962
let goals = self . delegate . relate ( param_env, lhs, variance, rhs, self . origin_span ) ?;
942
- self . add_goals ( GoalSource :: Misc , goals) ;
963
+ if cfg ! ( debug_assertions) {
964
+ for g in goals. iter ( ) {
965
+ match g. predicate . kind ( ) . skip_binder ( ) {
966
+ ty:: PredicateKind :: Subtype { .. } | ty:: PredicateKind :: AliasRelate ( ..) => { }
967
+ p => unreachable ! ( "unexpected nested goal in `relate`: {p:?}" ) ,
968
+ }
969
+ }
970
+ }
971
+ // Normalization is always unproductive.
972
+ self . add_goals ( GoalSource :: MiscKnownInductive , goals) ;
943
973
Ok ( ( ) )
944
974
}
945
975
0 commit comments