Skip to content

Cannot resolve TAIT when used with impl/dyn Trait inside RPIT #101750

Closed
@xxchan

Description

@xxchan

The condition seems complex, but a practical instance is async fn foo() -> Result<TAIT>

I tried this code:

#![feature(type_alias_impl_trait)]

trait Trait {}

type TAIT = impl Trait;

type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

fn foo() -> TAIT {
    struct Bar;
    impl Trait for Bar {}
    Bar
}

async fn bar() -> Result<TAIT> {
    Ok(foo())
}

I expected to see this happen: it compiles

Instead, this happened: error:

error: concrete type differs from previous defining opaque type use
  --> src/tmp.rs:15:32
   |
15 |   async fn bar() -> Result<TAIT> {
   |  ________________________________^
16 | |     Ok(foo())
17 | | }
   | |_^ expected `Bar`, got `TAIT`
   |
note: previous use here
  --> src/tmp.rs:12:5
   |
12 |     Bar
   |     ^^^

Notes:

  • It compiles in nightly-2022-08-12, but failed in nightly-2022-09-13
  • fn() -> Result<TAIT> works, and async fn() -> Option<TAIT> works

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (fa6ee9375 2022-09-12)
binary: rustc
commit-hash: fa6ee9375242ae784dab1837dfc0b92f43e787ce
commit-date: 2022-09-12
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

Metadata

Metadata

Assignees

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)]`

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions