)]}'
{
  "commit": "35a31ba763976907cd38ba88743a3aefbaf8ffff",
  "tree": "b988e125b1d2e80f4e31bc01dc15ab2085b63ef2",
  "parents": [
    "842bd5be253e17831e318fdbd9d01d716557cc75",
    "b235cc22acdde9be7a25c3b5828e9c5863a0b54f"
  ],
  "author": {
    "name": "bors",
    "email": "bors@rust-lang.org",
    "time": "Thu Jan 29 21:36:31 2026 +0000"
  },
  "committer": {
    "name": "bors",
    "email": "bors@rust-lang.org",
    "time": "Thu Jan 29 21:36:31 2026 +0000"
  },
  "message": "Auto merge of #140283 - adwinwhite:fn-pointer-coercion, r\u003djackh726\n\nFix accidental type inference in array coercion\n\n\r\nFixes rust-lang/rust#136420.\r\n\r\nIf the expectation of array element is a type variable, we should avoid resolving it to the first element\u0027s type and wait until LUB coercion is completed.\r\nWe create a free type variable instead which is only used in this `CoerceMany`.\r\n\r\n[`check_expr_match`](https://github.com/rust-lang/rust/blob/847e3ee6b0e614937eee4e6d8f61094411eadcc0/compiler/rustc_hir_typeck/src/_match.rs#L72) and [`check_expr_if`](https://github.com/rust-lang/rust/blob/847e3ee6b0e614937eee4e6d8f61094411eadcc0/compiler/rustc_hir_typeck/src/expr.rs#L1329) where `CoerceMany` is also used do the [same](https://github.com/rust-lang/rust/blob/847e3ee6b0e614937eee4e6d8f61094411eadcc0/compiler/rustc_hir_typeck/src/expectation.rs#L50). \r\n\r\n### [FCP Proposal](https://github.com/rust-lang/rust/pull/140283#issuecomment-2933771068):\r\n\u003e Array expressions normally lub their element expressions\u0027 types to ensure that things like `[5, 5_u8]` work and don\u0027t result in type mismatches. When invoking a generic function `fn foo\u003cT\u003e(_: [T; N])` with an array expression, we end up with an infer var for the element type of the array in the signature. So when typecking the first array element we compare its type with the infer var and thus subsequently require all other elements to be the same type.\r\n\u003e \r\n\u003e This PR changes that to instead fall back to \"not knowing\" that the argument type is array of infer var, but just having an infer var for the entire argument. Thus we typeck the array expression normally, lubbing the element expressions, and then in the end comparing the array expression\u0027s type with the array of infer var type.\r\n\u003e \r\n\u003e Things like\r\n\u003e \r\n\u003e ```rust\r\n\u003e fn foo() {}\r\n\u003e fn bar() {} \r\n\u003e fn f\u003cT\u003e(_: [T; 2]) {}\r\n\u003e \r\n\u003e f([foo, bar]);\r\n\u003e ```\r\n\u003e \r\n\u003e and\r\n\u003e \r\n\u003e ```rust\r\n\u003e struct Foo;\r\n\u003e struct Bar;\r\n\u003e trait Trait {}\r\n\u003e impl Trait for Foo {}\r\n\u003e impl Trait for Bar {} \r\n\u003e fn f\u003cT\u003e(_: [T; 2]) {}\r\n\u003e \r\n\u003e f([\u0026Foo, \u0026Bar as \u0026dyn Trait]);\r\n\u003e ```\r\n\r\n### Remaining inconsistency with `if` and `match`(rust-lang/rust#145048):\r\nThe typeck of array always uses the element coercion target type as the expectation of element exprs while `if` and `match` use `NoExpectation` if the expected type is an infer var.\r\nThis causes that array doesn\u0027t support nested coercion. \r\n```rust\r\nfn foo() {}\r\nfn bar() {}\r\nfn main() {\r\n    let _ \u003d  [foo, if false { bar } else { foo }]; // type mismatch when trying to coerce `bar` into `foo` in if-then branch coercion.\r\n}\r\n```\r\nBut we can\u0027t simply change this behavior to be the same as `if` and `match` since [many code](https://github.com/rust-lang/rust/pull/140283#issuecomment-3190564399) depends on using the first element\u0027s type as expectation.",
  "tree_diff": []
}
