rust-lang / rust-lang/rust

Duplicate doubly higher-ranked trait bound fails to compile

Open
#140,071 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug fixed-by-next-solver T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

fn f()
where
    for<'db> for<'a> fn(&'a str): std::fmt::Debug,
    for<'db> for<'a> fn(&'a str): std::fmt::Debug,
{
}

I expected to see this happen:

It compiles successfully like it does when the bound is not duplicated as in

fn f()
where
    for<'db> for<'a> fn(&'a str): std::fmt::Debug,
{
}

or when a layer of for binders is removed

fn f()
where
    for<'a> fn(&'a str): std::fmt::Debug,
    for<'a> fn(&'a str): std::fmt::Debug,
{
}

Instead, this happened:

error[E0283]: type annotations needed: cannot satisfy `for<'a> fn(&'a str): Debug`
  --> tests\tracked_method_inherent_return_ref.rs:36:35
   |
36 |     for<'db> for<'a> fn(&'a str): std::fmt::Debug,
   |                                   ^^^^^^^^^^^^^^^
   |
note: multiple `impl`s or `where` clauses satisfying `for<'a> fn(&'a str): Debug` found
  --> tests\tracked_method_inherent_return_ref.rs:36:35
   |
36 |     for<'db> for<'a> fn(&'a str): std::fmt::Debug,
   |                                   ^^^^^^^^^^^^^^^
37 |     for<'db> for<'a> fn(&'a str): std::fmt::Debug,
   |                                   ^^^^^^^^^^^^^^^
   = note: and another `impl` found in the `core` crate:
           - impl<F> Debug for F
             where F: FnPtr;

For more information about this error, try `rustc --explain E0283`.
error: could not compile `salsa` (test "tracked_method_inherent_return_ref") due to 1 previous error
Meta

rustc --version --verbose:

rustc 1.88.0-nightly (5e17a2a91 2025-04-05)
binary: rustc
commit-hash: 5e17a2a91dd7dbefd8b4a1087c2e42257457deeb
commit-date: 2025-04-05
host: x86_64-pc-windows-msvc
release: 1.88.0-nightly
LLVM version: 20.1.2

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 duplicated higher-ranked trait-bound example in the issue and the diagnostic location tests\tracked_method_inherent_return_ref.rs. Reproduce the E0283 error with the stated nightly compiler, then trace how rustc handles duplicate nested for bounds. Done means the example compiles as expected and a regression test covers both duplicated and non-duplicated forms.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.