Skip to content

Cycle detected when processing existential type #55997

Open
@Nemo157

Description

@Nemo157

playground

#![feature(existential_type)]

use std::rc::Rc;

existential type Foo: Fn() -> usize;

fn foo() -> Foo {
    let rc = Rc::new(5);
    move || { *rc.as_ref() }
}

fn assert_send<T: Send>(_: &T) {
}

fn main() {
    let f = foo();
    assert_send(&f);
    println!("{}", f());
}
error[E0391]: cycle detected when processing `Foo`
 --> src/main.rs:5:1
  |
5 | existential type Foo: Fn() -> usize;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires processing `main`...
 --> src/main.rs:15:1
  |
15| fn main() {
  | ^^^^^^^^^
note: ...which requires evaluating trait selection obligation `Foo: std::marker::Send`...
  = note: ...which again requires processing `Foo`, completing the cycle

Commenting out the assert_send(&f); line compiles and runs fine (playground), moving Foo and foo into a sub-module correctly identifies that Foo: !Send (playground).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-cycleIssue: A query cycle occurred while none was expectedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Can do after stabilization

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions