@@ -271,12 +271,38 @@ where
271271 /// and will need to clearly document it in the rustc-dev-guide before
272272 /// stabilization.
273273 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+ }
278291 }
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 ,
280306 }
281307 }
282308
@@ -606,7 +632,7 @@ where
606632
607633 let ( NestedNormalizationGoals ( nested_goals) , _, certainty) = self . evaluate_goal_raw (
608634 GoalEvaluationKind :: Nested ,
609- GoalSource :: Misc ,
635+ GoalSource :: normalizes_to ( ) ,
610636 unconstrained_goal,
611637 ) ?;
612638 // Add the nested goals from normalization to our own nested goals.
@@ -683,7 +709,7 @@ where
683709 pub ( super ) fn add_normalizes_to_goal ( & mut self , mut goal : Goal < I , ty:: NormalizesTo < I > > ) {
684710 goal. predicate = goal. predicate . fold_with ( & mut ReplaceAliasWithInfer :: new (
685711 self ,
686- GoalSource :: Misc ,
712+ GoalSource :: normalizes_to ( ) ,
687713 goal. param_env ,
688714 ) ) ;
689715 self . inspect . add_normalizes_to_goal ( self . delegate , self . max_input_universe , goal) ;
@@ -939,7 +965,7 @@ where
939965 rhs : T ,
940966 ) -> Result < ( ) , NoSolution > {
941967 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) ;
943969 Ok ( ( ) )
944970 }
945971
0 commit comments