rust/tests
bors bd53aa3bf7 Auto merge of #129317 - compiler-errors:expectation-subtyping, r=lcnr
Use equality when relating formal and expected type in arg checking

#129059 uncovered an interesting issue in argument checking. When we check arguments, we create three sets of types:
* Formals
* Expected
* Actuals

The **actuals** are the types of the argument expressions themselves. The **formals** are the types from the signature that we're checking. The **expected** types are the formal types, but passed through `expected_inputs_for_expected_outputs`:

a971212545/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs (L691-L725)

This method attempts to constrain the formal inputs by relating the [expectation](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/expectation/enum.Expectation.html) of the call expression and the formal output.

When we check an argument, we get the expression's actual type, and then we first attempt to coerce it to the expected type:

a971212545/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs (L280-L293)

Then we subtype the expected type and the formal type:

a971212545/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs (L299-L305)

However, since we are now recording the right coercion target (since #129059), we now end up recording the expected type to the typeck results, rather than the actual.

Since that expected type was [fudged](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/struct.InferCtxt.html#method.fudge_inference_if_ok), it has fresh variables. And since the expected type is only subtyped against the formal type, if that expected type has a bivariant parameter, it will likely remain unconstrained since `Covariant * Bivariant = Bivariant` according to [xform](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.Variance.html#method.xform). This leads to an unconstrained type variable in writeback.

AFAICT, there's no reason for us to be using subtyping here, though. The expected output is already related to the expectation by subtyping:

a971212545/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs (L713)

So the formals don't need "another" indirection of subtyping in the argument checking... So I've changed it to use equality here. We could alternatively fix this by requiring WF for all the expected types to constrain their bivariant parameters, but this seems a bit overkill.

Fixes #129286
2024-09-02 16:08:50 +00:00
..
assembly Revert "Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwU" 2024-09-01 16:35:53 +02:00
auxiliary
codegen Rollup merge of #129316 - dingxiangfei2009:riscv64-imac-scs, r=nnethercote 2024-08-29 16:21:47 +02:00
codegen-units Fix and enable disabled codegen-units tests 2024-08-10 14:03:27 -04:00
coverage Finish blessing coverage/mcdc tests after LLVM 19 upgrade 2024-08-01 13:36:50 +10:00
coverage-run-rustdoc
crashes Rollup merge of #129780 - cyrgani:master, r=compiler-errors 2024-09-01 03:58:05 +02:00
debuginfo Make option-like-enum.rs UB-free and portable 2024-08-27 19:12:14 -04:00
incremental Rollup merge of #127279 - bvanjoi:fix-112680, r=petrochenkov 2024-08-21 19:35:10 +02:00
mir-opt Rollup merge of #129493 - cjgillot:early-opaque-def, r=petrochenkov 2024-09-01 03:58:04 +02:00
pretty stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
run-make Rollup merge of #129837 - aDotInTheVoid:test-better-json, r=jieyouxu 2024-09-02 04:19:30 +02:00
run-pass-valgrind
rustdoc Rollup merge of #129560 - GuillaumeGomez:impl-assoc-type-source-link, r=notriddle 2024-08-27 00:42:01 +02:00
rustdoc-gui Rollup merge of #127474 - tesuji:foldable-inline-derefs, r=t-rustdoc 2024-09-02 04:19:27 +02:00
rustdoc-js Add test for Self not being a generic in search index 2024-08-04 12:49:28 -07:00
rustdoc-js-std rustdoc: show exact case-sensitive matches first 2024-08-23 13:05:24 -04:00
rustdoc-json Rollup merge of #129123 - aDotInTheVoid:rustdoc-json-self, r=fmease 2024-08-31 10:08:52 +02:00
rustdoc-ui Adjust expected errors for a rustdoc test 2024-08-18 22:52:54 -05:00
ui Auto merge of #129317 - compiler-errors:expectation-subtyping, r=lcnr 2024-09-02 16:08:50 +00:00
ui-fulldeps Deny imports of rustc_type_ir::inherent outside of type ir + new trait solver 2024-09-01 12:16:18 -04:00
COMPILER_TESTS.md