-   Notifications  You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I tried this code:
fn foo() {} fn bar() {} fn main() { let _a = if true { foo } else { bar }; let _b = vec![foo, bar]; let _c = [foo, bar]; d(if true { foo } else { bar }); e(vec![foo, bar]); f([foo, bar]); } fn d<T>(_: T) {} fn e<T>(_: Vec<T>) {} fn f<T>(_: [T; 2]) {}I expected the six lines to either all compile or all error. Instead, only the f([foo, bar]) line fails, with the following error:
error[E0308]: mismatched types --> src/main.rs:10:7 | 10 | f([foo, bar]); | - ^^^^^^^^^^ expected `[fn() {foo}; 2]`, found `[fn(); 2]` | | | arguments to this function are incorrect | = note: expected array `[fn() {foo}; 2]` found array `[fn(); 2]` note: function defined here --> src/main.rs:15:4 | 15 | fn f<T>(_: [T; 2]) {} | ^ --------- For more information about this error, try `rustc --explain E0308`. For some reason, it's failing to coerce the function items into function pointers, but only when an array is being passed to a generic function.
Discovered by @xero-lib
Meta
Issue reproducible on the playground with stable rust 1.84.1, and nightly rust 1.86.0-nightly (2025-02-01 8239a37f9c0951a037cf)
@rustbot labels +A-inference +A-coercions
xero-lib
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.