Skip to content

Commit 9b87f59

Browse files
committed
Implement is_coinductive
Fixes #55096.
1 parent f2b9217 commit 9b87f59

File tree

1 file changed

+20
-3
lines changed
  • src/librustc_traits/chalk_context

1 file changed

+20
-3
lines changed

src/librustc_traits/chalk_context/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,29 @@ impl context::AggregateOps<ChalkArenas<'gcx>> for ChalkContext<'cx, 'gcx> {
155155
}
156156

157157
impl context::ContextOps<ChalkArenas<'gcx>> for ChalkContext<'cx, 'gcx> {
158-
/// True if this is a coinductive goal -- e.g., proving an auto trait.
158+
/// True if this is a coinductive goal: basically proving that an auto trait
159+
/// is implemented or proving that a trait reference is well-formed.
159160
fn is_coinductive(
160161
&self,
161-
_goal: &Canonical<'gcx, InEnvironment<'gcx, Goal<'gcx>>>
162+
goal: &Canonical<'gcx, InEnvironment<'gcx, Goal<'gcx>>>
162163
) -> bool {
163-
unimplemented!()
164+
use rustc::traits::{WellFormed, WhereClause};
165+
166+
let mut goal = goal.value.goal;
167+
loop {
168+
match goal {
169+
GoalKind::DomainGoal(domain_goal) => match domain_goal {
170+
DomainGoal::WellFormed(WellFormed::Trait(..)) => return true,
171+
DomainGoal::Holds(WhereClause::Implemented(trait_predicate)) => {
172+
return self.tcx.trait_is_auto(trait_predicate.def_id());
173+
}
174+
_ => return false,
175+
}
176+
177+
GoalKind::Quantified(_, bound_goal) => goal = *bound_goal.skip_binder(),
178+
_ => return false,
179+
}
180+
}
164181
}
165182

166183
/// Create an inference table for processing a new goal and instantiate that goal

0 commit comments

Comments
 (0)