rust/tests/ui/coercion
bors 97b131c900 Auto merge of #148602 - BoxyUwU:coercion_cleanup_uncontroversial, r=lcnr
misc coercion cleanups and handle safety correctly

r? lcnr

### "remove normalize call"

Fixes rust-lang/rust#132765

If the normalization fails we would sometimes get a `TypeError` containing inference variables created inside of the probe used by coercion. These would then get leaked out causing ICEs in diagnostics logic

### "leak check and lub for closure<->closure coerce-lubs of same defids"

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/233
```rust
fn peculiar() -> impl Fn(u8) -> u8 {
    return |x| x + 1
}
```
the `|x| x + 1` expr has a type of `Closure(?31t)` which we wind up inferring the RPIT to. The `CoerceMany` `ret_coercion` for the whole `peculiar` typeck has an expected type of `RPIT` (unnormalized). When we type check the `return |x| x + 1` expr we go from the never type to `Closure(?31t)` which then participates in the `ret_coercion` giving us a `coerce-lub(RPIT, Closure(?31t))`.

Normalizing `RPIT` gives us some `Closure(?50t)` where `?31t` and `?50t` have been unified with `?31t` as the root var. `resolve_vars_if_possible` doesn't resolve infer vars to their roots so these wind up with different structural identities so the fast path doesn't apply and we fall back to coercing to a `fn` ptr. cc rust-lang/rust#147193 which also fixes this

New solver probably just gets more inference variables here because canonicalization + generally different approach to normalization of opaques. Idk :3

### FCP worthy stuffy

there are some other FCP worthy things but they're in my FCP comment which also contains some analysis of the breaking nature of the previously listed changes in this PR: https://github.com/rust-lang/rust/pull/148602#issuecomment-3503497467
2025-12-05 11:46:41 +00:00
..
auxiliary Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fudge-inference Mention issue 149379 and add tests for it 2025-11-28 00:24:59 +09:00
any-trait-object-debug-12744.rs comments 2025-07-31 21:25:49 +05:00
basic-ptr-coercions.rs cleaned up some tests 2025-07-05 00:45:24 +05:00
cast-higher-ranked-unsafe-fn-ptr.rs Use subtyping for UnsafeFnPointer coercion, too 2024-08-19 21:26:10 -04:00
codegen-smart-pointer-with-alias.rs Normalize ADT fields in find_tails_for_unsizing 2025-04-14 16:51:00 +00:00
coerce-block-tail-26978.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-block-tail-26978.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
coerce-block-tail-57749.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-block-tail-57749.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
coerce-block-tail-83783.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-block-tail-83783.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-block-tail-83783.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
coerce-block-tail-83850.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-block-tail-83850.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
coerce-block-tail.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-block-tail.stderr Suggest removing Box::new 2025-09-16 04:22:50 -04:00
coerce-box-new-to-unboxed.rs Suggest removing Box::new 2025-09-16 04:22:50 -04:00
coerce-box-new-to-unboxed.stderr Suggest removing Box::new 2025-09-16 04:22:50 -04:00
coerce-expect-unsized-ascribed.rs Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
coerce-expect-unsized-ascribed.stderr Rework "long type names" printing logic 2025-01-31 20:39:01 +00:00
coerce-expect-unsized.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-issue-49593-box-never.e2021.stderr refactor Box<! -> dyn Error> regression test 2025-12-02 11:07:42 +01:00
coerce-issue-49593-box-never.nofallback.stderr remove feature(never_type_fallback) 2025-11-27 22:48:00 +01:00
coerce-issue-49593-box-never.rs refactor Box<! -> dyn Error> regression test 2025-12-02 11:07:42 +01:00
coerce-loop-issue-122561.rs add explanation comments to !-related tests 2025-11-14 00:04:58 +01:00
coerce-loop-issue-122561.stderr add explanation comments to !-related tests 2025-11-14 00:04:58 +01:00
coerce-mut-trait-object-8248.rs Add test batch 2 2025-08-27 15:06:05 -04:00
coerce-mut-trait-object-8248.stderr Add test batch 2 2025-08-27 15:06:05 -04:00
coerce-mut.rs compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
coerce-mut.stderr compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
coerce-overloaded-autoderef-fail.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
coerce-overloaded-autoderef-fail.stderr Tweak E0597 2023-01-15 19:46:20 +00:00
coerce-overloaded-autoderef.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coerce-reborrow-imm-ptr-arg.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coerce-reborrow-imm-ptr-rcvr.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-reborrow-imm-vec-arg.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coerce-reborrow-imm-vec-rcvr.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-reborrow-multi-arg-fail.rs UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
coerce-reborrow-multi-arg-fail.stderr Tweak parameter mismatch explanation to not say unknown 2024-11-25 03:04:07 +00:00
coerce-reborrow-multi-arg.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-reborrow-mut-ptr-arg.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coerce-reborrow-mut-ptr-rcvr.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coerce-reborrow-mut-vec-arg.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-reborrow-mut-vec-rcvr.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-to-bang-cast.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
coerce-to-bang-cast.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
coerce-unify-return.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coerce-unify.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coerce-unsize-subtype.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
coercion-missing-tail-expected-type.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coercion-missing-tail-expected-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coercion-missing-tail-expected-type.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
coercion-slice.rs compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
coercion-slice.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
constrain-expectation-in-arg.rs Inline expected_inputs_for_expected_output into check_argument_types/check_expr_struct_fields 2024-08-31 16:08:29 -04:00
fake-sized-ptr-cast.rs Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts 2025-08-23 16:49:15 +00:00
hr_alias_normalization_leaking_vars.rs reviews 2025-12-03 16:36:32 +00:00
hr_alias_normalization_leaking_vars.stderr reviews 2025-12-03 16:36:32 +00:00
index-coercion-over-indexmut-72002.rs Add test batch 5 2025-10-12 00:33:20 -04:00
intrinsic-in-unifying-coercion-149143.rs Check for intrinsic to fn ptr casts in unified coercions 2025-11-21 00:01:21 +01:00
intrinsic-in-unifying-coercion-149143.stderr Check for intrinsic to fn ptr casts in unified coercions 2025-11-21 00:01:21 +01:00
invalid-blanket-coerce-unsized-impl.rs Check CoerceUnsized impl validity before coercing 2025-06-24 17:48:09 +00:00
invalid-blanket-coerce-unsized-impl.stderr Check CoerceUnsized impl validity before coercing 2025-06-24 17:48:09 +00:00
issue-3794.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-14589.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-14589.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
issue-26905-rpass.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-26905.rs Move some tests 2024-02-09 15:43:08 -03:00
issue-26905.stderr Consolidate and rework CoercePointee and DispatchFromDyn errors 2025-02-24 19:34:54 +00:00
issue-32122-1.fixed Move some tests 2024-04-21 15:43:43 -03:00
issue-32122-1.rs Move some tests 2024-04-21 15:43:43 -03:00
issue-32122-1.stderr Move some tests 2024-04-21 15:43:43 -03:00
issue-32122-2.fixed Move some tests 2024-04-21 15:43:43 -03:00
issue-32122-2.rs Move some tests 2024-04-21 15:43:43 -03:00
issue-32122-2.stderr Move some tests 2024-04-21 15:43:43 -03:00
issue-36007.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-37655.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-39823.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-53475.rs Remove track_errors entirely 2024-01-23 15:23:22 +00:00
issue-53475.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-73886.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-73886.stderr Make cast suggestions verbose 2025-06-06 19:53:12 +00:00
issue-88097.rs Properly handle closure<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:53:54 +00:00
issue-101066.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
leak_check_fndef_lub.rs reviews 2025-12-03 16:36:32 +00:00
leak_check_fndef_lub_deadcode_breakage.rs reviews 2025-12-03 16:36:32 +00:00
leak_check_fndef_lub_deadcode_breakage.stderr reviews 2025-12-03 16:36:32 +00:00
lub_coercion_handles_safety.rs account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00
method-return-trait-object-14399.rs comments 2025-08-05 19:34:46 +05:00
method-return-trait-object-14399.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
mut-mut-wont-coerce.rs compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
mut-mut-wont-coerce.stderr compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
mut-trait-object-coercion-8398.rs Rehome tests/ui/issues/ tests [5/?] 2025-08-17 13:01:02 -04:00
no_local_for_coerced_const-issue-143671.rs mark THIR use as candidate for constness check 2025-09-25 01:54:25 +08:00
non-primitive-cast-135412.fixed fix for issue 135412 2025-04-24 03:20:19 +05:00
non-primitive-cast-135412.rs fix for issue 135412 2025-04-24 03:20:19 +05:00
non-primitive-cast-135412.stderr Make cast suggestions verbose 2025-06-06 19:53:12 +00:00
pin-dyn-dispatch-sound.rs Add test for dynamic dispatch + Pin::new soundness 2024-05-13 14:25:03 +02:00
pin-dyn-dispatch-sound.stderr Add test for dynamic dispatch + Pin::new soundness 2024-05-13 14:25:03 +02:00
ptr-mutability-errors.rs cleaned up some tests 2025-07-05 00:45:24 +05:00
ptr-mutability-errors.stderr cleaned up some tests 2025-07-05 00:45:24 +05:00
retslot-cast.rs Add missing dyn keywords to tests that do not test for them 2025-06-02 11:02:50 +02:00
retslot-cast.stderr Add missing dyn keywords to tests that do not test for them 2025-06-02 11:02:50 +02:00
struct-coerce-vec-to-slice.rs cleaned and organized 3 tests in ./tests/ui/issues 2025-03-21 22:55:00 -06:00
struct-literal-field-type-coercion-to-expected-type.rs cleaned and organized 3 tests in ./tests/ui/issues 2025-03-21 22:55:00 -06:00
structural_identity_dependent_reborrows.rs non-behaviour changing cleanups 2025-12-03 14:53:54 +00:00
structural_identity_dependent_reborrows.stderr non-behaviour changing cleanups 2025-12-03 14:53:54 +00:00
sub-principals.rs Check allow instantiating object trait binder when upcasting and in new solver 2024-09-26 22:26:29 -04:00
trait-object-arrays-11205.rs comments 2025-07-25 20:38:54 +05:00
trait-object-coercion-distribution-9951.rs Rehome tests/ui/issues/ tests [4/?] 2025-08-10 11:54:15 -04:00
trait-object-coercion-distribution-9951.stderr bless tests with new lint messages 2025-08-19 21:27:10 +02:00
type-errors.rs fix ICE for deref coercions with type errors 2024-02-12 14:37:35 +01:00
type-errors.stderr Merge E0412 into E0425 2025-12-02 18:25:13 +00:00
unboxing-needing-parenthases-issue-132924.rs add parentheses when unboxing suggestion needed 2024-11-12 18:23:57 +08:00
unboxing-needing-parenthases-issue-132924.stderr add parentheses when unboxing suggestion needed 2024-11-12 18:23:57 +08:00
unsafe-coercion.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00