rust/compiler
bors 4f7bb9890c Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnr
Rework upcasting confirmation to support upcasting to fewer projections in target bounds

This PR implements a modified trait upcasting algorithm that is resilient to changes in the number of associated types in the bounds of the source and target trait objects.

It does this by equating each bound of the target trait ref individually against the bounds of the source trait ref, rather than doing them all together by constructing a new trait object.

#### The new way we do trait upcasting confirmation

1. Equate the target trait object's principal trait ref with one of the supertraits of the source trait object's principal.
fdcab310b2/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2509-L2525)

2. Make sure that every auto trait in the *target* trait object is present in the source trait ref's bounds.
fdcab310b2/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2559-L2562)

3. For each projection in the *target* trait object, make sure there is exactly one projection that equates with it in the source trait ref's bound. If there is more than one, bail with ambiguity.
fdcab310b2/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2526-L2557)
    * Since there may be more than one that applies, we probe first to check that there is exactly one, then we equate it outside of a probe once we know that it's unique.

4. Make sure the lifetime of the source trait object outlives the lifetime of the target.

<details>
<summary>Meanwhile, this is how we used to do upcasting:</summary>

1. For each supertrait of the source trait object, take that supertrait, append the source object's projection bounds, and the *target* trait object's auto trait bounds, and make this into a new object type:
d12c6e947c/compiler/rustc_trait_selection/src/traits/select/confirmation.rs (L915-L929)

2. Then equate it with the target trait object:
d12c6e947c/compiler/rustc_trait_selection/src/traits/select/confirmation.rs (L936)

This will be a type mismatch if the target trait object has fewer projection bounds, since we compare the bounds structurally in relate:
d12c6e947c/compiler/rustc_middle/src/ty/relate.rs (L696-L698)

</details>

Fixes #114035
Also fixes #114113, because I added a normalize call in the old solver.

r? types
2023-08-04 10:55:22 +00:00
..
rustc inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_abi Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_arena Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_ast Auto merge of #114353 - nnethercote:parser-ast-cleanups, r=petrochenkov 2023-08-03 04:26:42 +00:00
rustc_ast_lowering
rustc_ast_passes inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_ast_pretty Remove MacDelimiter. 2023-08-03 09:03:30 +10:00
rustc_attr [rustc_attr][nit] Replace filter + is_some with map_or. 2023-08-01 12:39:32 -07:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=cjgillot 2023-08-04 09:18:58 +02:00
rustc_builtin_macros Remove MacDelimiter. 2023-08-03 09:03:30 +10:00
rustc_codegen_cranelift Forbid old-style simd_shuffleN intrinsics 2023-08-03 09:29:00 +00:00
rustc_codegen_gcc Forbid old-style simd_shuffleN intrinsics 2023-08-03 09:29:00 +00:00
rustc_codegen_llvm Auto merge of #114350 - erikdesjardins:ident, r=tmiasko 2023-08-04 07:17:02 +00:00
rustc_codegen_ssa Rollup merge of #114427 - Enselic:rustc_codegen_ssa-fixme, r=Nilstrieb 2023-08-04 09:18:59 +02:00
rustc_const_eval Rollup merge of #114372 - RalfJung:const-pointer-as-int, r=oli-obk 2023-08-03 17:29:08 +02:00
rustc_data_structures Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_driver
rustc_driver_impl
rustc_error_codes Rollup merge of #113534 - oli-obk:simd_shuffle_dehackify, r=workingjubilee 2023-08-04 07:25:45 +02:00
rustc_error_messages Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_errors Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_expand Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_feature Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_hir_analysis Rollup merge of #114253 - fmease:compute-variances-for-lazy-ty-aliases, r=oli-obk 2023-08-04 09:18:58 +02:00
rustc_hir_pretty
rustc_hir_typeck Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=cjgillot 2023-08-04 09:18:58 +02:00
rustc_incremental Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_index Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_infer Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnr 2023-08-04 10:55:22 +00:00
rustc_interface
rustc_lexer
rustc_lint Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk 2023-08-03 22:58:02 +00:00
rustc_lint_defs Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_llvm Auto merge of #113339 - lqd:respect-filters, r=tmiasko 2023-08-01 23:15:20 +00:00
rustc_log inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_macros Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_metadata Rollup merge of #114253 - fmease:compute-variances-for-lazy-ty-aliases, r=oli-obk 2023-08-04 09:18:58 +02:00
rustc_middle Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnr 2023-08-04 10:55:22 +00:00
rustc_mir_build Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=cjgillot 2023-08-04 09:18:58 +02:00
rustc_mir_dataflow Use upvar_tys in more places, make it a list 2023-08-01 23:19:31 +00:00
rustc_mir_transform Rollup merge of #113534 - oli-obk:simd_shuffle_dehackify, r=workingjubilee 2023-08-04 07:25:45 +02:00
rustc_monomorphize avoid 'miri' when refering to the shared interpreter 2023-08-02 16:52:03 +02:00
rustc_parse Rollup merge of #113999 - Centri3:macro-arm-expand, r=wesleywiser 2023-08-04 07:25:45 +02:00
rustc_parse_format
rustc_passes
rustc_plugin_impl
rustc_privacy Remove constness from TraitPredicate 2023-08-02 15:38:00 +00:00
rustc_query_impl Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_query_system inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_resolve Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_serialize
rustc_session Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_smir clean up, use opaque types 2023-08-01 17:48:20 +03:00
rustc_span Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk 2023-08-03 22:58:02 +00:00
rustc_symbol_mangling avoid 'miri' when refering to the shared interpreter 2023-08-02 16:52:03 +02:00
rustc_target Add internal_features lint 2023-08-03 14:50:50 +02:00
rustc_trait_selection Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnr 2023-08-04 10:55:22 +00:00
rustc_traits
rustc_transmute
rustc_ty_utils Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obk 2023-08-02 13:46:54 +02:00
rustc_type_ir Rollup merge of #114355 - compiler-errors:resolve_vars_early, r=lcnr 2023-08-04 09:18:59 +02:00