Skip to content

Commit 2af7441

Browse files
authored
Unrolled build for #152385
Rollup merge of #152385 - LaneAsade:gate-type-const-defaults, r=BoxyUwU Feature gate for defaulted associated type_consts with associated_type_defaults *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152385)* This PR for issue #130288 extends a feature gate that was already present for defaulted associated types to defaulted type consts under associated_type_defaults. Code added: ``` if ctxt == AssocCtxt::Trait && rhs.is_some() { gate!( &self, associated_type_defaults, i.span, "associated type defaults are unstable" ); } ``` Error produced: ``` 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 <#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 warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/type-const-associated-default.rs:1:12 | LL | #![feature(min_generic_const_args)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #132980 <#132980> for more information = note: `#[warn(incomplete_features)]` on by default error: aborting due to 1 previous error; 1 warning emitted For more information about this error, try `rustc --explain E0658`. ``` Thanks to @BoxyUwU for the guidance on this issue.
2 parents 1500f0f + 84140cf commit 2af7441

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
@@ -427,7 +427,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
427427
false
428428
}
429429
ast::AssocItemKind::Const(box ast::ConstItem {
430-
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
430+
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
431431
..
432432
}) => {
433433
// Make sure this is only allowed if the feature gate is enabled.
@@ -438,6 +438,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
438438
i.span,
439439
"associated `type const` are unstable"
440440
);
441+
// Make sure associated `type const` defaults in traits are only allowed
442+
// if the feature gate is enabled.
443+
// #![feature(associated_type_defaults)]
444+
if ctxt == AssocCtxt::Trait && rhs.is_some() {
445+
gate!(
446+
&self,
447+
associated_type_defaults,
448+
i.span,
449+
"associated type defaults are unstable"
450+
);
451+
}
441452
false
442453
}
443454
_ => 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)