rust-lang / rust-lang/rust

TAIT: combining those types cannot compile

Open
#139,003 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-type_alias_impl_trait T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code:

#![feature(type_alias_impl_trait)]

type A = impl Sized;
type B = impl Future<Output = A>;

#[define_opaque(A)]
fn a() -> A {
    5
}

#[define_opaque(B)]
fn b(a: A) -> B {
    async { a }
}

// Or like this too:
//
// #[define_opaque(B)]
// fn b() -> B {
//     async { a() }
// }

I expected it to compile, but instead got an error:

 error: item does not constrain `A::{opaque#0}`
   --> src/main.rs:12:4
    |
 12 | fn b(a: A) -> B {
    |    ^
    |
    = note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]`
 note: this opaque type is supposed to be constrained
   --> src/main.rs:3:10
    |
 3  | type A = impl Sized;
    |
Meta

rustc --version --verbose:

rustc 1.87.0-nightly (b48576b4d 2025-03-22)
binary: rustc
commit-hash: b48576b4db5a595f453891f0b7243ef75d8c0afa
commit-date: 2025-03-22
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic from the example in src/main.rs using the reported rustc 1.87.0-nightly environment. Investigate how #[define_opaque] handles the relationship between opaque types A and B, including the alternate b() form. Done means both examples compile without the “item does not constrain” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.