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