Skip to content

Trying to use same existential type for two functions cause cycle dependency #61863

Closed
@shootingsyh

Description

@shootingsyh

On a nightly rustup 1.18.3 (435397f48 2019-05-22)
Some code like this

#![feature(existential_type)]
pub trait T {
    fn bla() -> ();
}

pub struct S {
  v: u64
}

impl T for S {
    fn bla() -> () {}
}

existential type TE: T;
pub fn bla() -> TE {
    return S {v:1}
}

pub fn bla2() -> TE {
    bla()
}

cause error

Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when processing TE
--> src/lib.rs:14:1
|
14 | existential type TE: T;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires processing bla2...
--> src/lib.rs:19:21
|
19 | pub fn bla2() -> TE {
| ___________________^
20 | | bla()
21 | | }
| |
^
= note: ...which again requires processing TE, completing the cycle
note: cycle used when collecting item types in top-level module
--> src/lib.rs:1:1
|
1 | / #![feature(existential_type)]
2 | | pub trait T {
3 | | fn bla() -> ();
4 | | }
... |
20 | | bla()
21 | | }
| |
^

error: concrete type differs from previous defining existential type use
--> src/lib.rs:19:1
|
19 | / pub fn bla2() -> TE {
20 | | bla()
21 | | }
| |^ expected S, got TE
|
note: previous use here
--> src/lib.rs:15:1
|
15 | / pub fn bla() -> TE {
16 | | return S {v:1}
17 | | }
| |
^

error: aborting due to 2 previous errors

playground link:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=71c724f92b074d0b6f355a6aaf8d3d1a

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions