Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
oli-obk opened this issue Aug 15, 2018 · 3 comments · Fixed by #96686
Closed

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

oli-obk opened this issue Aug 15, 2018 · 3 comments · Fixed by #96686
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. E-needs-test Call 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-nightly This issue requires a nightly compiler in some way.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Aug 15, 2018

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.

@oli-obk oli-obk added the A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. label Aug 15, 2018
@oli-obk oli-obk added the C-bug Category: This is a bug. label Jan 25, 2019
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
@Aaron1011
Copy link
Member

Updated version:

#![feature(type_alias_impl_trait)]

type Foo = impl Fn() -> Foo;

fn foo() -> Foo {
    foo
}

fn main() {
}

This still doesn't compile.

@nikomatsakis
Copy link
Contributor

Using min-type-alias-impl-trait (playground), you get an error.

I think this is ok, though, as it is we don't support cyclic types like this.

I'm going to mark this as E-needs-test.

@nikomatsakis nikomatsakis added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-min_type_alias_impl_trait and removed C-bug Category: This is a bug. labels Jun 29, 2021
@nikomatsakis
Copy link
Contributor

If we adopted a different model of impl trait, one where they were more "nominal" and hence could be cyclic, that'd be a different thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. E-needs-test Call 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-nightly This issue requires a nightly compiler in some way.
Development

Successfully merging a pull request may close this issue.

4 participants