Skip to content

Cyclic dependency bug processing RPIT impl Trait #55634

@alexreg

Description

@alexreg
trait Foo: Fn(i32) + Send {}

impl<T: ?Sized + Fn(i32) + Send> Foo for T {}

fn gives_foo() -> impl Foo {
    let f = |x| println!("{}", x);
    f
}

fn main() {
    gives_foo()(42);
}

yields

error[E0391]: cycle detected when processing `gives_foo::{{impl-Trait}}`
 --> test.rs:5:19
  |
5 | fn gives_foo() -> impl Foo {
  |                   ^^^^^^^^
  |
note: ...which requires processing `gives_foo::{{impl-Trait}}`...
 --> test.rs:5:19
  |
5 | fn gives_foo() -> impl Foo {
  |                   ^^^^^^^^
note: ...which requires processing `gives_foo::{{impl-Trait}}`...
 --> test.rs:5:19
  |
5 | fn gives_foo() -> impl Foo {
  |                   ^^^^^^^^
  = note: ...which again requires processing `gives_foo::{{impl-Trait}}`, completing the cycle
note: cycle used when processing `gives_foo`
 --> test.rs:5:1
  |
5 | fn gives_foo() -> impl Foo {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^

I originally thought this was my PR #55101 that was at fault, but I've now confirmed this bug occurs on master, so it looks like it isn't... not in the latest nightly though, as of now, so it must have been a recent PR.

CC @nikomatsakis @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions