@@ -271,12 +271,38 @@ 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
+ // We treat checking super trait bounds for unknowable candidates as
293
+ // unknown. Treating them is inductive would cause be unsound as it causes
294
+ // tests/ui/traits/next-solver/coherence/ambiguity-causes-visitor-hang.rs
295
+ // to compile.
296
+ GoalSource :: CoherenceUnknowableSuper => PathKind :: Unknown ,
297
+ // A step which is clearly unproductive. Cycles exclusively involving such steps
298
+ // result in `Err(NoSolution)`.
299
+ GoalSource :: MiscKnownInductive | GoalSource :: InstantiateHigherRanked => {
300
+ PathKind :: Inductive
301
+ }
302
+ // These goal sources are likely unproductive and can be changed to
303
+ // `PathKind::Inductive`. Keeping them as unknown until we're confident
304
+ // about this and have an example where it is necessary.
305
+ GoalSource :: AliasBoundConstCondition | GoalSource :: AliasWellFormed => PathKind :: Unknown ,
280
306
}
281
307
}
282
308
@@ -606,7 +632,7 @@ where
606
632
607
633
let ( NestedNormalizationGoals ( nested_goals) , _, certainty) = self . evaluate_goal_raw (
608
634
GoalEvaluationKind :: Nested ,
609
- GoalSource :: Misc ,
635
+ GoalSource :: normalizes_to ( ) ,
610
636
unconstrained_goal,
611
637
) ?;
612
638
// Add the nested goals from normalization to our own nested goals.
@@ -683,7 +709,7 @@ where
683
709
pub ( super ) fn add_normalizes_to_goal ( & mut self , mut goal : Goal < I , ty:: NormalizesTo < I > > ) {
684
710
goal. predicate = goal. predicate . fold_with ( & mut ReplaceAliasWithInfer :: new (
685
711
self ,
686
- GoalSource :: Misc ,
712
+ GoalSource :: normalizes_to ( ) ,
687
713
goal. param_env ,
688
714
) ) ;
689
715
self . inspect . add_normalizes_to_goal ( self . delegate , self . max_input_universe , goal) ;
@@ -939,7 +965,7 @@ where
939
965
rhs : T ,
940
966
) -> Result < ( ) , NoSolution > {
941
967
let goals = self . delegate . relate ( param_env, lhs, variance, rhs, self . origin_span ) ?;
942
- self . add_goals ( GoalSource :: Misc , goals) ;
968
+ self . add_goals ( GoalSource :: MiscKnownInductive , goals) ;
943
969
Ok ( ( ) )
944
970
}
945
971
0 commit comments