rust/compiler
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
..
rustc Fix overcapturing, unsafe extern blocks, and new unsafe ops 2025-02-22 00:01:48 +00:00
rustc_abi Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_arena Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ast Auto merge of #137420 - matthiaskrgr:rollup-rr0q37f, r=matthiaskrgr 2025-02-22 13:32:44 +00:00
rustc_ast_ir Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ast_lowering Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_ast_passes Rollup merge of #137435 - estebank:match-arm-2, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_ast_pretty Rollup merge of #137423 - Urgau:imprv-pretty-hir, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_attr_data_structures Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_attr_parsing Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_baked_icu_data Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_borrowck Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_builtin_macros Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3 2025-02-23 00:16:18 +01:00
rustc_codegen_cranelift Rollup merge of #137505 - tgross35:builtins-cannot-call-error, r=compiler-errors 2025-02-24 02:11:38 -05:00
rustc_codegen_gcc Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35 2025-02-23 14:30:25 -05:00
rustc_codegen_llvm Auto merge of #137271 - nikic:gep-nuw-2, r=scottmcm 2025-02-24 03:06:16 +00:00
rustc_codegen_ssa Rollup merge of #137505 - tgross35:builtins-cannot-call-error, r=compiler-errors 2025-02-24 02:11:38 -05:00
rustc_const_eval Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_data_structures Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_driver Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_driver_impl Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_error_codes Consolidate and rework CoercePointee and DispatchFromDyn errors 2025-02-24 19:34:54 +00:00
rustc_error_messages Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_errors Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril 2025-02-22 11:36:43 +01:00
rustc_expand Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_feature Remove dyn_compatible_for_dispatch 2025-02-24 18:48:40 +00:00
rustc_fluent_macro Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_fs_util Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_graphviz Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_hashes Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_hir Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_hir_analysis Rollup merge of #137289 - compiler-errors:coerce-unsized-errors, r=oli-obk 2025-02-24 19:21:45 -05:00
rustc_hir_pretty Rollup merge of #137423 - Urgau:imprv-pretty-hir, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_hir_typeck Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_incremental Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk 2025-02-23 00:16:19 +01:00
rustc_index Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_index_macros Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_infer Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_interface Auto merge of #137420 - matthiaskrgr:rollup-rr0q37f, r=matthiaskrgr 2025-02-22 13:32:44 +00:00
rustc_lexer Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_lint Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrum 2025-02-23 11:12:56 +00:00
rustc_lint_defs Fix binding mode problems 2025-02-22 00:13:19 +00:00
rustc_llvm Auto merge of #137271 - nikic:gep-nuw-2, r=scottmcm 2025-02-24 03:06:16 +00:00
rustc_log Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_macros Fix binding mode problems 2025-02-22 00:13:19 +00:00
rustc_metadata Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_middle Fix some use items that import more than necessary. 2025-02-24 09:30:42 +11:00
rustc_mir_build Fix some use items that import more than necessary. 2025-02-24 09:30:42 +11:00
rustc_mir_dataflow Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_mir_transform Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_monomorphize Auto merge of #137225 - RalfJung:vectorcall, r=nnethercote 2025-02-23 14:12:38 +00:00
rustc_next_trait_solver Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril 2025-02-22 11:36:43 +01:00
rustc_parse Rollup merge of #137435 - estebank:match-arm-2, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_parse_format Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_passes Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk 2025-02-23 00:16:19 +01:00
rustc_pattern_analysis Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_privacy Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk 2025-02-23 00:16:19 +01:00
rustc_query_impl Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_query_system Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_resolve Fix binding mode problems 2025-02-22 00:13:19 +00:00
rustc_sanitizers Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_serialize rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
rustc_session Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_smir Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_span Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35 2025-02-23 14:30:25 -05:00
rustc_symbol_mangling Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_target Rollup merge of #136637 - Pyr0de:binary-format, r=Noratrieb 2025-02-23 14:30:26 -05:00
rustc_trait_selection Remove dyn_compatible_for_dispatch 2025-02-24 18:48:40 +00:00
rustc_traits Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril 2025-02-22 11:36:43 +01:00
rustc_transmute Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ty_utils Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_type_ir Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_type_ir_macros Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
stable_mir Rollup merge of #137448 - compiler-errors:control-flow-oops, r=scottmcm 2025-02-23 02:44:20 -05:00