Skip to content

existential types cannot be defined in terms of themselves at all #53398

Closed
@oli-obk

Description

@oli-obk

I assumed that the following code would be legal, as it does not require indefinitely sized types, but apparently somewhere the existential type is revealed too early:

#![feature(existential_type)]

existential type Foo: Fn() -> Foo;

fn foo() -> Foo {
    foo
}

fn main() {
}

(Playground)

Errors:

   Compiling playground v0.0.1 (file:///playground)
error[E0271]: type mismatch resolving `<fn() -> Foo {foo} as std::ops::FnOnce<()>>::Output == fn() -> Foo {foo}`
 --> src/main.rs:3:1
  |
3 | existential type Foo: Fn() -> Foo;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected anonymized type, found fn item
  |
  = note: expected type `Foo`
             found type `fn() -> Foo {foo}`
  = note: the return type of a function must have a statically known size

error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions