rust/tests
bors 35a31ba763 Auto merge of #140283 - adwinwhite:fn-pointer-coercion, r=jackh726
Fix accidental type inference in array coercion


Fixes rust-lang/rust#136420.

If the expectation of array element is a type variable, we should avoid resolving it to the first element's type and wait until LUB coercion is completed.
We create a free type variable instead which is only used in this `CoerceMany`.

[`check_expr_match`](847e3ee6b0/compiler/rustc_hir_typeck/src/_match.rs (L72)) and [`check_expr_if`](847e3ee6b0/compiler/rustc_hir_typeck/src/expr.rs (L1329)) where `CoerceMany` is also used do the [same](847e3ee6b0/compiler/rustc_hir_typeck/src/expectation.rs (L50)). 

### [FCP Proposal](https://github.com/rust-lang/rust/pull/140283#issuecomment-2933771068):
> Array expressions normally lub their element expressions' types to ensure that things like `[5, 5_u8]` work and don't result in type mismatches. When invoking a generic function `fn foo<T>(_: [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.
> 
> 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's type with the array of infer var type.
> 
> Things like
> 
> ```rust
> fn foo() {}
> fn bar() {} 
> fn f<T>(_: [T; 2]) {}
> 
> f([foo, bar]);
> ```
> 
> and
> 
> ```rust
> struct Foo;
> struct Bar;
> trait Trait {}
> impl Trait for Foo {}
> impl Trait for Bar {} 
> fn f<T>(_: [T; 2]) {}
> 
> f([&Foo, &Bar as &dyn Trait]);
> ```

### Remaining inconsistency with `if` and `match`(rust-lang/rust#145048):
The 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.
This causes that array doesn't support nested coercion. 
```rust
fn foo() {}
fn bar() {}
fn main() {
    let _ =  [foo, if false { bar } else { foo }]; // type mismatch when trying to coerce `bar` into `foo` in if-then branch coercion.
}
```
But we can't 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's type as expectation.
2026-01-29 21:36:31 +00:00
..
assembly-llvm Adjust loongarch assembly test 2026-01-27 12:09:39 +01:00
auxiliary Rollup merge of #150368 - minicore-ordering, r=workingjubilee 2026-01-11 09:56:38 +01:00
build-std/configurations Test that -Zbuild-std=core works on a variety of profiles 2026-01-14 20:39:12 -05:00
codegen-llvm Rollup merge of #150893 - ZuseZ4:move-un-register-lib, r=oli-obk 2026-01-28 19:03:51 +11:00
codegen-units address review comments; fix CI 2026-01-01 19:17:11 -05:00
coverage Rollup merge of #147611 - stablize-remap-path-scope, r=davidtwco 2026-01-20 14:36:30 +01:00
coverage-run-rustdoc
crashes Auto merge of #150843 - fmease:dyn-ace, r=BoxyUwU 2026-01-22 01:56:41 +00:00
debuginfo Auto merge of #150843 - fmease:dyn-ace, r=BoxyUwU 2026-01-22 01:56:41 +00:00
incremental Implement incremental caching for derive macro expansions 2026-01-16 07:36:36 +01:00
mir-opt Auto merge of #150945 - scottmcm:tweak-slice-partial-eq, r=Mark-Simulacrum 2026-01-28 14:31:41 +00:00
pretty Update uitests 2026-01-19 21:50:29 +01:00
run-make Add support for trait object types in type_info reflection 2026-01-27 19:49:09 -04:00
run-make-cargo tests/run-make-cargo/same-crate-name-and-macro-name: New regression test 2025-12-17 11:21:27 +01:00
rustdoc-gui Rollup merge of #151665 - arferreira:fix-rustdoc-contrast, r=GuillaumeGomez 2026-01-29 19:03:32 +11:00
rustdoc-html resolve: Mark items under ambigous imports as exported 2026-01-27 16:24:53 +03:00
rustdoc-js Auto merge of #149370 - Zalathar:rollup-6fkk5x4, r=Zalathar 2025-11-27 07:30:25 +00:00
rustdoc-js-std Explicitly export core and std macros 2026-01-13 08:47:48 +01:00
rustdoc-json resolve: Mark items under ambigous imports as exported 2026-01-27 16:24:53 +03:00
rustdoc-ui Rollup merge of #151449 - GuillaumeGomez:regression-test-for-151411, r=lolbinarycat 2026-01-28 21:10:54 +01:00
ui Auto merge of #140283 - adwinwhite:fn-pointer-coercion, r=jackh726 2026-01-29 21:36:31 +00:00
ui-fulldeps Remove unused no_span option 2026-01-28 22:23:23 +01:00
COMPILER_TESTS.md