rust-lang / rust-lang/rust

Tait fails when type alias inside the adjacent function

Open
#149,686 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried this code:
playground

#![feature(type_alias_impl_trait)]

type Foo = impl Sized;

#[define_opaque(Foo)]
fn foo() -> Foo {
    0i32
}

fn bar() {
    type Bar = Foo;
}

fn main() {}

I expected to see this happen: code checks, just like this one (type alias moved out from the function):

#![feature(type_alias_impl_trait)]

type Foo = impl Sized;

#[define_opaque(Foo)]
fn foo() -> Foo {
    0i32
}

type Bar = Foo;

fn bar() {}

fn main() {}

Instead, this happened:

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

error: could not compile `play` (bin "play") due to 1 previous error
Meta

rustc --version --verbose:

> rustc --version --verbose
rustc 1.93.0-nightly (adaa83897 2025-10-27)
binary: rustc
commit-hash: adaa838976ff99a4f0661136322f64cb466b58a0
commit-date: 2025-10-27
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3

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 linked Rust Playground reproducer and compare the failing local type-alias case with the working top-level alias case. Trace the compiler handling for #[define_opaque(Foo)] and local aliases; done means the failing example checks without producing 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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.