Open
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