rust/compiler/rustc_hir_analysis
Michael Goulet 0bb00e2085
Rollup merge of #137289 - compiler-errors:coerce-unsized-errors, r=oli-obk
Consolidate and improve error messaging for `CoerceUnsized` and `DispatchFromDyn`

Firstly, this PR consolidates and reworks the error diagnostics for `CoercePointee` and `DispatchFromDyn`. There was a ton of duplication for no reason -- this reworks both the errors and also the error codes, since they can be shared between both traits since they report the same thing.

Secondly, when encountering a struct with multiple fields that must be coerced, point out the field spans, rather than mentioning the fields by name. This makes the error message clearer, but also means that we don't mention the `__S` dummy parameter for `derive(CoercePointee)`.

Thirdly, emit a custom error message when we encounter a trait error that comes from the recursive field `CoerceUnsized`/`DispatchFromDyn` trait check. **Note:** This is the only one I'm not too satisfied with -- I think it could use some more refinement, but ideally it explains that the field must be an unsize-able pointer... Feedback welcome.

Finally, don't emit `DispatchFromDyn` validity errors if we detect `CoerceUnsized` validity errors from an impl of the same ADT.

This is best reviewed per commit.

r? `@oli-obk` perhaps?

cc `@dingxiangfei2009` -- sorry for making my own attempt at this PR, but I wanted to see if I could implement a fix for #136796 in a less complicated way, since communicating over github review comments can be a bit slow. I'll leave comments inline to explain my thinking about the diagnostics changes.
2025-02-24 19:21:45 -05:00
..
src Rollup merge of #137289 - compiler-errors:coerce-unsized-errors, r=oli-obk 2025-02-24 19:21:45 -05:00
Cargo.toml Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
messages.ftl Simplify trait error message for CoercePointee validation 2025-02-24 19:34:54 +00:00
README.md

For high-level intro to how type checking works in rustc, see the type checking chapter of the rustc dev guide.