Skip to content

Commit 68f64af

Browse files
committed
propagate nested goal path kind
1 parent 75948c8 commit 68f64af

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ where
275275
// as inductive even though it should not be, it may be unsound during coherence and
276276
// fixing it may cause inference breakage or introduce ambiguity.
277277
GoalSource::Misc => PathKind::Unknown,
278-
GoalSource::NormalizeGoal(path_kind) => path_kind,
278+
GoalSource::NormalizeGoal(path_kind)
279+
| GoalSource::NestedNormalizationGoal(path_kind) => path_kind,
279280
GoalSource::ImplWhereBound => match self.current_goal_kind {
280281
// We currently only consider a cycle coinductive if it steps
281282
// into a where-clause of a coinductive trait.
@@ -679,7 +680,11 @@ where
679680
) = self.evaluate_goal_raw(source, unconstrained_goal, stalled_on)?;
680681
// Add the nested goals from normalization to our own nested goals.
681682
trace!(?nested_goals);
682-
self.nested_goals.extend(nested_goals.into_iter().map(|(s, g)| (s, g, None)));
683+
self.nested_goals.extend(
684+
nested_goals
685+
.into_iter()
686+
.map(|(s, g)| (GoalSource::NestedNormalizationGoal(s), g, None)),
687+
);
683688

684689
// Finally, equate the goal's RHS with the unconstrained var.
685690
//
@@ -1258,7 +1263,10 @@ where
12581263
(
12591264
Certainty::Yes,
12601265
NestedNormalizationGoals(
1261-
goals.into_iter().map(|(s, g, _)| (s, g)).collect(),
1266+
goals
1267+
.into_iter()
1268+
.map(|(s, g, _)| (self.step_kind_for_source(s), g))
1269+
.collect(),
12621270
),
12631271
)
12641272
}

compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,10 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
495495
match (child_mode, nested_goal.source()) {
496496
(
497497
ChildMode::Trait(_) | ChildMode::Host(_),
498-
GoalSource::Misc | GoalSource::TypeRelating | GoalSource::NormalizeGoal(_),
498+
GoalSource::Misc
499+
| GoalSource::TypeRelating
500+
| GoalSource::NormalizeGoal(_)
501+
| GoalSource::NestedNormalizationGoal(_),
499502
) => {
500503
continue;
501504
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use std::marker::PhantomData;
2222
use derive_where::derive_where;
2323
#[cfg(feature = "nightly")]
2424
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
25+
use rustc_type_ir::Interner;
2526
use rustc_type_ir::data_structures::HashMap;
27+
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
2628
use tracing::{debug, instrument};
2729

2830
mod stack;
@@ -122,6 +124,7 @@ pub trait Delegate: Sized {
122124
feature = "nightly",
123125
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
124126
)]
127+
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
125128
pub enum PathKind {
126129
/// A path consisting of only inductive/unproductive steps. Their initial
127130
/// provisional result is `Err(NoSolution)`. We currently treat them as

compiler/rustc_type_ir/src/solve/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub enum GoalSource {
8585
/// 2. for rigid projections's trait goal,
8686
/// 3. for GAT where clauses.
8787
AliasWellFormed,
88+
/// A goal from a nested `NormalizesTo` goal which has been propagated to its caller.
89+
NestedNormalizationGoal(PathKind),
8890
/// In case normalizing aliases in nested goals cycles, eagerly normalizing these
8991
/// aliases in the context of the parent may incorrectly change the cycle kind.
9092
/// Normalizing aliases in goals therefore tracks the original path kind for this
@@ -269,7 +271,7 @@ impl<I: Interner> ExternalConstraintsData<I> {
269271
#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)]
270272
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
271273
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
272-
pub struct NestedNormalizationGoals<I: Interner>(pub Vec<(GoalSource, Goal<I, I::Predicate>)>);
274+
pub struct NestedNormalizationGoals<I: Interner>(pub Vec<(PathKind, Goal<I, I::Predicate>)>);
273275

274276
impl<I: Interner> Eq for NestedNormalizationGoals<I> {}
275277

0 commit comments

Comments
 (0)