diff --git a/compiler/rustc_traits/src/coroutine_witnesses.rs b/compiler/rustc_traits/src/coroutine_witnesses.rs index c2f517d6019c6..c874feb4e0bbb 100644 --- a/compiler/rustc_traits/src/coroutine_witnesses.rs +++ b/compiler/rustc_traits/src/coroutine_witnesses.rs @@ -47,11 +47,18 @@ pub(crate) fn coroutine_hidden_types<'tcx>( ) } +// FIXME: The assumptions are only used in the old solver when `-Zhigher-ranked-assumptions` +// is true. `-Zhigher-ranked-assumptions` is superseded by `assumptions-on-binders`. +// We can remove this function soon. fn compute_assumptions<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, bound_tys: &'tcx ty::List>, ) -> &'tcx ty::List> { + if tcx.next_trait_solver_globally() || !tcx.sess.opts.unstable_opts.higher_ranked_assumptions { + return &ty::List::empty(); + } + let infcx = tcx .infer_ctxt() .build(ty::TypingMode::Typeck { defining_opaque_types_and_generators: ty::List::empty() }); diff --git a/tests/ui/traits/next-solver/coroutine_query_cycle.rs b/tests/ui/traits/next-solver/coroutine_query_cycle.rs new file mode 100644 index 0000000000000..929c8ae4e1b9b --- /dev/null +++ b/tests/ui/traits/next-solver/coroutine_query_cycle.rs @@ -0,0 +1,20 @@ +//@ compile-flags: -Znext-solver +//@ edition: 2024 +//@ check-pass + +// Regression test for trait-system-refactor-initiative#282 +// Previously we always computed higher ranked assumptions for coroutines. +// It led to query cycle in recursive functions like the one below. +// Thoses assumptions are not used in the next solver and +// the functionality is superseded by `assumptions-on-binders`. + +fn go() -> impl Future + Send + 'static { + spawn(async { + go().await; + }) +} +fn spawn(_: impl Future + Send + 'static) -> impl Future { + async {} +} + +fn main() {}