Skip to content

Commit

Permalink
Stabilize associated type bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 5, 2024
1 parent 7606c13 commit ae9d4ca
Show file tree
Hide file tree
Showing 93 changed files with 146 additions and 531 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#![doc(rust_logo)]
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(associated_type_defaults)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
constraint.span,
"return type notation is experimental"
);
} else {
gate!(
&self,
associated_type_bounds,
constraint.span,
"associated type bounds are unstable"
);
}
}
visit::walk_assoc_constraint(self, constraint)
Expand Down Expand Up @@ -608,7 +601,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
}

gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
gate_all_legacy_dont_use!(associated_type_bounds, "associated type bounds are unstable");
// Despite being a new feature, `where T: Trait<Assoc(): Sized>`, which is RTN syntax now,
// used to be gated under associated_type_bounds, which are right above, so RTN needs to
// be too.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![feature(assert_matches)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(box_patterns)]
#![feature(let_chains)]
#![feature(min_specialization)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#![feature(
rustc_private,
decl_macro,
associated_type_bounds,
never_type,
trusted_len,
hash_raw_entry
)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![allow(broken_intra_doc_links)]
#![recursion_limit="256"]
#![warn(rust_2018_idioms)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(let_chains)]
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0719.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ An associated type value was specified more than once.
Erroneous code example:

```compile_fail,E0719
#![feature(associated_type_bounds)]
trait FooTrait {}
trait BarTrait {}
Expand All @@ -19,8 +17,6 @@ specify the associated type with the new trait.
Corrected example:

```
#![feature(associated_type_bounds)]
trait FooTrait {}
trait BarTrait {}
trait FooBarTrait: FooTrait + BarTrait {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![feature(array_windows)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(associated_type_defaults)]
#![feature(if_let_guard)]
#![feature(let_chains)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ declare_features! (
(accepted, asm_sym, "1.66.0", Some(93333)),
/// Allows the definition of associated constants in `trait` or `impl` blocks.
(accepted, associated_consts, "1.20.0", Some(29646)),
/// Allows the user of associated type bounds.
(accepted, associated_type_bounds, "CURRENT_RUSTC_VERSION", Some(52662)),
/// Allows using associated `type`s in `trait`s.
(accepted, associated_types, "1.0.0", None),
/// Allows free and inherent `async fn`s, `async` blocks, and `<expr>.await` expressions.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ declare_features! (
(unstable, asm_unwind, "1.58.0", Some(93334)),
/// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`.
(unstable, associated_const_equality, "1.58.0", Some(92827)),
/// Allows the user of associated type bounds.
(unstable, associated_type_bounds, "1.34.0", Some(52662)),
/// Allows associated type defaults.
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
/// Allows `async || body` closures.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(box_patterns)]
#![feature(extend_one)]
#![feature(let_chains)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#![feature(trusted_len)]
#![feature(type_alias_impl_trait)]
#![feature(strict_provenance)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(rustc_attrs)]
#![feature(control_flow_enum)]
#![feature(trait_upcasting)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![feature(assert_matches)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(let_chains)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@ impl<'a> Parser<'a> {
&& matches!(args.output, ast::FnRetTy::Default(..))
{
self.sess.gated_spans.gate(sym::return_type_notation, span);
} else {
self.sess.gated_spans.gate(sym::associated_type_bounds, span);
}
}
let constraint =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![doc(rust_logo)]
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(const_option)]
#![feature(core_intrinsics)]
#![feature(generic_nonzero)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![feature(assert_matches)]
#![feature(associated_type_bounds)]
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(extract_if)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
sugg.extend(ty_spans.into_iter().map(|s| (s, type_param_name.to_string())));

// Suggest `fn foo<T: Trait>(t: T) where <T as Trait>::A: Bound`.
// FIXME: once `#![feature(associated_type_bounds)]` is stabilized, we should suggest
// `fn foo(t: impl Trait<A: Bound>)` instead.
// FIXME: we should suggest `fn foo(t: impl Trait<A: Bound>)` instead.
err.multipart_suggestion(
"introduce a type parameter with a trait bound instead of using `impl Trait`",
sugg,
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@
//
// Language features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![cfg_attr(not(test), feature(coroutine_trait))]
#![cfg_attr(test, feature(panic_update_hook))]
#![cfg_attr(test, feature(test))]
#![feature(allocator_internals)]
#![feature(allow_internal_unstable)]
#![feature(associated_type_bounds)]
#![feature(c_unwind)]
#![feature(cfg_sanitize)]
#![feature(const_mut_refs)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@
//
// Language features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![cfg_attr(bootstrap, feature(platform_intrinsics))]
#![feature(abi_unadjusted)]
#![feature(adt_const_params)]
#![feature(allow_internal_unsafe)]
#![feature(allow_internal_unstable)]
#![feature(asm_const)]
#![feature(associated_type_bounds)]
#![feature(auto_traits)]
#![feature(c_unwind)]
#![feature(cfg_sanitize)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/associated-consts/issue-93835.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ fn e() {
//~| ERROR cannot find value
//~| ERROR associated const equality
//~| ERROR cannot find trait `p` in this scope
//~| ERROR associated type bounds
}

fn main() {}
12 changes: 1 addition & 11 deletions tests/ui/associated-consts/issue-93835.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ LL | type_ascribe!(p, a<p:p<e=6>>);
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: associated type bounds are unstable
--> $DIR/issue-93835.rs:4:24
|
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^^^^^^^^
|
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0405, E0412, E0425, E0658.
For more information about an error, try `rustc --explain E0405`.
2 changes: 0 additions & 2 deletions tests/ui/associated-type-bounds/ambiguous-associated-type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(associated_type_bounds)]

pub struct Flatten<I>
where
I: Iterator<Item: IntoIterator>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// Additionally, as reported in https://github.com/rust-lang/rust/issues/63594,
// we check that the spans for the error message are sane here.

#![feature(associated_type_bounds)]

fn main() {}

trait Bar {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: associated type bounds are not allowed in `dyn` types
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:28:28
|
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
| ^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(associated_type_bounds)]

use std::fmt::Debug;
use std::iter::Once;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(associated_type_bounds)]

trait B {
type AssocType;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: associated type bounds are not allowed in `dyn` types
--> $DIR/bad-universal-in-dyn-in-where-clause.rs:9:19
--> $DIR/bad-universal-in-dyn-in-where-clause.rs:7:19
|
LL | dyn for<'j> B<AssocType: 'j>:,
| ^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-type-bounds/bad-universal-in-impl-sig.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(associated_type_bounds)]

trait Trait {
type Item;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: associated type bounds are not allowed in `dyn` types
--> $DIR/bad-universal-in-impl-sig.rs:10:16
--> $DIR/bad-universal-in-impl-sig.rs:8:16
|
LL | impl dyn Trait<Item: Trait2> {}
| ^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(associated_type_bounds)]

use std::fmt::Debug;
use std::iter::Empty;
use std::ops::Range;
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-type-bounds/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(associated_type_bounds)]

pub fn accept(_: impl Trait<K: Copy>) {}
//~^ ERROR expected type, found constant

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-type-bounds/consts.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: expected type, found constant
--> $DIR/consts.rs:3:29
--> $DIR/consts.rs:1:29
|
LL | pub fn accept(_: impl Trait<K: Copy>) {}
| ^------ bounds are not allowed on associated constants
| |
| unexpected constant
|
note: the associated constant is defined here
--> $DIR/consts.rs:7:5
--> $DIR/consts.rs:5:5
|
LL | const K: i32;
| ^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/associated-type-bounds/duplicate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(associated_type_bounds)]
#![feature(type_alias_impl_trait)]

use std::iter;
Expand Down
Loading

0 comments on commit ae9d4ca

Please sign in to comment.