Skip to content

Regression from nightly to nightly in type_alias_impl_trait #89952

Closed
@iliakonnov

Description

@iliakonnov

Code

I tried this code:

#![feature(type_alias_impl_trait)]

trait SomeTrait {}
impl SomeTrait for () {}

trait MyFuture {
    type Output;
}
impl<T> MyFuture for T {
    type Output = T;
}

trait ReturnsFuture {
    type Output: SomeTrait;
    type Future: MyFuture<Output=Result<Self::Output, ()>>;
    fn func() -> Self::Future;
}

struct Foo;

impl ReturnsFuture for Foo {
    type Output = impl SomeTrait;
    type Future = impl MyFuture<Output=Result<Self::Output, ()>>;
    fn func() -> Self::Future {
        Result::<(), ()>::Err(())
    }
}

I expected to see this happen: code compiles successfully

Instead, this happened:

error[E0271]: type mismatch resolving `<Result<(), ()> as MyFuture>::Output == Result<impl SomeTrait, ()>`
  --> ./demo.rs:24:18
   |
22 |     type Output = impl SomeTrait;
   |                   -------------- the expected opaque type
23 |     type Future = impl MyFuture<Output=Result<Self::Output, ()>>;
24 |     fn func() -> Self::Future {
   |                  ^^^^^^^^^^^^ expected opaque type, found `()`
   |
   = note: expected enum `Result<impl SomeTrait, _>`
              found enum `Result<(), _>`

error: could not find defining uses
  --> ./demo.rs:22:19
   |
22 |     type Output = impl SomeTrait;
   |                   ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Version it worked on

rustc --version --verbose:

rustc 1.57.0-nightly (5ecc8ad84 2021-09-19)
binary: rustc
commit-hash: 5ecc8ad8462574354a55162a0c16b10eb95e3e70
commit-date: 2021-09-19
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

Version with regression

rustc --version --verbose:

rustc 1.57.0-nightly (ac2d9fc50 2021-09-21)
binary: rustc
commit-hash: ac2d9fc509e36d1b32513744adf58c34bcc4f43c
commit-date: 2021-09-21
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

@rustbot modify labels: +requires-nightly +F-type_alias_impl_trait

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.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