Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
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.
Expand All @@ -442,6 +442,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/const-generics/mgca/type-const-associated-default.rs
Original file line number Diff line number Diff line change
@@ -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(){
}
13 changes: 13 additions & 0 deletions tests/ui/const-generics/mgca/type-const-associated-default.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading