Skip to content

Commit 84140cf

Browse files
committed
gate defaulted type consts with associated_type_defaults
1 parent 7ad4e69 commit 84140cf

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
431431
false
432432
}
433433
ast::AssocItemKind::Const(box ast::ConstItem {
434-
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
434+
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
435435
..
436436
}) => {
437437
// Make sure this is only allowed if the feature gate is enabled.
@@ -442,6 +442,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
442442
i.span,
443443
"associated `type const` are unstable"
444444
);
445+
// Make sure associated `type const` defaults in traits are only allowed
446+
// if the feature gate is enabled.
447+
// #![feature(associated_type_defaults)]
448+
if ctxt == AssocCtxt::Trait && rhs.is_some() {
449+
gate!(
450+
&self,
451+
associated_type_defaults,
452+
i.span,
453+
"associated type defaults are unstable"
454+
);
455+
}
445456
false
446457
}
447458
_ => false,

tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// issue: <https://github.com/rust-lang/rust/issues/108220>
66
//@ check-pass
7-
#![feature(min_generic_const_args)]
7+
#![feature(min_generic_const_args, associated_type_defaults)]
88
#![allow(incomplete_features)]
99

1010
pub trait TraitA<T> {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(min_generic_const_args)]
2+
#![expect(incomplete_features)]
3+
trait Trait {
4+
type const N: usize = 10;
5+
//~^ ERROR associated type defaults are unstable
6+
}
7+
8+
fn main(){
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: associated type defaults are unstable
2+
--> $DIR/type-const-associated-default.rs:4:5
3+
|
4+
LL | type const N: usize = 10;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
8+
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ICE: assertion failed: !value.has_infer()
22
// issue: rust-lang/rust#115806
33
#![feature(adt_const_params, min_generic_const_args, unsized_const_params)]
4+
#![feature(associated_type_defaults)]
45
#![allow(incomplete_features)]
56

67
pub struct NoPin;

tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin`
2-
--> $DIR/assoc-const-no-infer-ice-115806.rs:16:1
2+
--> $DIR/assoc-const-no-infer-ice-115806.rs:17:1
33
|
44
LL | impl<TA> Pins<TA> for NoPin {}
55
| --------------------------- first implementation here

tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ build-pass
55
//@ no-prefer-dynamic
66

7-
#![feature(min_generic_const_args)]
7+
#![feature(min_generic_const_args, associated_type_defaults)]
88
#![expect(incomplete_features)]
99

1010
trait Trait {

0 commit comments

Comments
 (0)