rust-lang / rust-lang/rust

TAIT: requires bounds on type alias when shouldn't

Open
#149,765 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-impl-trait A-trait-system 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: playground:

#![feature(type_alias_impl_trait)]

type Foo<'a, C> = impl Sized;

#[define_opaque(Foo)]
fn foo<'a, C: PartialEq>(c: &'a C) -> Foo<'a, C> {
    bar(c)
}

fn bar<'a, C: PartialEq>(_: &'a C) -> impl Sized {
    0i32
}

fn main() {}

I expected to see this happen: foo has PartialEq bound, so could should compile.

Instead, this happened: it asks to put PartialEq bound in Foo itself. It implies all problems that arise after prematurely putting bounds on a struct.

❯ cargo check
    Checking play v0.1.0 (/home/ddystopia/code/play)
error[E0277]: can't compare `C` with `C`
  --> src/main.rs:7:5
   |
 7 |     bar(c)
   |     ^^^^^^ no implementation for `C == C`
   |
note: required by a bound in `bar`
  --> src/main.rs:10:15
   |
10 | fn bar<'a, C: PartialEq>(_: &'a C) -> impl Sized {
   |               ^^^^^^^^^ required by this bound in `bar`
help: consider restricting type parameter `C` with trait `PartialEq`
   |
 3 | type Foo<'a, C: std::cmp::PartialEq> = impl Sized;
   |               +++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `play` (bin "play") due to 1 previous error
Meta

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 by reproducing the supplied type_alias_impl_trait example with the nightly compiler using cargo check. Investigate how the compiler handles the #[define_opaque] function and bounds on the type alias versus its function parameters. Done means the example compiles without requiring the PartialEq bound on Foo, with regression coverage for this behavior.

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.