rust-lang / rust-lang/rust

"expected fn item, found a different fn item" for [(f, "f"), (g, "g")] even though [f, g] infers fine

Open
#142,970 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coercions C-feature-request T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

fn a(_: &str) {}
fn b(_: &str) {}
fn main() {
    for (f, s) in [(a, "a"), (b, "b")] {
        f(s);
    }
    // workaround
    for (f, s) in [a, b].into_iter().zip(["a", "b"]) {
        f(s);
    }
}

I expected to see this happen: both work

Instead, this happened: latter works, former errors with

error[E0308]: mismatched types
 --> a.rs:4:31
  |
4 |     for (f, s) in [(a, "a"), (b, "b")] {
  |                               ^ expected fn item, found a different fn item
  |
  = note: expected fn item `for<'a> fn(&'a _) {a}`
             found fn item `for<'a> fn(&'a _) {b}`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Meta

rustc --version --verbose:

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

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 compiling the minimal reproducer with rustc 1.87.0 and compare the tuple-array case with the zip workaround. Investigate how the compiler treats distinct function items during array type inference; done means the reported case is handled consistently without breaking the working workaround.

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.