gate defaulted type consts with associated_type_defaults

This commit is contained in:
LaneAsade
2026-02-08 23:06:35 +05:30
parent 7ad4e69ad5
commit 84140cf4e1
7 changed files with 38 additions and 4 deletions
+12 -1
View File
@@ -431,7 +431,7 @@ fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
false
}
ast::AssocItemKind::Const(box ast::ConstItem {
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
..
}) => {
// Make sure this is only allowed if the feature gate is enabled.
@@ -442,6 +442,17 @@ fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
i.span,
"associated `type const` are unstable"
);
// Make sure associated `type const` defaults in traits are only allowed
// if the feature gate is enabled.
// #![feature(associated_type_defaults)]
if ctxt == AssocCtxt::Trait && rhs.is_some() {
gate!(
&self,
associated_type_defaults,
i.span,
"associated type defaults are unstable"
);
}
false
}
_ => false,
@@ -4,7 +4,7 @@
//
// issue: <https://github.com/rust-lang/rust/issues/108220>
//@ check-pass
#![feature(min_generic_const_args)]
#![feature(min_generic_const_args, associated_type_defaults)]
#![allow(incomplete_features)]
pub trait TraitA<T> {
@@ -0,0 +1,9 @@
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Trait {
type const N: usize = 10;
//~^ ERROR associated type defaults are unstable
}
fn main(){
}
@@ -0,0 +1,13 @@
error[E0658]: associated type defaults are unstable
--> $DIR/type-const-associated-default.rs:4:5
|
LL | type const N: usize = 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
= help: add `#![feature(associated_type_defaults)]` 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 1 previous error
For more information about this error, try `rustc --explain E0658`.
@@ -1,6 +1,7 @@
// ICE: assertion failed: !value.has_infer()
// issue: rust-lang/rust#115806
#![feature(adt_const_params, min_generic_const_args, unsized_const_params)]
#![feature(associated_type_defaults)]
#![allow(incomplete_features)]
pub struct NoPin;
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin`
--> $DIR/assoc-const-no-infer-ice-115806.rs:16:1
--> $DIR/assoc-const-no-infer-ice-115806.rs:17:1
|
LL | impl<TA> Pins<TA> for NoPin {}
| --------------------------- first implementation here
@@ -4,7 +4,7 @@
//@ build-pass
//@ no-prefer-dynamic
#![feature(min_generic_const_args)]
#![feature(min_generic_const_args, associated_type_defaults)]
#![expect(incomplete_features)]
trait Trait {