rust/tests/ui/feature-gates
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
..
auxiliary
allow-features-empty.rs
allow-features-empty.stderr
allow-features.rs
allow-features.stderr
bench.rs
bench.stderr
doc-rust-logo.rs
doc-rust-logo.stderr
duplicate-features.rs
duplicate-features.stderr
env-flag.rs
env-flag.stderr
feature-gate-abi_ptx.rs
feature-gate-abi_ptx.stderr
feature-gate-abi_unadjusted.rs
feature-gate-abi_unadjusted.stderr
feature-gate-abi-avr-interrupt.rs
feature-gate-abi-avr-interrupt.stderr
feature-gate-abi-msp430-interrupt.rs
feature-gate-abi-msp430-interrupt.stderr
feature-gate-abi-riscv-interrupt.rs
feature-gate-abi-riscv-interrupt.stderr
feature-gate-abi-x86-interrupt.rs
feature-gate-abi-x86-interrupt.stderr
feature-gate-abi.rs
feature-gate-abi.stderr
feature-gate-adt_const_params.rs
feature-gate-adt_const_params.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
feature-gate-alloc-error-handler.rs
feature-gate-alloc-error-handler.stderr
feature-gate-allocator_internals.rs
feature-gate-allocator_internals.stderr
feature-gate-allow-internal-unsafe-nested-macro.rs
feature-gate-allow-internal-unsafe-nested-macro.stderr
feature-gate-allow-internal-unstable-nested-macro.rs
feature-gate-allow-internal-unstable-nested-macro.stderr
feature-gate-allow-internal-unstable-struct.rs
feature-gate-allow-internal-unstable-struct.stderr
feature-gate-allow-internal-unstable.rs
feature-gate-allow-internal-unstable.stderr
feature-gate-arbitrary_self_types-raw-pointer.rs
feature-gate-arbitrary_self_types-raw-pointer.stderr
feature-gate-arbitrary-self-types.rs
feature-gate-arbitrary-self-types.stderr
feature-gate-asm_const.rs
feature-gate-asm_const.stderr
feature-gate-asm_experimental_arch.rs
feature-gate-asm_experimental_arch.stderr
feature-gate-asm_goto.rs
feature-gate-asm_goto.stderr
feature-gate-asm_unwind.rs
feature-gate-asm_unwind.stderr
feature-gate-assoc-type-defaults.rs
feature-gate-assoc-type-defaults.stderr
feature-gate-associated_const_equality.rs
feature-gate-associated_const_equality.stderr
feature-gate-auto-traits.rs
feature-gate-auto-traits.stderr
feature-gate-box_patterns.rs
feature-gate-box_patterns.stderr
feature-gate-builtin_syntax.rs
feature-gate-builtin_syntax.stderr
feature-gate-c_variadic.rs
feature-gate-c_variadic.stderr
feature-gate-cfg_overflow_checks.rs
feature-gate-cfg_overflow_checks.stderr
feature-gate-cfg_sanitize.rs
feature-gate-cfg_sanitize.stderr
feature-gate-cfg-relocation-model.rs
feature-gate-cfg-relocation-model.stderr
feature-gate-cfg-sanitizer_cfi.rs
feature-gate-cfg-sanitizer_cfi.stderr
feature-gate-cfg-target-compact.rs
feature-gate-cfg-target-compact.stderr
feature-gate-cfg-target-has-atomic-equal-alignment.rs
feature-gate-cfg-target-has-atomic-equal-alignment.stderr
feature-gate-cfg-target-has-atomic.rs
feature-gate-cfg-target-has-atomic.stderr
feature-gate-cfg-target-thread-local.rs
feature-gate-cfg-target-thread-local.stderr
feature-gate-cfg-version.rs
feature-gate-cfg-version.stderr
feature-gate-cfi_encoding.rs
feature-gate-cfi_encoding.stderr
feature-gate-check-cfg.rs
feature-gate-check-cfg.stderr
feature-gate-closure_lifetime_binder.rs
feature-gate-closure_lifetime_binder.stderr
feature-gate-closure_track_caller.rs
feature-gate-closure_track_caller.stderr
feature-gate-collapse_debuginfo.rs
feature-gate-collapse_debuginfo.stderr
feature-gate-compiler-builtins.rs
feature-gate-compiler-builtins.stderr
feature-gate-concat_bytes.rs
feature-gate-concat_bytes.stderr
feature-gate-concat_idents2.rs
feature-gate-concat_idents2.stderr
feature-gate-concat_idents3.rs
feature-gate-concat_idents3.stderr
feature-gate-concat_idents.rs
feature-gate-concat_idents.stderr
feature-gate-const_refs_to_cell.rs
feature-gate-const-indexing.rs
feature-gate-const-refs-to-static.rs
feature-gate-const-refs-to-static.stderr
feature-gate-coroutines.e2024.stderr
feature-gate-coroutines.none.stderr
feature-gate-coroutines.rs
feature-gate-coverage-attribute.rs
feature-gate-coverage-attribute.stderr
feature-gate-custom_attribute2.rs
feature-gate-custom_attribute2.stderr
feature-gate-custom_attribute.rs
feature-gate-custom_attribute.stderr
feature-gate-custom_mir.rs
feature-gate-custom_mir.stderr
feature-gate-custom_test_frameworks.rs
feature-gate-custom_test_frameworks.stderr
feature-gate-decl_macro.rs
feature-gate-decl_macro.stderr
feature-gate-default_type_parameter_fallback.rs
feature-gate-default_type_parameter_fallback.stderr
feature-gate-deprecated_safe.rs
feature-gate-deprecated_safe.stderr
feature-gate-dispatch-from-dyn-cell.rs
feature-gate-dispatch-from-dyn-cell.stderr
feature-gate-dispatch-from-dyn-missing-impl.rs
feature-gate-dispatch-from-dyn-missing-impl.stderr
feature-gate-doc_cfg.rs
feature-gate-doc_cfg.stderr
feature-gate-doc_masked.rs
feature-gate-doc_masked.stderr
feature-gate-doc_notable_trait.rs
feature-gate-doc_notable_trait.stderr
feature-gate-exclusive-range-pattern.rs
feature-gate-exclusive-range-pattern.stderr
feature-gate-exhaustive-patterns.rs
feature-gate-exhaustive-patterns.stderr
feature-gate-explicit_tail_calls.rs
feature-gate-explicit_tail_calls.stderr
feature-gate-extern_absolute_paths.rs
feature-gate-extern_absolute_paths.stderr
feature-gate-extern_prelude.rs
feature-gate-extern_prelude.stderr
feature-gate-extern_types.rs
feature-gate-extern_types.stderr
feature-gate-f16.rs Add feature gates for f16 and f128 2024-03-14 13:32:54 -04:00
feature-gate-f16.stderr Add feature gates for f16 and f128 2024-03-14 13:32:54 -04:00
feature-gate-f128.rs Add feature gates for f16 and f128 2024-03-14 13:32:54 -04:00
feature-gate-f128.stderr Add feature gates for f16 and f128 2024-03-14 13:32:54 -04:00
feature-gate-feature-gate.rs
feature-gate-feature-gate.stderr
feature-gate-ffi_const.rs
feature-gate-ffi_const.stderr
feature-gate-ffi_pure.rs
feature-gate-ffi_pure.stderr
feature-gate-fn_align.rs
feature-gate-fn_align.stderr
feature-gate-fn_delegation.rs
feature-gate-fn_delegation.stderr
feature-gate-format_args_nl.rs
feature-gate-format_args_nl.stderr
feature-gate-freeze-impls.rs
feature-gate-freeze-impls.stderr
feature-gate-fundamental.rs
feature-gate-fundamental.stderr
feature-gate-gen_blocks.e2024.stderr
feature-gate-gen_blocks.none.stderr
feature-gate-gen_blocks.rs
feature-gate-generic_arg_infer.normal.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
feature-gate-generic_arg_infer.rs
feature-gate-generic_associated_types_extended.rs
feature-gate-generic_associated_types_extended.stderr
feature-gate-impl_trait_in_assoc_type.rs
feature-gate-impl_trait_in_assoc_type.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
feature-gate-impl_trait_in_fn_trait_return.rs
feature-gate-impl_trait_in_fn_trait_return.stderr
feature-gate-inherent_associated_types.rs
feature-gate-inherent_associated_types.stderr
feature-gate-inline_const_pat.rs
feature-gate-inline_const_pat.stderr
feature-gate-inline_const.rs
feature-gate-inline_const.stderr
feature-gate-intrinsics.rs
feature-gate-intrinsics.stderr
feature-gate-is_sorted.rs
feature-gate-is_sorted.stderr
feature-gate-lang-items.rs
feature-gate-lang-items.stderr
feature-gate-large-assignments.rs
feature-gate-large-assignments.stderr
feature-gate-lifetime-capture-rules-2024.rs
feature-gate-lifetime-capture-rules-2024.stderr
feature-gate-link_cfg.rs
feature-gate-link_cfg.stderr
feature-gate-link_llvm_intrinsics.rs
feature-gate-link_llvm_intrinsics.stderr
feature-gate-link-arg-attribute.rs
feature-gate-link-arg-attribute.stderr
feature-gate-linkage.rs
feature-gate-linkage.stderr
feature-gate-lint-reasons.rs
feature-gate-lint-reasons.stderr
feature-gate-log_syntax2.rs
feature-gate-log_syntax2.stderr
feature-gate-log_syntax2.stdout
feature-gate-log_syntax.rs
feature-gate-log_syntax.stderr
feature-gate-log_syntax.stdout
feature-gate-marker_trait_attr.rs
feature-gate-marker_trait_attr.stderr
feature-gate-may-dangle.rs
feature-gate-may-dangle.stderr
feature-gate-min_const_fn.rs
feature-gate-min_const_fn.stderr
feature-gate-more-qualified-paths.rs
feature-gate-more-qualified-paths.stderr
feature-gate-multiple_supertrait_upcastable.rs
feature-gate-multiple_supertrait_upcastable.stderr
feature-gate-naked_functions.rs
feature-gate-naked_functions.stderr
feature-gate-native_link_modifiers_as_needed.rs
feature-gate-native_link_modifiers_as_needed.stderr
feature-gate-needs-allocator.rs
feature-gate-needs-allocator.stderr
feature-gate-negate-unsigned.rs
feature-gate-negate-unsigned.stderr
feature-gate-negative_bounds.rs
feature-gate-negative_bounds.stderr
feature-gate-never_patterns.rs
feature-gate-never_patterns.stderr
feature-gate-never_type.rs
feature-gate-never_type.stderr
feature-gate-no_core.rs
feature-gate-no_core.stderr
feature-gate-no_sanitize.rs
feature-gate-no_sanitize.stderr
feature-gate-non_exhaustive_omitted_patterns_lint.rs
feature-gate-non_exhaustive_omitted_patterns_lint.stderr
feature-gate-non_lifetime_binders.rs
feature-gate-non_lifetime_binders.stderr
feature-gate-object_safe_for_dispatch.rs
feature-gate-object_safe_for_dispatch.stderr
feature-gate-offset-of-enum.rs
feature-gate-offset-of-enum.stderr
feature-gate-offset-of-nested.rs
feature-gate-offset-of-nested.stderr
feature-gate-omit-gdb-pretty-printer-section.rs
feature-gate-omit-gdb-pretty-printer-section.stderr
feature-gate-optimize_attribute.rs
feature-gate-optimize_attribute.stderr
feature-gate-overlapping_marker_traits.rs
feature-gate-overlapping_marker_traits.stderr
feature-gate-pattern-complexity.rs
feature-gate-pattern-complexity.stderr
feature-gate-precise_pointer_size_matching.rs
feature-gate-precise_pointer_size_matching.stderr
feature-gate-prelude_import.rs
feature-gate-prelude_import.stderr
feature-gate-proc_macro_byte_character.rs
feature-gate-proc_macro_byte_character.stderr
feature-gate-proc_macro_c_str_literals.rs
feature-gate-proc_macro_c_str_literals.stderr
feature-gate-profiler-runtime.rs
feature-gate-profiler-runtime.stderr
feature-gate-public_private_dependencies.rs
feature-gate-register_tool.rs
feature-gate-register_tool.stderr
feature-gate-repr128.rs
feature-gate-repr128.stderr
feature-gate-repr-simd.rs
feature-gate-repr-simd.stderr
feature-gate-return_type_notation.cfg.stderr
feature-gate-return_type_notation.no.stderr
feature-gate-return_type_notation.rs
feature-gate-rust_cold_cc.rs
feature-gate-rust_cold_cc.stderr
feature-gate-rustc_const_unstable.rs
feature-gate-rustc_const_unstable.stderr
feature-gate-rustc-allow-const-fn-unstable.rs
feature-gate-rustc-allow-const-fn-unstable.stderr
feature-gate-rustc-attrs-1.rs
feature-gate-rustc-attrs-1.stderr
feature-gate-rustc-attrs.rs
feature-gate-rustc-attrs.stderr
feature-gate-rustdoc_internals.rs
feature-gate-rustdoc_internals.stderr
feature-gate-simd-ffi.rs
feature-gate-simd-ffi.stderr
feature-gate-simd.rs
feature-gate-simd.stderr
feature-gate-staged_api.rs
feature-gate-staged_api.stderr
feature-gate-start.rs
feature-gate-start.stderr
feature-gate-stmt_expr_attributes.rs
feature-gate-stmt_expr_attributes.stderr
feature-gate-strict_provenance.rs
feature-gate-strict_provenance.stderr
feature-gate-test_unstable_lint.rs
feature-gate-test_unstable_lint.stderr
feature-gate-thread_local.rs
feature-gate-thread_local.stderr
feature-gate-trace_macros.rs
feature-gate-trace_macros.stderr
feature-gate-trait_upcasting.rs
feature-gate-trait_upcasting.stderr
feature-gate-trait-alias.rs
feature-gate-trait-alias.stderr
feature-gate-transparent_unions.rs
feature-gate-transparent_unions.stderr
feature-gate-trivial_bounds-lint.rs
feature-gate-trivial_bounds.rs
feature-gate-trivial_bounds.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
feature-gate-try_blocks.rs
feature-gate-try_blocks.stderr
feature-gate-type_alias_impl_trait.rs
feature-gate-type_ascription.rs
feature-gate-type_ascription.stderr
feature-gate-type_privacy_lints.rs
feature-gate-type_privacy_lints.stderr
feature-gate-unboxed-closures-manual-impls.rs
feature-gate-unboxed-closures-manual-impls.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
feature-gate-unboxed-closures-method-calls.rs
feature-gate-unboxed-closures-method-calls.stderr
feature-gate-unboxed-closures-ufcs-calls.rs
feature-gate-unboxed-closures-ufcs-calls.stderr
feature-gate-unboxed-closures.rs
feature-gate-unboxed-closures.stderr
feature-gate-unix_sigpipe.rs
feature-gate-unix_sigpipe.stderr
feature-gate-unnamed_fields.rs
feature-gate-unnamed_fields.stderr
feature-gate-unsafe_pin_internals.rs
feature-gate-unsafe_pin_internals.stderr
feature-gate-unsized_fn_params.rs
feature-gate-unsized_fn_params.stderr
feature-gate-unsized_locals.rs
feature-gate-unsized_locals.stderr
feature-gate-unsized_tuple_coercion.rs
feature-gate-unsized_tuple_coercion.stderr
feature-gate-used_with_arg.rs
feature-gate-used_with_arg.stderr
feature-gate-vectorcall.rs
feature-gate-vectorcall.stderr
feature-gate-wasm_abi.rs
feature-gate-wasm_abi.stderr
feature-gate-with_negative_coherence.rs
feature-gate-with_negative_coherence.stderr
feature-gate-yeet_expr-in-cfg.rs
feature-gate-yeet_expr-in-cfg.stderr
feature-gate-yeet_expr.rs
feature-gate-yeet_expr.stderr
feature-gated-feature-in-macro-arg.rs
feature-gated-feature-in-macro-arg.stderr
gated-bad-feature.rs
gated-bad-feature.stderr
issue-43106-gating-of-bench.rs
issue-43106-gating-of-bench.stderr
issue-43106-gating-of-builtin-attrs-error.rs
issue-43106-gating-of-builtin-attrs-error.stderr
issue-43106-gating-of-builtin-attrs.rs
issue-43106-gating-of-builtin-attrs.stderr
issue-43106-gating-of-deprecated.rs
issue-43106-gating-of-derive-2.rs
issue-43106-gating-of-derive-2.stderr
issue-43106-gating-of-derive.rs
issue-43106-gating-of-derive.stderr
issue-43106-gating-of-macro_escape.rs
issue-43106-gating-of-macro_escape.stderr
issue-43106-gating-of-macro_use.rs
issue-43106-gating-of-macro_use.stderr
issue-43106-gating-of-proc_macro_derive.rs
issue-43106-gating-of-proc_macro_derive.stderr
issue-43106-gating-of-stable.rs
issue-43106-gating-of-stable.stderr
issue-43106-gating-of-test.rs
issue-43106-gating-of-test.stderr
issue-43106-gating-of-unstable.rs
issue-43106-gating-of-unstable.stderr
issue-49983-see-issue-0.rs
issue-49983-see-issue-0.stderr
rustc-private.rs
rustc-private.stderr
soft-syntax-gates-with-errors.rs
soft-syntax-gates-with-errors.stderr
soft-syntax-gates-without-errors.rs
soft-syntax-gates-without-errors.stderr
stability-attribute-consistency.rs
stability-attribute-consistency.stderr
stable-features.rs
stable-features.stderr
test-listing-format-json.rs
test-listing-format-json.run.stderr
trace_macros-gate.rs
trace_macros-gate.stderr
unknown-feature.rs
unknown-feature.stderr
unstable-attribute-allow-issue-0.rs
unstable-attribute-allow-issue-0.stderr