Skip to content

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

@nabijaczleweli

Description

@nabijaczleweli

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coercionsArea: implicit and explicit `expr as Type` coercionsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-typesRelevant to the types 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