rust-lang / rust-lang/rust

Can't define TAIT inside another function

Open
#145,296 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried this code:

#![feature(type_alias_impl_trait)]

fn main() {
    type Opaque = impl Sized;

    #[define_opaque(Opaque)]
    fn make_opaque() -> Opaque {
        1i32
    }
}

I expected the code to compile. But instead I got this error:

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

@rustbot labels +F-type_alias_impl_trait

Meta

Reproduces on the playground with version 1.91.0-nightly (2025-08-11 1ebbd87a62ce96a72b22)

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

Start with the reproducer in src/main.rs and run it on the reported nightly version or the playground to confirm the nested type alias impl trait failure. Trace the compiler handling of #[define_opaque] for the local Opaque alias; done means the example compiles without the constraint error and coverage exists for this case.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.