mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
gate defaulted type consts with associated_type_defaults
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user