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

rustdoc can't handle existential types #58624

Closed
QuietMisdreavus opened this issue Feb 21, 2019 · 4 comments
Closed

rustdoc can't handle existential types #58624

QuietMisdreavus opened this issue Feb 21, 2019 · 4 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@QuietMisdreavus
Copy link
Member

#![feature(existential_type)]

pub trait SomeTrait {
    fn some_fn(&self) {}
    
    type SomeType;
}

struct SomeStruct;

impl SomeTrait for SomeStruct {
    type SomeType = String;
}

pub existential type Asdf: SomeTrait;
pub fn asdf() -> Asdf { SomeStruct }

This sample compiles just fine, but when you run it in rustdoc...

$ rustdoc +nightly c.rs
error[E0277]: the trait bound `(): SomeTrait` is not satisfied
  --> c.rs:15:1
   |
15 | pub existential type Asdf: SomeTrait;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SomeTrait` is not implemented for `()`
   |
   = note: the return type of a function must have a statically known size

error: Compilation failed, aborting rustdoc

$ rustdoc +nightly --version
rustdoc 1.34.0-nightly (f66e4697a 2019-02-20)

My personal guess is that the fact that rustdoc runs everybody_loops on the function that defines this type means that it no longer returns the actual type - instead it returns !, though the compiler picks up () for the error message.

@QuietMisdreavus QuietMisdreavus added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Feb 21, 2019
@QuietMisdreavus
Copy link
Member Author

cc #34511

@oli-obk
Copy link
Contributor

oli-obk commented Feb 21, 2019

The same thing happens for plain impl trait:

trait Foo {}

fn foo() -> impl Foo {
    loop {}
}

gives

error[E0277]: the trait bound `(): Foo` is not satisfied
 --> src/lib.rs:3:13
  |
3 | fn foo() -> impl Foo {
  |             ^^^^^^^^ the trait `Foo` is not implemented for `()`
  |
  = note: the return type of a function must have a statically known size

I'm not sure how to handle this, even if I turn on #![feature(never_type)], I get

error[E0277]: the trait bound `!: Foo` is not satisfied
 --> src/lib.rs:5:13
  |
5 | fn foo() -> impl Foo {
  |             ^^^^^^^^ the trait `Foo` is not implemented for `!`
  |
  = note: the return type of a function must have a statically known size

@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
@alecmocatta
Copy link
Contributor

see also #58011

@varkor
Copy link
Member

varkor commented Jan 12, 2020

Closing as a duplicate of #65863 (which has more information).

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. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Development

No branches or pull requests

5 participants