Repository navigation
cycle detected when checking if trait is dyn-compatible with next-gen trait solver and arbitrary_self_types #161536
Copy link
Copy link
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-arbitrary_self_types`#![feature(arbitrary_self_types)]``#![feature(arbitrary_self_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
I have some weird code I was using as a workaround for #17893 (comment) but it stopped compiling on the latest nightly. Using -Znext-solver=coherence makes it compile again so it's presumably because of #160895.
I tried to minimize it below:
Code
I tried this code:
#![feature(arbitrary_self_types, derive_coerce_pointee)]
#![allow(dead_code)]
use core::marker::{CoercePointee, PhantomData};
use std::ops::Deref;
#[derive(CoercePointee)]
#[repr(transparent)]
struct Ref<#[pointee] T: ?Sized, D: ?Sized + GenericTrait<D>> {
ptr: Box<T>,
phantom: PhantomData<D>,
}
impl<T: ?Sized, D: ?Sized + GenericTrait<D>> Deref for Ref<T, D> {
type Target = T;
fn deref(&self) -> &T {
&self.ptr
}
}
trait GenericTrait<D: ?Sized + GenericTrait<D>> {}
trait MyTrait {
fn causes_cycle(self: Ref<Self, dyn MyTrait>);
}
impl GenericTrait<dyn MyTrait> for dyn MyTrait {}
fn main() {}I expected to see this happen: compiles, as it does with -Znext-solver=coherence
Instead, this happened:
error[E0391]: cycle detected when checking if trait `MyTrait` is dyn-compatible
--> src\main.rs:22:1
|
22 | trait MyTrait {
| ^^^^^^^^^^^^^
|
= note: ...which requires determining dyn-compatibility of trait `MyTrait`...
= note: ...which again requires checking if trait `MyTrait` is dyn-compatible, completing the cycle
note: cycle used when coherence checking all impls of trait `GenericTrait`
--> src\main.rs:20:1
|
20 | trait GenericTrait<D: ?Sized + GenericTrait<D>> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
Version it worked on
Same as below but with -Znext-solver=coherence
Version with regression
rustc 1.100.0-nightly (c656540d6 2026-08-21)
binary: rustc
commit-hash: c656540d6467dee1381f0cbd882412d6bd1cd5ae
commit-date: 2026-08-21
host: x86_64-pc-windows-msvc
release: 1.100.0-nightly
LLVM version: 23.1.0
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-arbitrary_self_types`#![feature(arbitrary_self_types)]``#![feature(arbitrary_self_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
dimpolo commentedon Aug 23, 2026
Today's nightly 2026-08-22 now produces the same error with -Znext-solver=coherence as well.
So this just became a normal nightly-to-nightly regression irrespective of trait solver used.
My LLM suggests this could be because of #154992
lcnr commentedon Aug 23, 2026
Thanks for opening this issue. Would be worth to get a better sense of why this errors. It doesn't feel too surprising to me that having a receiver reference the current trait is causing issues 🤔
saberoueslati commentedon Aug 29, 2026
@rustbot claim