Skip to content

Can't define TAIT inside another function #145296

@theemathas

Description

@theemathas

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions