rust/compiler
bors 21d94a3d2c Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk
Stabilize associated type bounds (RFC 2289)

This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses.

### What are we stabilizing?

We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation.

In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info).

Associated type bounds are stabilized in four positions:
* **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`.
* **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629.
* **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`.
* **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound.

The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds.

### How does this differ from the RFC?

Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular:
* It does *not* desugar to anonymous associated items in associated type item bounds.
* It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds.

This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example:
* Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531.
* Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types.

This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719.

### Implementation history:

Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out--
* #57428
* #108063
* #110512
* #112629
* #120719
* #120584

Closes #52662

[RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-19 00:04:09 +00:00
..
rustc Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_abi Auto merge of #121668 - erikdesjardins:commonprim, r=scottmcm,oli-obk 2024-03-13 15:25:35 +00:00
rustc_arena rename ptr::invalid -> ptr::without_provenance 2024-02-21 20:15:52 +01:00
rustc_ast Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_ast_ir Fix typo in VisitorResult 2024-03-08 23:20:29 -05:00
rustc_ast_lowering do not eat nested exprs result in format args visitor 2024-03-18 09:27:47 +00:00
rustc_ast_passes Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_ast_pretty Rename ast::StmtKind::Local into ast::StmtKind::Let 2024-03-14 12:42:04 +01:00
rustc_attr Rename IntoDiagnostic as Diagnostic. 2024-03-11 09:15:09 +11:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_builtin_macros delay expand macro bang when there has indeterminate path 2024-03-13 16:11:16 +08:00
rustc_codegen_cranelift Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
rustc_codegen_gcc Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_codegen_llvm Rollup merge of #122649 - cuviper:min-llvm-17, r=nikic 2024-03-18 16:27:09 +01:00
rustc_codegen_ssa Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_const_eval Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin 2024-03-18 22:24:38 +01:00
rustc_data_structures Issue 122262: MAP_PRIVATE for more reliability on virtualised filesystems. 2024-03-15 18:31:07 -04:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Rollup merge of #121764 - Zoxc:incr-sess-no-source, r=oli-obk 2024-03-14 20:00:18 +01:00
rustc_error_codes Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_error_messages Rename SubdiagnosticMessage as SubdiagMessage. 2024-03-05 12:14:49 +11:00
rustc_errors Make SubdiagMessageOp well-formed 2024-03-14 13:13:08 -04:00
rustc_expand Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_feature Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_fluent_macro Rename SubdiagnosticMessage as SubdiagMessage. 2024-03-05 12:14:49 +11:00
rustc_fs_util Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_graphviz Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_hir Add missing try_visit calls in visitors. 2024-03-18 11:21:06 -04:00
rustc_hir_analysis Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin 2024-03-18 22:24:38 +01:00
rustc_hir_pretty Rollup merge of #122487 - GuillaumeGomez:rename-stmtkind-local, r=oli-obk 2024-03-14 20:00:21 +01:00
rustc_hir_typeck Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin 2024-03-18 22:24:38 +01:00
rustc_incremental Make incremental sessions identity no longer depend on the crate names provided by source code 2024-03-13 16:40:02 +01:00
rustc_index doc: Add better explanation 2024-03-06 16:54:42 +01:00
rustc_index_macros Step all bootstrap cfgs forward 2024-02-08 07:44:34 -05:00
rustc_infer Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_interface Rollup merge of #121764 - Zoxc:incr-sess-no-source, r=oli-obk 2024-03-14 20:00:18 +01:00
rustc_lexer Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_lint Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin 2024-03-18 22:24:38 +01:00
rustc_lint_defs Rollup merge of #121720 - tmandry:split-refining, r=compiler-errors 2024-03-16 23:28:47 +01:00
rustc_llvm Update the minimum external LLVM to 17 2024-03-17 10:11:04 -07:00
rustc_log rustc_log: expose tracing-tree "wraparound" in an env var 2024-03-03 12:33:26 +01:00
rustc_macros Rename diagnostic derive things. 2024-03-11 10:06:34 +11:00
rustc_metadata Rollup merge of #122588 - klensy:imported_source_file, r=michaelwoerister 2024-03-18 16:27:08 +01:00
rustc_middle Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_mir_build Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_mir_dataflow Distinguish between library and lang UB in assert_unsafe_precondition 2024-03-08 18:53:58 -05:00
rustc_mir_transform Rollup merge of #122701 - compiler-errors:allocator-suspend, r=oli-obk 2024-03-18 22:24:41 +01:00
rustc_monomorphize Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
rustc_next_trait_solver Allow a way to add constructors for rustc_type_ir types 2024-03-04 15:39:59 +00:00
rustc_parse Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_parse_format remove a couple of redundant clones 2024-02-17 12:46:18 +01:00
rustc_passes Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin 2024-03-18 22:24:38 +01:00
rustc_pattern_analysis Rollup merge of #121823 - Nadrieril:never-witnesses, r=compiler-errors 2024-03-18 22:24:36 +01:00
rustc_privacy Test and implement reachability for trait objects and generic parameters of functions 2024-03-14 14:10:45 +00:00
rustc_query_impl Verify that query keys result in unique dep nodes 2024-03-12 05:31:41 +01:00
rustc_query_system Rollup merge of #122245 - saethlin:check-dep-graph-size, r=petrochenkov 2024-03-12 09:04:00 -07:00
rustc_resolve Auto merge of #121926 - tgross35:f16-f128-step3-feature-gate, r=compiler-errors,petrochenkov 2024-03-16 02:02:00 +00:00
rustc_serialize Stabilize associated type bounds 2024-03-08 20:56:25 +00:00
rustc_session Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin 2024-03-18 22:24:38 +01:00
rustc_smir Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
rustc_span remove retag_box_to_raw, it is no longer needed 2024-03-18 10:32:25 +01:00
rustc_symbol_mangling Rename IntoDiagnostic as Diagnostic. 2024-03-11 09:15:09 +11:00
rustc_target Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiser 2024-03-14 20:00:18 +01:00
rustc_trait_selection Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk 2024-03-19 00:04:09 +00:00
rustc_traits Merge check_mod_impl_wf and check_mod_type_wf 2024-03-07 06:27:09 +00:00
rustc_transmute Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
rustc_ty_utils Rollup merge of #122513 - petrochenkov:somehir4, r=fmease 2024-03-15 17:24:09 +01:00
rustc_type_ir improve comments 2024-03-18 18:13:25 +01:00
stable_mir Rollup merge of #122405 - celinval:smir-new-const, r=oli-obk 2024-03-14 11:09:58 +01:00