Skip to content

Rustdoc fails to compile compilable crates with #![feature(type_alias_impl_trait)] #75088

@WaffleLapkin

Description

@WaffleLapkin

I was trying to use #![feature(type_alias_impl_trait)] in my crates, but I've recently found out that rustdoc fails to compile their doc (though cargo build compiles them just fine)

First example (playground):

#![feature(type_alias_impl_trait)]
use std::future::Future;

struct Ty;
trait Trait {
    type Fut;

    fn fut() -> Self::Fut;
}

impl Trait for Ty {
    type Fut = impl Future<Output = Ty>;

    fn fut() -> Self::Fut {
        async { Ty }
    }
}

cargo doc error:

% cargo doc
 Documenting rustfmt_brakes_because_of_futures v0.1.0 (/home/waffle/projects/repos/rustfmt_brakes_because_of_futures)
error[E0277]: `()` is not a future
  --> src/lib.rs:12:16
   |
12 |     type Fut = impl Future<Output = Ty>;
   |                ^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future
   |
   = help: the trait `std::future::Future` is not implemented for `()`
   = note: the return type of a function must have a statically known size

Second example (playground):

#![feature(type_alias_impl_trait)]
use std::future::Future;

struct Ty;
trait Trait {
    type Fut;

    // The `Option<>` is important here - without it it's essentially first example.
    // (in my original crates it was `Result` and nto option, but it doesn't change anything)
    fn fut() -> Option<Self::Fut>;
}

impl Trait for Ty {
    type Fut = impl Future<Output = Ty>;

    fn fut() -> Option<Self::Fut> {
        Some(async { Ty })
    }
}

cargo doc error:

% cargo doc
 Documenting rustfmt_brakes_because_of_futures v0.1.0 (/home/waffle/projects/repos/rustfmt_brakes_because_of_futures)
error: could not find defining uses
  --> src/lib.rs:12:16
   |
12 |     type Fut = impl Future<Output = Ty>;
   |                ^^^^^^^^^^^^^^^^^^^^^^^^

Meta

rustc --version --verbose:

rustc 1.46.0-nightly (346aec9b0 2020-07-11)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions