Skip to content

Commit 96171dc

Browse files
Check if type has coroutines before visiting
1 parent bf5e6cc commit 96171dc

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use rustc_infer::traits::{
1010
FromSolverError, PredicateObligation, PredicateObligations, TraitEngine,
1111
};
1212
use rustc_middle::ty::{
13-
self, DelayedSet, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, TypingMode,
13+
self, DelayedSet, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
14+
TypingMode,
1415
};
1516
use rustc_next_trait_solver::delegate::SolverDelegate as _;
1617
use rustc_next_trait_solver::solve::{
@@ -332,10 +333,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for StalledOnCoroutines<'tcx> {
332333
if let ty::CoroutineWitness(def_id, _) = *ty.kind()
333334
&& def_id.as_local().is_some_and(|def_id| self.stalled_generators.contains(&def_id))
334335
{
335-
return ControlFlow::Break(());
336+
ControlFlow::Break(())
337+
} else if ty.has_coroutines() {
338+
ty.super_visit_with(self)
339+
} else {
340+
ControlFlow::Continue(())
336341
}
337-
338-
ty.super_visit_with(self)
339342
}
340343
}
341344

compiler/rustc_type_ir/src/flags.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ bitflags::bitflags! {
130130

131131
/// Does this have any binders with bound vars (e.g. that need to be anonymized)?
132132
const HAS_BINDER_VARS = 1 << 23;
133+
134+
/// Does this type have any coroutine witnesses in it?
135+
// FIXME: This should probably be changed to track whether the type has any
136+
// *coroutines* in it, though this will happen if we remove coroutine witnesses
137+
// altogether.
138+
const HAS_TY_CORO = 1 << 24;
133139
}
134140
}
135141

@@ -240,10 +246,12 @@ impl<I: Interner> FlagComputation<I> {
240246
self.add_flags(TypeFlags::HAS_TY_PARAM);
241247
}
242248

243-
ty::Closure(_, args)
244-
| ty::Coroutine(_, args)
245-
| ty::CoroutineClosure(_, args)
246-
| ty::CoroutineWitness(_, args) => {
249+
ty::Closure(_, args) | ty::Coroutine(_, args) | ty::CoroutineClosure(_, args) => {
250+
self.add_args(args.as_slice());
251+
}
252+
253+
ty::CoroutineWitness(_, args) => {
254+
self.add_flags(TypeFlags::HAS_TY_CORO);
247255
self.add_args(args.as_slice());
248256
}
249257

compiler/rustc_type_ir/src/visit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ pub trait TypeVisitableExt<I: Interner>: TypeVisitable<I> {
269269
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
270270
}
271271

272+
fn has_coroutines(&self) -> bool {
273+
self.has_type_flags(TypeFlags::HAS_TY_CORO)
274+
}
275+
272276
fn references_error(&self) -> bool {
273277
self.has_type_flags(TypeFlags::HAS_ERROR)
274278
}

0 commit comments

Comments
 (0)